Skip to content

Commit b4effe8

Browse files
committed
fixing versions + grisu3
1 parent 7c3108d commit b4effe8

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

benchmarks/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ endif()
6767
target_link_libraries(benchmark PUBLIC fmt)
6868
target_link_libraries(benchmark PUBLIC cxxopts)
6969

70-
target_link_libraries(benchmark PUBLIC grisu2)
70+
#target_link_libraries(benchmark PUBLIC grisu2)
7171
target_link_libraries(benchmark PUBLIC double-conversion)
7272
target_link_libraries(benchmark PUBLIC ryu::ryu)
7373
target_link_libraries(benchmark PUBLIC teju)

benchmarks/algorithms.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "dragon4.h"
2727
#include "dragonbox/dragonbox_to_chars.h"
2828
#include "grisu2.h"
29+
#include "grisu3.h"
2930
#include "grisu_exact.h"
3031
#include "ieeeToString.h"
3132
#include "ryu/ryu.h"
@@ -50,7 +51,8 @@ enum Algorithm {
5051
DOUBLE_CONVERSION = 12,
5152
ABSEIL = 13,
5253
STD_TO_CHARS = 14,
53-
COUNT = 15
54+
GRISU3 = 15,
55+
COUNT = 16,
5456
};
5557

5658
template<typename T>
@@ -158,11 +160,17 @@ int snprintf(T d, std::span<char>& buffer) {
158160
return std::snprintf(buffer.data(), buffer.size(), "%.17g", d);
159161
}
160162

161-
// grisu2::dtoa_impl::grisu2 can take a template type
162-
// However, grisu2::to_chars is hardcoded for double.
163+
// grisu2 is hardcoded for double.
163164
template<arithmetic_float T>
164165
int grisu2(T d, std::span<char>& buffer) {
165-
const char* newp = grisu2::to_chars(buffer.data(), nullptr, d);
166+
const char* newp = grisu2::Dtoa(buffer.data(), d);
167+
return newp - buffer.data();
168+
}
169+
170+
// grisu3 is hardcoded for double.
171+
template<arithmetic_float T>
172+
int grisu3(T d, std::span<char>& buffer) {
173+
const char* newp = grisu3::Dtoa(buffer.data(), d);
166174
return newp - buffer.data();
167175
}
168176

benchmarks/benchmark.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ int main(int argc, char **argv) {
149149
("t,test", "Test the algorithms and find their properties.",
150150
cxxopts::value<bool>()->default_value("false"))
151151
("d,dragon", "Enable dragon4 (current impl. triggers some asserts).",
152+
#ifdef NDEBUG
153+
cxxopts::value<bool>()->default_value("true"))
154+
#else // NDEBUG
155+
// dragon4 is not safe in debug mode: some asserts fire.
152156
cxxopts::value<bool>()->default_value("false"))
157+
#endif
153158
("e,errol", "Enable errol3 (current impl. returns invalid values, e.g., for 0).",
154159
cxxopts::value<bool>()->default_value("false"))
155160
("h,help", "Print usage.");
@@ -202,6 +207,7 @@ int main(int argc, char **argv) {
202207
args[Benchmarks::DOUBLE_CONVERSION] = { "double_conversion" , Benchmarks::double_conversion<T> , true };
203208
args[Benchmarks::ABSEIL] = { "abseil" , Benchmarks::abseil<T> , ABSEIL_SUPPORTED };
204209
args[Benchmarks::STD_TO_CHARS] = { "std::to_chars" , Benchmarks::std_to_chars<T> , TO_CHARS_SUPPORTED };
210+
args[Benchmarks::GRISU3] = { "grisu3" , Benchmarks::grisu3<T> , true };
205211
return args;
206212
};
207213

dependencies/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
if(NOT WIN32)
22
add_subdirectory(netlib)
33
endif()
4-
add_subdirectory(grisu2)
4+
#add_subdirectory(grisu2)
55

66
include(FetchContent)
77
include(ExternalProject)
@@ -14,7 +14,7 @@ if (NOT CYGWIN)
1414

1515
FetchContent_Declare(abseil
1616
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
17-
GIT_TAG "d7aaad8")
17+
GIT_TAG "d9e4955") # Abseil LTS branch, January 2025, Patch 1
1818
FetchContent_GetProperties(abseil)
1919
if(NOT abseil_POPULATED)
2020
set(BUILD_TESTING OFF)
@@ -30,15 +30,15 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
3030
FetchContent_Declare(
3131
doubleconversion
3232
GIT_REPOSITORY https://github.com/google/double-conversion.git
33-
GIT_TAG "v3.1.5"
33+
GIT_TAG "v3.3.1"
3434
GIT_SHALLOW TRUE
3535
)
3636
FetchContent_MakeAvailable(doubleconversion)
3737

3838
FetchContent_Declare(
3939
teju_jagua
4040
GIT_REPOSITORY https://github.com/jaja360/teju_jagua.git
41-
GIT_TAG main
41+
GIT_TAG e62fcfc418170cdcba0fc842dcb5e93ead428ba6
4242
GIT_SHALLOW TRUE
4343
)
4444
FetchContent_MakeAvailable(teju_jagua)
@@ -55,15 +55,15 @@ endif()
5555
FetchContent_Declare(
5656
ryu
5757
GIT_REPOSITORY https://github.com/ulfjack/ryu
58-
GIT_TAG master
58+
GIT_TAG 1264a946ba66eab320e927bfd2362e0c8580c42f
5959
GIT_SHALLOW TRUE
6060
)
6161
FetchContent_MakeAvailable(ryu)
6262

6363
FetchContent_Declare(
6464
grisu-exact
6565
GIT_REPOSITORY https://github.com/jk-jeon/Grisu-Exact
66-
GIT_TAG master
66+
GIT_TAG 4279e63faa301c03112f56f9ee4ed8bdff947fee
6767
GIT_SHALLOW TRUE
6868
)
6969
FetchContent_MakeAvailable(grisu-exact)
@@ -80,7 +80,7 @@ FetchContent_MakeAvailable(dragonbox)
8080
FetchContent_Declare(
8181
drachennest # for schubfach and dragon4
8282
GIT_REPOSITORY https://github.com/abolz/Drachennest.git
83-
GIT_TAG master
83+
GIT_TAG e6714a39ad331b4489d0b6aaf3968635bff4eb5e
8484
GIT_SHALLOW TRUE
8585
)
8686
FetchContent_GetProperties(drachennest)
@@ -92,12 +92,15 @@ add_library(dragon_schubfach_lib STATIC
9292
${drachennest_SOURCE_DIR}/src/dragon4.cc
9393
${drachennest_SOURCE_DIR}/src/schubfach_32.cc
9494
${drachennest_SOURCE_DIR}/src/schubfach_64.cc
95+
${drachennest_SOURCE_DIR}/src/grisu3.cc
96+
${drachennest_SOURCE_DIR}/src/grisu2.cc
97+
9598
)
9699
target_include_directories(dragon_schubfach_lib PUBLIC
97100
${drachennest_SOURCE_DIR}/src
98101
)
99102

100-
CPMAddPackage("gh:fmtlib/fmt#11.0.2")
103+
CPMAddPackage("gh:fmtlib/fmt#11.1.4")
101104
CPMAddPackage(
102105
GITHUB_REPOSITORY jarro2783/cxxopts
103106
VERSION 3.2.0

0 commit comments

Comments
 (0)