Skip to content

Commit b3a77a6

Browse files
authored
Merge pull request #8 from fastfloat/adding_errol
adding errol3 algorithm
2 parents dc055e2 + ace1254 commit b3a77a6

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_C_STANDARD 99)
77
set(CMAKE_C_STANDARD_REQUIRED ON)
88

9-
cmake_policy(SET CMP0169 OLD) # Prevent warning when using FetchContent_Populate
9+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
10+
cmake_policy(SET CMP0169 OLD) # Prevent warning when using FetchContent_Populate
11+
endif()
1012

1113
include(CheckCXXCompilerFlag)
1214
unset(FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE CACHE)

benchmarks/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ if(teju_has_float128)
3939
endif()
4040
target_link_libraries(benchmark PUBLIC dragonbox::dragonbox_to_chars)
4141
target_link_libraries(benchmark PUBLIC dragon_schubfach_lib)
42-
42+
if(TARGET errol)
43+
target_link_libraries(benchmark PUBLIC errol)
44+
endif()
4345
target_include_directories(benchmark PUBLIC ${grisu-exact_SOURCE_DIR})

benchmarks/benchmark.cpp

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include "grisu_exact.h"
2121
#include "dragon4.h"
2222
#include "schubfach_64.h"
23+
#if __has_include("errol.h")
24+
#include "errol.h"
25+
#define ERROL_SUPPORTED 1
26+
#else
27+
#define ERROL_SUPPORTED 0
28+
#endif
2329

2430
#define IEEE_8087
2531
#include "benchutil.h"
@@ -66,7 +72,20 @@ void process(std::vector<double> &lines) {
6672
}
6773
return volume;
6874
});
69-
75+
76+
#if ERROL_SUPPORTED
77+
pretty_print(lines, "errol3", [](const std::vector<double> &lines) {
78+
double volume = 0;
79+
char buffer[100];
80+
for (const auto d : lines) {
81+
errol3_dtoa(d, buffer); // returns the exponent?
82+
volume += std::strlen(buffer);
83+
}
84+
return volume;
85+
});
86+
#else
87+
std::cout << "# errol not supported" << std::endl;
88+
#endif // ERROL_SUPPORTED
7089
pretty_print(lines, "std::to_string", [](const std::vector<double> &lines) {
7190
double volume = 0;
7291
for (const auto d : lines) {
@@ -136,24 +155,6 @@ void process(std::vector<double> &lines) {
136155
return volume;
137156
});
138157

139-
#if FROM_CHARS_DOUBLE_SUPPORTED
140-
pretty_print(lines, "std::to_chars", [](const std::vector<double> &lines) {
141-
double volume = 0;
142-
char buffer[100];
143-
for (const auto d : lines) {
144-
const auto [p, ec] = std::to_chars(buffer, buffer + sizeof(buffer), d);
145-
if(ec != std::errc()) {
146-
std::cerr << "problem with " << d << std::endl;
147-
std::abort();
148-
}
149-
volume += p - buffer;
150-
}
151-
return volume;
152-
});
153-
#else
154-
std::cout << "# std::to_chars not supported" << std::endl;
155-
#endif
156-
157158
pretty_print(lines, "schubfach", [](const std::vector<double> &lines) {
158159
double volume = 0;
159160
char buffer[100];
@@ -224,6 +225,26 @@ void process(std::vector<double> &lines) {
224225
}
225226
return volume;
226227
});
228+
229+
230+
#if FROM_CHARS_DOUBLE_SUPPORTED
231+
pretty_print(lines, "std::to_chars", [](const std::vector<double> &lines) {
232+
double volume = 0;
233+
char buffer[100];
234+
for (const auto d : lines) {
235+
const auto [p, ec] = std::to_chars(buffer, buffer + sizeof(buffer), d);
236+
if(ec != std::errc()) {
237+
std::cerr << "problem with " << d << std::endl;
238+
std::abort();
239+
}
240+
volume += p - buffer;
241+
}
242+
return volume;
243+
});
244+
#else
245+
std::cout << "# std::to_chars not supported" << std::endl;
246+
#endif
247+
227248
}
228249

229250
void fileload(const char *filename) {

dependencies/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,16 @@ CPMAddPackage(
103103
VERSION 3.2.0
104104
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
105105
)
106+
107+
if(NOT WIN32)
108+
CPMAddPackage(
109+
NAME errol
110+
GITHUB_REPOSITORY marcandrysco/Errol
111+
GIT_TAG 5364de4
112+
DOWNLOAD_ONLY ON
113+
)
114+
115+
116+
add_library(errol STATIC "${errol_SOURCE_DIR}/lib/errol.c")
117+
target_include_directories(errol SYSTEM PUBLIC "${errol_SOURCE_DIR}/lib")
118+
endif()

0 commit comments

Comments
 (0)