From 8559cfa73f8d42e5d2c489fb41a609009e80e423 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 27 Oct 2020 21:11:19 -0400 Subject: [PATCH] Some optimization. --- include/fast_float/simple_decimal_conversion.h | 3 +++ tests/basictest.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/include/fast_float/simple_decimal_conversion.h b/include/fast_float/simple_decimal_conversion.h index ef1f0ad..2ac43ba 100644 --- a/include/fast_float/simple_decimal_conversion.h +++ b/include/fast_float/simple_decimal_conversion.h @@ -356,6 +356,9 @@ adjusted_mantissa parse_long_mantissa(const char *first, const char* last) { decimal d = parse_decimal(first, last); const uint64_t mantissa = d.to_truncated_mantissa(); const int64_t exponent = d.to_truncated_exponent(); + // credit: Nigel Tao who first implemented this fast path (to my knowledge). + // It is rough, but it does the job of accelerating the slow path since most + // long streams of digits are determined after 19 digits. adjusted_mantissa am1 = compute_float(exponent, mantissa); adjusted_mantissa am2 = compute_float(exponent, mantissa+1); if( am1 == am2 ) { return am1; } diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 9e19936..b07f8a9 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -139,6 +139,7 @@ int main() { std::cout << "======= 64 bits " << std::endl; + Assert(basic_test_64bit("2.22507385850720212418870147920222032907240528279439037814303133837435107319244194686754406432563881851382188218502438069999947733013005649884107791928741341929297200970481951993067993290969042784064731682041565926728632933630474670123316852983422152744517260835859654566319282835244787787799894310779783833699159288594555213714181128458251145584319223079897504395086859412457230891738946169368372321191373658977977723286698840356390251044443035457396733706583981055420456693824658413747607155981176573877626747665912387199931904006317334709003012790188175203447190250028061277777916798391090578584006464715943810511489154282775041174682194133952466682503431306181587829379004205392375072083366693241580002758391118854188641513168478436313080237596295773983001708984375e-308", 0x1.0000000000002p-1022)); Assert(basic_test_64bit("1.0000000000000006661338147750939242541790008544921875",1.0000000000000007)); Assert(basic_test_64bit("1090544144181609348835077142190",0x1.b8779f2474dfbp+99)); Assert(basic_test_64bit("2.2250738585072013e-308",2.2250738585072013e-308));