2121#include < iostream>
2222#include < string>
2323#include < variant>
24+ #include < fast_float/fast_float.h>
25+ #if FROM_CHARS_SUPPORTED || TO_CHARS_SUPPORTED
26+ #include < charconv> // technically included by "algorithms.h"
27+ #endif
2428
2529using Benchmarks::arithmetic_float;
2630using Benchmarks::BenchArgs;
@@ -45,16 +49,17 @@ void evaluateProperties(const std::vector<T> &lines,
4549 const int vRef = Benchmarks::std_to_chars (d, bufRef);
4650 bufRef[vRef] = ' \0 ' ;
4751 T dRef;
48- auto [ptr, ec] = std::from_chars (bufRef.data (), bufRef.data () + vRef, dRef);
52+ // We prefer fast_float::from_chars over std::from_chars because it is more
53+ // likely to be available.
54+ auto [ptr, ec] = fast_float::from_chars (bufRef.data (), bufRef.data () + vRef, dRef);
4955 assert (ptr == bufRef.data () + vRef);
5056 assert (ec == std::errc ());
5157 assert (d == dRef);
52-
5358 // Tested algorithm output
5459 const int vAlgo = algo.func (d, bufAlgo);
5560 bufAlgo[vAlgo] = ' \0 ' ;
5661 T dAlgo;
57- auto [ptrAlgo, ecAlgo] = std ::from_chars (bufAlgo.data (), bufAlgo.data () + vAlgo, dAlgo);
62+ auto [ptrAlgo, ecAlgo] = fast_float ::from_chars (bufAlgo.data (), bufAlgo.data () + vAlgo, dAlgo);
5863 assert (ptrAlgo == bufAlgo.data () + vAlgo);
5964 assert (ecAlgo == std::errc ());
6065 if ((incorrect += (d != dAlgo)) == 1 )
@@ -132,21 +137,22 @@ cxxopts::Options
132137
133138int main (int argc, char **argv) {
134139 try {
135- options.add_options ()(" f,file" , " File name." ,
136- cxxopts::value<std::string>()->default_value (" " ))(
137- " v,volume" , " Volume (number of floats generated)." ,
138- cxxopts::value<size_t >()->default_value (" 100000" ))(
139- " m,model" , " Random Model." ,
140- cxxopts::value<std::string>()->default_value (" uniform" ))(
141- " s,single" , " Use single precision instead of double." ,
142- cxxopts::value<bool >()->default_value (" false" ))(
143- " t,test" , " Test the algorithms and find their properties." ,
144- cxxopts::value<bool >()->default_value (" false" ))(
145- " d,dragon" , " Enable dragon4 (current impl. triggers some asserts)." ,
146- cxxopts::value<bool >()->default_value (" false" ))(
147- " e,errol" , " Enable errol3 (current impl. returns invalid values, e.g., for 0)." ,
148- cxxopts::value<bool >()->default_value (" false" ))(
149- " h,help" , " Print usage." );
140+ options.add_options ()
141+ (" f,file" , " File name." ,
142+ cxxopts::value<std::string>()->default_value (" " ))
143+ (" v,volume" , " Volume (number of floats generated)." ,
144+ cxxopts::value<size_t >()->default_value (" 100000" ))
145+ (" m,model" , " Random Model." ,
146+ cxxopts::value<std::string>()->default_value (" uniform" ))
147+ (" s,single" , " Use single precision instead of double." ,
148+ cxxopts::value<bool >()->default_value (" false" ))
149+ (" t,test" , " Test the algorithms and find their properties." ,
150+ cxxopts::value<bool >()->default_value (" false" ))
151+ (" d,dragon" , " Enable dragon4 (current impl. triggers some asserts)." ,
152+ cxxopts::value<bool >()->default_value (" false" ))
153+ (" e,errol" , " Enable errol3 (current impl. returns invalid values, e.g., for 0)." ,
154+ cxxopts::value<bool >()->default_value (" false" ))
155+ (" h,help" , " Print usage." );
150156 const auto result = options.parse (argc, argv);
151157
152158 if (result[" help" ].as <bool >()) {
@@ -195,7 +201,7 @@ int main(int argc, char **argv) {
195201 args[Benchmarks::TEJU_JAGUA] = { " teju_jagua" , Benchmarks::teju_jagua<T> , true };
196202 args[Benchmarks::DOUBLE_CONVERSION] = { " double_conversion" , Benchmarks::double_conversion<T> , true };
197203 args[Benchmarks::ABSEIL] = { " abseil" , Benchmarks::abseil<T> , ABSEIL_SUPPORTED };
198- args[Benchmarks::STD_TO_CHARS] = { " std::to_chars" , Benchmarks::std_to_chars<T> , FROM_CHARS_SUPPORTED };
204+ args[Benchmarks::STD_TO_CHARS] = { " std::to_chars" , Benchmarks::std_to_chars<T> , TO_CHARS_SUPPORTED };
199205 return args;
200206 };
201207
0 commit comments