forked from fastfloat/fast_float
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasictest.cpp
2072 lines (1954 loc) · 97.1 KB
/
basictest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define DOCTEST_CONFIG_SUPER_FAST_ASSERTS
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
#include "fast_float/fast_float.h"
#include <cfenv>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <system_error>
#include <type_traits>
#if FASTFLOAT_IS_CONSTEXPR
#ifndef FASTFLOAT_CONSTEXPR_TESTS
#define FASTFLOAT_CONSTEXPR_TESTS 1
#endif // #ifndef FASTFLOAT_CONSTEXPR_TESTS
#endif // FASTFLOAT_IS_CONSTEXPR
#if FASTFLOAT_HAS_BIT_CAST
#include <bit>
#endif
#ifndef SUPPLEMENTAL_TEST_DATA_DIR
#define SUPPLEMENTAL_TEST_DATA_DIR "data/"
#endif
#ifndef __cplusplus
#error fastfloat requires a C++ compiler
#endif
#ifndef FASTFLOAT_CPLUSPLUS
#if defined(_MSVC_LANG) && !defined(__clang__)
#define FASTFLOAT_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG)
#else
#define FASTFLOAT_CPLUSPLUS __cplusplus
#endif
#endif
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || \
defined(sun) || defined(__sun)
#define FASTFLOAT_ODDPLATFORM 1
#endif
#if defined __has_include
#if __has_include(<filesystem>)
#else
// filesystem is not available
#define FASTFLOAT_ODDPLATFORM 1
#endif
#else
// __has_include is not available
#define FASTFLOAT_ODDPLATFORM 1
#endif
template <typename T> std::string iHexAndDec(T v) {
std::ostringstream ss;
ss << std::hex << "0x" << (v) << " (" << std::dec << (v) << ")";
return ss.str();
}
template <typename T> std::string fHexAndDec(T v) {
std::ostringstream ss;
ss << std::hexfloat << (v) << " (" << std::defaultfloat
<< std::setprecision(DBL_MAX_10_EXP + 1) << (v) << ")";
return ss.str();
}
char const *round_name(int d) {
switch (d) {
case FE_UPWARD:
return "FE_UPWARD";
case FE_DOWNWARD:
return "FE_DOWNWARD";
case FE_TOWARDZERO:
return "FE_TOWARDZERO";
case FE_TONEAREST:
return "FE_TONEAREST";
default:
return "UNKNOWN";
}
}
#define FASTFLOAT_STR(x) #x
#define SHOW_DEFINE(x) printf("%s='%s'\n", #x, FASTFLOAT_STR(x))
TEST_CASE("system_info") {
std::cout << "system info:" << std::endl;
#ifdef FASTFLOAT_CONSTEXPR_TESTS
SHOW_DEFINE(FASTFLOAT_CONSTEXPR_TESTS);
#endif
#ifdef _MSC_VER
SHOW_DEFINE(_MSC_VER);
#endif
#ifdef FASTFLOAT_64BIT_LIMB
SHOW_DEFINE(FASTFLOAT_64BIT_LIMB);
#endif
#ifdef __clang__
SHOW_DEFINE(__clang__);
#endif
#ifdef FASTFLOAT_VISUAL_STUDIO
SHOW_DEFINE(FASTFLOAT_VISUAL_STUDIO);
#endif
#ifdef FASTFLOAT_IS_BIG_ENDIAN
#if FASTFLOAT_IS_BIG_ENDIAN
printf("big endian\n");
#else
printf("little endian\n");
#endif
#endif
#ifdef FASTFLOAT_32BIT
SHOW_DEFINE(FASTFLOAT_32BIT);
#endif
#ifdef FASTFLOAT_64BIT
SHOW_DEFINE(FASTFLOAT_64BIT);
#endif
#ifdef FLT_EVAL_METHOD
SHOW_DEFINE(FLT_EVAL_METHOD);
#endif
#ifdef _WIN32
SHOW_DEFINE(_WIN32);
#endif
#ifdef _WIN64
SHOW_DEFINE(_WIN64);
#endif
std::cout << "fegetround() = " << round_name(fegetround()) << std::endl;
std::cout << std::endl;
}
TEST_CASE("double.rounds_to_nearest") {
//
// If this function fails, we may be left in a non-standard rounding state.
//
static double volatile fmin = std::numeric_limits<double>::min();
fesetround(FE_UPWARD);
std::cout << "FE_UPWARD: fmin + 1.0 = " << fHexAndDec(fmin + 1.0)
<< " 1.0 - fmin = " << fHexAndDec(1.0 - fmin) << std::endl;
CHECK(fegetround() == FE_UPWARD);
CHECK(fast_float::detail::rounds_to_nearest() == false);
fesetround(FE_DOWNWARD);
std::cout << "FE_DOWNWARD: fmin + 1.0 = " << fHexAndDec(fmin + 1.0)
<< " 1.0 - fmin = " << fHexAndDec(1.0 - fmin) << std::endl;
CHECK(fegetround() == FE_DOWNWARD);
CHECK(fast_float::detail::rounds_to_nearest() == false);
fesetround(FE_TOWARDZERO);
std::cout << "FE_TOWARDZERO: fmin + 1.0 = " << fHexAndDec(fmin + 1.0)
<< " 1.0 - fmin = " << fHexAndDec(1.0 - fmin) << std::endl;
CHECK(fegetround() == FE_TOWARDZERO);
CHECK(fast_float::detail::rounds_to_nearest() == false);
fesetround(FE_TONEAREST);
std::cout << "FE_TONEAREST: fmin + 1.0 = " << fHexAndDec(fmin + 1.0)
<< " 1.0 - fmin = " << fHexAndDec(1.0 - fmin) << std::endl;
CHECK(fegetround() == FE_TONEAREST);
#if (FLT_EVAL_METHOD == 1) || (FLT_EVAL_METHOD == 0)
CHECK(fast_float::detail::rounds_to_nearest() == true);
#endif
}
TEST_CASE("double.parse_zero") {
//
// If this function fails, we may be left in a non-standard rounding state.
//
char const *zero = "0";
uint64_t float64_parsed;
double f = 0;
::memcpy(&float64_parsed, &f, sizeof(f));
CHECK(float64_parsed == 0);
fesetround(FE_UPWARD);
auto r1 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r1.ec == std::errc());
std::cout << "FE_UPWARD parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0);
fesetround(FE_TOWARDZERO);
auto r2 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r2.ec == std::errc());
std::cout << "FE_TOWARDZERO parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0);
fesetround(FE_DOWNWARD);
auto r3 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r3.ec == std::errc());
std::cout << "FE_DOWNWARD parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0);
fesetround(FE_TONEAREST);
auto r4 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r4.ec == std::errc());
std::cout << "FE_TONEAREST parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0);
}
TEST_CASE("double.parse_negative_zero") {
//
// If this function fails, we may be left in a non-standard rounding state.
//
char const *negative_zero = "-0";
uint64_t float64_parsed;
double f = -0.;
::memcpy(&float64_parsed, &f, sizeof(f));
CHECK(float64_parsed == 0x8000'0000'0000'0000);
fesetround(FE_UPWARD);
auto r1 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r1.ec == std::errc());
std::cout << "FE_UPWARD parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0x8000'0000'0000'0000);
fesetround(FE_TOWARDZERO);
auto r2 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r2.ec == std::errc());
std::cout << "FE_TOWARDZERO parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0x8000'0000'0000'0000);
fesetround(FE_DOWNWARD);
auto r3 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r3.ec == std::errc());
std::cout << "FE_DOWNWARD parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0x8000'0000'0000'0000);
fesetround(FE_TONEAREST);
auto r4 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r4.ec == std::errc());
std::cout << "FE_TONEAREST parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.);
::memcpy(&float64_parsed, &f, sizeof(f));
std::cout << "double as uint64_t is " << iHexAndDec(float64_parsed)
<< std::endl;
CHECK(float64_parsed == 0x8000'0000'0000'0000);
}
TEST_CASE("float.rounds_to_nearest") {
//
// If this function fails, we may be left in a non-standard rounding state.
//
static float volatile fmin = std::numeric_limits<float>::min();
fesetround(FE_UPWARD);
std::cout << "FE_UPWARD: fmin + 1.0f = " << fHexAndDec(fmin + 1.0f)
<< " 1.0f - fmin = " << fHexAndDec(1.0f - fmin) << std::endl;
CHECK(fegetround() == FE_UPWARD);
CHECK(fast_float::detail::rounds_to_nearest() == false);
fesetround(FE_DOWNWARD);
std::cout << "FE_DOWNWARD: fmin + 1.0f = " << fHexAndDec(fmin + 1.0f)
<< " 1.0f - fmin = " << fHexAndDec(1.0f - fmin) << std::endl;
CHECK(fegetround() == FE_DOWNWARD);
CHECK(fast_float::detail::rounds_to_nearest() == false);
fesetround(FE_TOWARDZERO);
std::cout << "FE_TOWARDZERO: fmin + 1.0f = " << fHexAndDec(fmin + 1.0f)
<< " 1.0f - fmin = " << fHexAndDec(1.0f - fmin) << std::endl;
CHECK(fegetround() == FE_TOWARDZERO);
CHECK(fast_float::detail::rounds_to_nearest() == false);
fesetround(FE_TONEAREST);
std::cout << "FE_TONEAREST: fmin + 1.0f = " << fHexAndDec(fmin + 1.0f)
<< " 1.0f - fmin = " << fHexAndDec(1.0f - fmin) << std::endl;
CHECK(fegetround() == FE_TONEAREST);
#if (FLT_EVAL_METHOD == 1) || (FLT_EVAL_METHOD == 0)
CHECK(fast_float::detail::rounds_to_nearest() == true);
#endif
}
TEST_CASE("float.parse_zero") {
//
// If this function fails, we may be left in a non-standard rounding state.
//
char const *zero = "0";
uint32_t float32_parsed;
float f = 0;
::memcpy(&float32_parsed, &f, sizeof(f));
CHECK(float32_parsed == 0);
fesetround(FE_UPWARD);
auto r1 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r1.ec == std::errc());
std::cout << "FE_UPWARD parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0);
fesetround(FE_TOWARDZERO);
auto r2 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r2.ec == std::errc());
std::cout << "FE_TOWARDZERO parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0);
fesetround(FE_DOWNWARD);
auto r3 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r3.ec == std::errc());
std::cout << "FE_DOWNWARD parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0);
fesetround(FE_TONEAREST);
auto r4 = fast_float::from_chars(zero, zero + 1, f);
CHECK(r4.ec == std::errc());
std::cout << "FE_TONEAREST parsed zero as " << fHexAndDec(f) << std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0);
}
TEST_CASE("float.parse_negative_zero") {
//
// If this function fails, we may be left in a non-standard rounding state.
//
char const *negative_zero = "-0";
uint32_t float32_parsed;
float f = -0.;
::memcpy(&float32_parsed, &f, sizeof(f));
CHECK(float32_parsed == 0x8000'0000);
fesetround(FE_UPWARD);
auto r1 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r1.ec == std::errc());
std::cout << "FE_UPWARD parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0x8000'0000);
fesetround(FE_TOWARDZERO);
auto r2 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r2.ec == std::errc());
std::cout << "FE_TOWARDZERO parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0x8000'0000);
fesetround(FE_DOWNWARD);
auto r3 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r3.ec == std::errc());
std::cout << "FE_DOWNWARD parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0x8000'0000);
fesetround(FE_TONEAREST);
auto r4 = fast_float::from_chars(negative_zero, negative_zero + 2, f);
CHECK(r4.ec == std::errc());
std::cout << "FE_TONEAREST parsed negative zero as " << fHexAndDec(f)
<< std::endl;
CHECK(f == 0.f);
::memcpy(&float32_parsed, &f, sizeof(f));
std::cout << "float as uint32_t is " << iHexAndDec(float32_parsed)
<< std::endl;
CHECK(float32_parsed == 0x8000'0000);
}
#if FASTFLOAT_SUPPLEMENTAL_TESTS
// C++ 17 because it is otherwise annoying to browse all files in a directory.
// We also only run these tests on little endian systems.
#if (FASTFLOAT_CPLUSPLUS >= 201703L) && (FASTFLOAT_IS_BIG_ENDIAN == 0) && \
!defined(FASTFLOAT_ODDPLATFORM)
#include <filesystem>
#include <charconv>
// return true on success
bool check_file(std::string file_name) {
std::cout << "Checking " << file_name << std::endl;
// We check all rounding directions, for each file.
std::vector<int> directions = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};
for (int d : directions) {
std::cout << "fesetround to " << round_name(d) << std::endl;
fesetround(d);
size_t number{0};
std::fstream newfile(file_name, std::ios::in);
if (newfile.is_open()) {
std::string str;
while (std::getline(newfile, str)) {
if (str.size() > 0) {
#ifdef __STDCPP_FLOAT16_T__
// Read 16-bit hex
uint16_t float16{};
auto r16 =
std::from_chars(str.data(), str.data() + str.size(), float16, 16);
if (r16.ec != std::errc()) {
std::cerr << "16-bit parsing failure: " << str << "\n";
return false;
}
#endif
// Read 32-bit hex
uint32_t float32{};
auto r32 = std::from_chars(str.data() + 5, str.data() + str.size(),
float32, 16);
if (r32.ec != std::errc()) {
std::cerr << "32-bit parsing failure: " << str << "\n";
return false;
}
// Read 64-bit hex
uint64_t float64{};
auto r64 = std::from_chars(str.data() + 14, str.data() + str.size(),
float64, 16);
if (r64.ec != std::errc()) {
std::cerr << "64-bit parsing failure: " << str << "\n";
return false;
}
// The string to parse:
char const *number_string = str.data() + 31;
char const *end_of_string = str.data() + str.size();
#ifdef __STDCPP_FLOAT16_T__
// Parse as 16-bit float
std::float16_t parsed_16{};
auto fast_float_r16 =
fast_float::from_chars(number_string, end_of_string, parsed_16);
if (fast_float_r16.ec != std::errc() &&
fast_float_r16.ec != std::errc::result_out_of_range) {
std::cerr << "16-bit fast_float parsing failure: " << str << "\n";
return false;
}
#endif
// Parse as 32-bit float
float parsed_32{};
auto fast_float_r32 =
fast_float::from_chars(number_string, end_of_string, parsed_32);
if (fast_float_r32.ec != std::errc() &&
fast_float_r32.ec != std::errc::result_out_of_range) {
std::cerr << "32-bit fast_float parsing failure: " << str << "\n";
return false;
}
// Parse as 64-bit float
double parsed_64{};
auto fast_float_r64 =
fast_float::from_chars(number_string, end_of_string, parsed_64);
if (fast_float_r64.ec != std::errc() &&
fast_float_r32.ec != std::errc::result_out_of_range) {
std::cerr << "64-bit fast_float parsing failure: " << str << "\n";
return false;
}
// Convert the floats to unsigned ints.
#ifdef __STDCPP_FLOAT16_T__
uint16_t float16_parsed{};
#endif
uint32_t float32_parsed{};
uint64_t float64_parsed{};
#ifdef __STDCPP_FLOAT16_T__
::memcpy(&float16_parsed, &parsed_16, sizeof(parsed_16));
#endif
::memcpy(&float32_parsed, &parsed_32, sizeof(parsed_32));
::memcpy(&float64_parsed, &parsed_64, sizeof(parsed_64));
// Compare with expected results
#ifdef __STDCPP_FLOAT16_T__
if (float16_parsed != float16) {
std::cout << "bad 16: " << str << std::endl;
std::cout << "parsed as " << fHexAndDec(parsed_16) << std::endl;
std::cout << "as raw uint16_t, parsed = " << float16_parsed
<< ", expected = " << float16 << std::endl;
std::cout << "fesetround: " << round_name(d) << std::endl;
const bool is_ulfjack =
file_name.find("ulfjack") != std::string::npos;
if (is_ulfjack) {
std::cout << "This is a known issue with ulfjack's test suite."
<< std::endl;
} else {
fesetround(FE_TONEAREST);
return false;
}
}
#endif
if (float32_parsed != float32) {
std::cout << "bad 32: " << str << std::endl;
std::cout << "parsed as " << fHexAndDec(parsed_32) << std::endl;
std::cout << "as raw uint32_t, parsed = " << float32_parsed
<< ", expected = " << float32 << std::endl;
std::cout << "fesetround: " << round_name(d) << std::endl;
fesetround(FE_TONEAREST);
return false;
}
if (float64_parsed != float64) {
std::cout << "bad 64: " << str << std::endl;
std::cout << "parsed as " << fHexAndDec(parsed_64) << std::endl;
std::cout << "as raw uint64_t, parsed = " << float64_parsed
<< ", expected = " << float64 << std::endl;
std::cout << "fesetround: " << round_name(d) << std::endl;
fesetround(FE_TONEAREST);
return false;
}
number++;
}
}
std::cout << "checked " << std::defaultfloat << number << " values"
<< std::endl;
newfile.close(); // close the file object
} else {
std::cout << "Could not read " << file_name << std::endl;
fesetround(FE_TONEAREST);
return false;
}
}
fesetround(FE_TONEAREST);
return true;
}
TEST_CASE("supplemental") {
std::string path = SUPPLEMENTAL_TEST_DATA_DIR;
for (auto const &entry : std::filesystem::directory_iterator(path)) {
const auto file = entry.path().string();
CAPTURE(file);
CHECK(check_file(file));
}
}
#endif
#endif
TEST_CASE("leading_zeroes") {
constexpr uint64_t const bit = 1;
CHECK(fast_float::leading_zeroes(bit << 0) == 63);
CHECK(fast_float::leading_zeroes(bit << 1) == 62);
CHECK(fast_float::leading_zeroes(bit << 2) == 61);
CHECK(fast_float::leading_zeroes(bit << 61) == 2);
CHECK(fast_float::leading_zeroes(bit << 62) == 1);
CHECK(fast_float::leading_zeroes(bit << 63) == 0);
}
void test_full_multiplication(uint64_t lhs, uint64_t rhs, uint64_t expected_lo,
uint64_t expected_hi) {
fast_float::value128 v;
v = fast_float::full_multiplication(lhs, rhs);
INFO("lhs=" << iHexAndDec(lhs) << " "
<< "rhs=" << iHexAndDec(rhs)
<< "\n actualLo=" << iHexAndDec(v.low) << " "
<< "actualHi=" << iHexAndDec(v.high)
<< "\n expectedLo=" << iHexAndDec(expected_lo) << " "
<< "expectedHi=" << iHexAndDec(expected_hi));
CHECK_EQ(v.low, expected_lo);
CHECK_EQ(v.high, expected_hi);
v = fast_float::full_multiplication(rhs, lhs);
CHECK_EQ(v.low, expected_lo);
CHECK_EQ(v.high, expected_hi);
}
TEST_CASE("full_multiplication") {
constexpr uint64_t const bit = 1;
// lhs rhs lo hi
test_full_multiplication(bit << 0, bit << 0, 1u, 0u);
test_full_multiplication(bit << 0, bit << 63, bit << 63, 0u);
test_full_multiplication(bit << 1, bit << 63, 0u, 1u);
test_full_multiplication(bit << 63, bit << 0, bit << 63, 0u);
test_full_multiplication(bit << 63, bit << 1, 0u, 1u);
test_full_multiplication(bit << 63, bit << 2, 0u, 2u);
test_full_multiplication(bit << 63, bit << 63, 0u, bit << 62);
}
TEST_CASE("issue8") {
char const *s =
"3."
"141592653589793238462643383279502884197169399375105820974944592307816406"
"286208998628034825342117067982148086513282306647093844609550582231725359"
"408128481117450284102701938521105559644622948954930381964428810975665933"
"446128475648233786783165271201909145648566923460348610454326648213393607"
"260249141273724587006606315588174881520920962829254091715364367892590360"
"011330530548820466521384146951941511609433057270365759591953092186117381"
"932611793105118548074462379962749567351885752724891227938183011949129833"
"673362440656643086021394946395224737190702179860943702770539217176293176"
"752384674818467669405132000568127145263560827785771342757789609173637178"
"721468440901224953430146549585371050792279689258923542019956112129021960"
"864034418159813629774771309960518707211349999998372978";
for (int i = 0; i < 16; i++) {
// Parse all but the last i chars. We should still get 3.141ish.
double d = 0.0;
auto answer = fast_float::from_chars(s, s + strlen(s) - i, d);
CHECK_MESSAGE(answer.ec == std::errc(), "i=" << i);
CHECK_MESSAGE(d == 0x1.921fb54442d18p+1,
"i=" << i << "\n"
<< std::string(s, strlen(s) - size_t(i)) << "\n"
<< std::hexfloat << d << "\n"
<< std::defaultfloat << "\n");
}
}
TEST_CASE("check_behavior") {
std::string const input = "abc";
double result;
auto answer =
fast_float::from_chars(input.data(), input.data() + input.size(), result);
CHECK_MESSAGE(answer.ec != std::errc(), "expected parse failure");
CHECK_MESSAGE(
answer.ptr == input.data(),
"If there is no pattern match, we should have ptr equals first");
}
TEST_CASE("decimal_point_parsing") {
double result;
fast_float::parse_options options{};
{
std::string const input = "1,25";
auto answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + 1,
"Parsing should have stopped at comma");
CHECK_EQ(result, 1.0);
options.decimal_point = ',';
answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
"Parsing should have stopped at end");
CHECK_EQ(result, 1.25);
}
{
std::string const input = "1.25";
auto answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + 1,
"Parsing should have stopped at dot");
CHECK_EQ(result, 1.0);
options.decimal_point = '.';
answer = fast_float::from_chars_advanced(
input.data(), input.data() + input.size(), result, options);
CHECK_MESSAGE(answer.ec == std::errc(), "expected parse success");
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
"Parsing should have stopped at end");
CHECK_EQ(result, 1.25);
}
}
TEST_CASE("issue19") {
std::string const input = "234532.3426362,7869234.9823,324562.645";
double result;
auto answer =
fast_float::from_chars(input.data(), input.data() + input.size(), result);
CHECK_MESSAGE(answer.ec == std::errc(),
"We want to parse up to 234532.3426362\n");
CHECK_MESSAGE(answer.ptr == input.data() + 14,
"Parsed the number "
<< result << " and stopped at the wrong character: after "
<< (answer.ptr - input.data()) << " characters");
CHECK_MESSAGE(result == 234532.3426362, "We want to parse234532.3426362\n");
CHECK_MESSAGE(answer.ptr[0] == ',', "We want to parse up to the comma\n");
answer = fast_float::from_chars(answer.ptr + 1, input.data() + input.size(),
result);
CHECK_MESSAGE(answer.ec == std::errc(), "We want to parse 7869234.9823\n");
CHECK_MESSAGE(answer.ptr == input.data() + 27,
"Parsed the number " << result
<< " and stopped at the wrong character "
<< (answer.ptr - input.data()));
CHECK_MESSAGE(answer.ptr[0] == ',', "We want to parse up to the comma\n");
CHECK_MESSAGE(result == 7869234.9823, "We want to parse up 7869234.9823\n");
answer = fast_float::from_chars(answer.ptr + 1, input.data() + input.size(),
result);
CHECK_MESSAGE(answer.ec == std::errc(), "We want to parse 324562.645\n");
CHECK_MESSAGE(answer.ptr == input.data() + 38,
"Parsed the number " << result
<< " and stopped at the wrong character "
<< (answer.ptr - input.data()));
CHECK_MESSAGE(result == 324562.645, "We want to parse up 7869234.9823\n");
}
TEST_CASE("issue19") {
std::string const input = "3.14e";
double result;
auto answer =
fast_float::from_chars(input.data(), input.data() + input.size(), result);
CHECK_MESSAGE(answer.ec == std::errc(), "We want to parse up to 3.14\n");
CHECK_MESSAGE(answer.ptr == input.data() + 4,
"Parsed the number "
<< result << " and stopped at the wrong character: after "
<< (answer.ptr - input.data()) << " characters");
}
TEST_CASE("scientific_only") {
// first, we try with something that should fail...
std::string input = "3.14";
double result;
auto answer =
fast_float::from_chars(input.data(), input.data() + input.size(), result,
fast_float::chars_format::scientific);
CHECK_MESSAGE(answer.ec != std::errc(),
"It is not scientific! Parsed: " << result);
input = "3.14e10";
answer = fast_float::from_chars(input.data(), input.data() + input.size(),
result, fast_float::chars_format::scientific);
CHECK_MESSAGE(answer.ec == std::errc(),
"It is scientific! Parsed: " << result);
CHECK_MESSAGE(answer.ptr == input.data() + input.size(),
"Parsed the number "
<< result << " and stopped at the wrong character: after "
<< (answer.ptr - input.data()) << " characters");
}
TEST_CASE("test_fixed_only") {
std::string const input = "3.14e10";
double result;
auto answer =
fast_float::from_chars(input.data(), input.data() + input.size(), result,
fast_float::chars_format::fixed);
CHECK_MESSAGE(answer.ec == std::errc(),
"We want to parse up to 3.14; parsed: " << result);
CHECK_MESSAGE(answer.ptr == input.data() + 4,
"Parsed the number "
<< result << " and stopped at the wrong character: after "
<< (answer.ptr - input.data()) << " characters");
}
static double const testing_power_of_ten[] = {
1e-323, 1e-322, 1e-321, 1e-320, 1e-319, 1e-318, 1e-317, 1e-316, 1e-315,
1e-314, 1e-313, 1e-312, 1e-311, 1e-310, 1e-309, 1e-308,
1e-307, 1e-306, 1e-305, 1e-304, 1e-303, 1e-302, 1e-301, 1e-300, 1e-299,
1e-298, 1e-297, 1e-296, 1e-295, 1e-294, 1e-293, 1e-292, 1e-291, 1e-290,
1e-289, 1e-288, 1e-287, 1e-286, 1e-285, 1e-284, 1e-283, 1e-282, 1e-281,
1e-280, 1e-279, 1e-278, 1e-277, 1e-276, 1e-275, 1e-274, 1e-273, 1e-272,
1e-271, 1e-270, 1e-269, 1e-268, 1e-267, 1e-266, 1e-265, 1e-264, 1e-263,
1e-262, 1e-261, 1e-260, 1e-259, 1e-258, 1e-257, 1e-256, 1e-255, 1e-254,
1e-253, 1e-252, 1e-251, 1e-250, 1e-249, 1e-248, 1e-247, 1e-246, 1e-245,
1e-244, 1e-243, 1e-242, 1e-241, 1e-240, 1e-239, 1e-238, 1e-237, 1e-236,
1e-235, 1e-234, 1e-233, 1e-232, 1e-231, 1e-230, 1e-229, 1e-228, 1e-227,
1e-226, 1e-225, 1e-224, 1e-223, 1e-222, 1e-221, 1e-220, 1e-219, 1e-218,
1e-217, 1e-216, 1e-215, 1e-214, 1e-213, 1e-212, 1e-211, 1e-210, 1e-209,
1e-208, 1e-207, 1e-206, 1e-205, 1e-204, 1e-203, 1e-202, 1e-201, 1e-200,
1e-199, 1e-198, 1e-197, 1e-196, 1e-195, 1e-194, 1e-193, 1e-192, 1e-191,
1e-190, 1e-189, 1e-188, 1e-187, 1e-186, 1e-185, 1e-184, 1e-183, 1e-182,
1e-181, 1e-180, 1e-179, 1e-178, 1e-177, 1e-176, 1e-175, 1e-174, 1e-173,
1e-172, 1e-171, 1e-170, 1e-169, 1e-168, 1e-167, 1e-166, 1e-165, 1e-164,
1e-163, 1e-162, 1e-161, 1e-160, 1e-159, 1e-158, 1e-157, 1e-156, 1e-155,
1e-154, 1e-153, 1e-152, 1e-151, 1e-150, 1e-149, 1e-148, 1e-147, 1e-146,
1e-145, 1e-144, 1e-143, 1e-142, 1e-141, 1e-140, 1e-139, 1e-138, 1e-137,
1e-136, 1e-135, 1e-134, 1e-133, 1e-132, 1e-131, 1e-130, 1e-129, 1e-128,
1e-127, 1e-126, 1e-125, 1e-124, 1e-123, 1e-122, 1e-121, 1e-120, 1e-119,
1e-118, 1e-117, 1e-116, 1e-115, 1e-114, 1e-113, 1e-112, 1e-111, 1e-110,
1e-109, 1e-108, 1e-107, 1e-106, 1e-105, 1e-104, 1e-103, 1e-102, 1e-101,
1e-100, 1e-99, 1e-98, 1e-97, 1e-96, 1e-95, 1e-94, 1e-93, 1e-92,
1e-91, 1e-90, 1e-89, 1e-88, 1e-87, 1e-86, 1e-85, 1e-84, 1e-83,
1e-82, 1e-81, 1e-80, 1e-79, 1e-78, 1e-77, 1e-76, 1e-75, 1e-74,
1e-73, 1e-72, 1e-71, 1e-70, 1e-69, 1e-68, 1e-67, 1e-66, 1e-65,
1e-64, 1e-63, 1e-62, 1e-61, 1e-60, 1e-59, 1e-58, 1e-57, 1e-56,
1e-55, 1e-54, 1e-53, 1e-52, 1e-51, 1e-50, 1e-49, 1e-48, 1e-47,
1e-46, 1e-45, 1e-44, 1e-43, 1e-42, 1e-41, 1e-40, 1e-39, 1e-38,
1e-37, 1e-36, 1e-35, 1e-34, 1e-33, 1e-32, 1e-31, 1e-30, 1e-29,
1e-28, 1e-27, 1e-26, 1e-25, 1e-24, 1e-23, 1e-22, 1e-21, 1e-20,
1e-19, 1e-18, 1e-17, 1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11,
1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2,
1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16,
1e17, 1e18, 1e19, 1e20, 1e21, 1e22, 1e23, 1e24, 1e25,
1e26, 1e27, 1e28, 1e29, 1e30, 1e31, 1e32, 1e33, 1e34,
1e35, 1e36, 1e37, 1e38, 1e39, 1e40, 1e41, 1e42, 1e43,
1e44, 1e45, 1e46, 1e47, 1e48, 1e49, 1e50, 1e51, 1e52,
1e53, 1e54, 1e55, 1e56, 1e57, 1e58, 1e59, 1e60, 1e61,
1e62, 1e63, 1e64, 1e65, 1e66, 1e67, 1e68, 1e69, 1e70,
1e71, 1e72, 1e73, 1e74, 1e75, 1e76, 1e77, 1e78, 1e79,
1e80, 1e81, 1e82, 1e83, 1e84, 1e85, 1e86, 1e87, 1e88,
1e89, 1e90, 1e91, 1e92, 1e93, 1e94, 1e95, 1e96, 1e97,
1e98, 1e99, 1e100, 1e101, 1e102, 1e103, 1e104, 1e105, 1e106,
1e107, 1e108, 1e109, 1e110, 1e111, 1e112, 1e113, 1e114, 1e115,
1e116, 1e117, 1e118, 1e119, 1e120, 1e121, 1e122, 1e123, 1e124,
1e125, 1e126, 1e127, 1e128, 1e129, 1e130, 1e131, 1e132, 1e133,
1e134, 1e135, 1e136, 1e137, 1e138, 1e139, 1e140, 1e141, 1e142,
1e143, 1e144, 1e145, 1e146, 1e147, 1e148, 1e149, 1e150, 1e151,
1e152, 1e153, 1e154, 1e155, 1e156, 1e157, 1e158, 1e159, 1e160,
1e161, 1e162, 1e163, 1e164, 1e165, 1e166, 1e167, 1e168, 1e169,
1e170, 1e171, 1e172, 1e173, 1e174, 1e175, 1e176, 1e177, 1e178,
1e179, 1e180, 1e181, 1e182, 1e183, 1e184, 1e185, 1e186, 1e187,
1e188, 1e189, 1e190, 1e191, 1e192, 1e193, 1e194, 1e195, 1e196,
1e197, 1e198, 1e199, 1e200, 1e201, 1e202, 1e203, 1e204, 1e205,
1e206, 1e207, 1e208, 1e209, 1e210, 1e211, 1e212, 1e213, 1e214,
1e215, 1e216, 1e217, 1e218, 1e219, 1e220, 1e221, 1e222, 1e223,
1e224, 1e225, 1e226, 1e227, 1e228, 1e229, 1e230, 1e231, 1e232,
1e233, 1e234, 1e235, 1e236, 1e237, 1e238, 1e239, 1e240, 1e241,
1e242, 1e243, 1e244, 1e245, 1e246, 1e247, 1e248, 1e249, 1e250,
1e251, 1e252, 1e253, 1e254, 1e255, 1e256, 1e257, 1e258, 1e259,
1e260, 1e261, 1e262, 1e263, 1e264, 1e265, 1e266, 1e267, 1e268,
1e269, 1e270, 1e271, 1e272, 1e273, 1e274, 1e275, 1e276, 1e277,
1e278, 1e279, 1e280, 1e281, 1e282, 1e283, 1e284, 1e285, 1e286,
1e287, 1e288, 1e289, 1e290, 1e291, 1e292, 1e293, 1e294, 1e295,
1e296, 1e297, 1e298, 1e299, 1e300, 1e301, 1e302, 1e303, 1e304,
1e305, 1e306, 1e307, 1e308};
TEST_CASE("powers_of_ten") {
char buf[1024];
WARN_MESSAGE(1e-308 == std::pow(10, -308),
"On your system, the pow function is busted. Sorry about that.");
bool is_pow_correct{1e-308 == std::pow(10, -308)};
// large negative values should be zero.
int start_point = is_pow_correct ? -1000 : -307;
for (int i = start_point; i <= 308; ++i) {
INFO("i=" << i);
size_t n = size_t(snprintf(buf, sizeof(buf), "1e%d", i));
REQUIRE(n < sizeof(buf)); // if false, fails the test and exits
double actual;
auto result = fast_float::from_chars(buf, buf + 1000, actual);
double expected =
((i >= -323) ? testing_power_of_ten[i + 323] : std::pow(10, i));
auto expected_ec =
(i < -323 || i > 308) ? std::errc::result_out_of_range : std::errc();
CHECK_MESSAGE(result.ec == expected_ec, " I could not parse " << buf);
CHECK_MESSAGE(actual == expected,
"String '" << buf << "'parsed to " << actual);
}
}
template <typename T> std::string to_string(T d) {
std::string s(64, '\0');
auto written = std::snprintf(&s[0], s.size(), "%.*e",
std::numeric_limits<T>::max_digits10 - 1, d);
s.resize(size_t(written));
return s;
}
template <typename T> std::string to_long_string(T d) {
std::string s(4096, '\0');
auto written = std::snprintf(&s[0], s.size(), "%.*e",
std::numeric_limits<T>::max_digits10 * 10, d);
s.resize(size_t(written));
return s;
}
uint32_t get_mantissa(float f) {
uint32_t m;
memcpy(&m, &f, sizeof(f));
return (m & ((uint32_t(1) << 23) - 1));
}
uint64_t get_mantissa(double f) {
uint64_t m;
memcpy(&m, &f, sizeof(f));
return (m & ((uint64_t(1) << 57) - 1));
}
#ifdef __STDCPP_FLOAT64_T__
uint64_t get_mantissa(std::float64_t f) {
uint64_t m;
memcpy(&m, &f, sizeof(f));
return (m & ((uint64_t(1) << 10) - 1));
}
#endif
#ifdef __STDCPP_FLOAT32_T__
uint32_t get_mantissa(std::float32_t f) {
uint32_t m;
memcpy(&m, &f, sizeof(f));
return (m & ((uint32_t(1) << 10) - 1));
}
#endif
#ifdef __STDCPP_FLOAT16_T__
uint16_t get_mantissa(std::float16_t f) {
uint16_t m;
memcpy(&m, &f, sizeof(f));
return (m & ((uint16_t(1) << 10) - 1));
}
#endif
#ifdef __STDCPP_BFLOAT16_T__
uint16_t get_mantissa(std::bfloat16_t f) {
uint16_t m;
memcpy(&m, &f, sizeof(f));
return (m & ((uint16_t(1) << 7) - 1));
}
#endif
std::string append_zeros(std::string str, size_t number_of_zeros) {
std::string answer(str);
for (size_t i = 0; i < number_of_zeros; i++) {
answer += "0";
}
return answer;
}
namespace {
enum class Diag { runtime, comptime };
} // anonymous namespace
constexpr size_t global_string_capacity = 2048;
template <Diag diag, class T, typename result_type, typename stringtype>
constexpr void check_basic_test_result(stringtype str, result_type result,
T actual, T expected,
std::errc expected_ec) {
struct ComptimeDiag {
// Purposely not constexpr
static void error_not_equal() {}
};
#define FASTFLOAT_CHECK_EQ(...) \
if constexpr (diag == Diag::runtime) { \
char narrow[global_string_capacity]{}; \
for (size_t i = 0; i < str.size(); i++) { \
narrow[i] = char(str[i]); \
} \
INFO("str(char" << 8 * sizeof(typename stringtype::value_type) \
<< ")=" << narrow << "\n" \
<< " expected=" << fHexAndDec(expected) << "\n" \
<< " ..actual=" << fHexAndDec(actual) << "\n" \
<< " expected mantissa=" \
<< iHexAndDec(get_mantissa(expected)) << "\n" \
<< " ..actual mantissa=" \
<< iHexAndDec(get_mantissa(actual))); \
CHECK_EQ(__VA_ARGS__); \
} else { \
if ([](auto const &lhs, auto const &rhs) { \
return lhs != rhs; \
}(__VA_ARGS__)) { \
ComptimeDiag::error_not_equal(); \
} \
}
auto copysign = [](double x, double y) -> double {
#if FASTFLOAT_HAS_BIT_CAST
if (fast_float::cpp20_and_in_constexpr()) {
using equiv_int = std::make_signed_t<fast_float::equiv_uint_t<double>>;
auto const i = std::bit_cast<equiv_int>(y);
if (i < 0) {
return -x;
}
return x;
} else
#endif
return std::copysign(x, y);
};
auto isnan = [](double x) -> bool { return x != x; };
FASTFLOAT_CHECK_EQ(result.ec, expected_ec);
FASTFLOAT_CHECK_EQ(result.ptr, str.data() + str.size());
FASTFLOAT_CHECK_EQ(copysign(1, actual), copysign(1, expected));
FASTFLOAT_CHECK_EQ(isnan(actual), isnan(expected));
FASTFLOAT_CHECK_EQ(actual, expected);
#undef FASTFLOAT_CHECK_EQ
}
template <Diag diag, class T>
constexpr void basic_test(std::string_view str, T expected,
std::errc expected_ec = std::errc()) {
T actual{};
auto result =
fast_float::from_chars(str.data(), str.data() + str.size(), actual);