@@ -410,28 +410,29 @@ static void TestParseDouble() {
410
410
TEST_DOUBLE(fullPrecision, "0e-9223372036854775808", 0.0);
411
411
#endif
412
412
413
- #if 0
414
- // Slightly above max-normal
415
- // Fails with "normal" precision
416
- TEST_DOUBLE(fullPrecision, "1.7976931348623158e+308", 1.7976931348623158e+308);
417
- #endif
413
+ if (fullPrecision)
414
+ {
415
+ // Slightly above max-normal
416
+ TEST_DOUBLE (fullPrecision, " 1.7976931348623158e+308" , 1.7976931348623158e+308 );
417
+
418
+ TEST_DOUBLE (fullPrecision,
419
+ " 17976931348623157081452742373170435679807056752584499659891747680315726"
420
+ " 07800285387605895586327668781715404589535143824642343213268894641827684"
421
+ " 67546703537516986049910576551282076245490090389328944075868508455133942"
422
+ " 30458323690322294816580855933212334827479782620414472316873817718091929"
423
+ " 9881250404026184124858368" ,
424
+ std::numeric_limits<double >::max ());
425
+
426
+ TEST_DOUBLE (fullPrecision,
427
+ " 243546080556034731077856379609316893158278902575447060151047"
428
+ " 212703405344938119816206067372775299130836050315842578309818"
429
+ " 316450894337978612745889730079163798234256495613858256849283"
430
+ " 467066859489192118352020514036083287319232435355752493038825"
431
+ " 828481044358810649108367633313557305310641892225870327827273"
432
+ " 41408256.000000" ,
433
+ 2.4354608055603473e+307 );
434
+ }
418
435
419
- #if 0
420
- TEST_DOUBLE(fullPrecision,
421
- "17976931348623157081452742373170435679807056752584499659891747680315726"
422
- "07800285387605895586327668781715404589535143824642343213268894641827684"
423
- "67546703537516986049910576551282076245490090389328944075868508455133942"
424
- "30458323690322294816580855933212334827479782620414472316873817718091929"
425
- "9881250404026184124858368",
426
- std::numeric_limits<double>::max());
427
- TEST_DOUBLE(fullPrecision,
428
- "243546080556034731077856379609316893158278902575447060151047"
429
- "212703405344938119816206067372775299130836050315842578309818"
430
- "316450894337978612745889730079163798234256495613858256849283"
431
- "467066859489192118352020514036083287319232435355752493038825"
432
- "828481044358810649108367633313557305310641892225870327827273"
433
- "41408256.000000",
434
- 2.4354608055603473e+307);
435
436
// 9007199254740991 * 2^971 (max normal)
436
437
TEST_DOUBLE (fullPrecision,
437
438
" 1.797693134862315708145274237317043567980705675258449965989174768031572607800285"
@@ -440,6 +441,9 @@ static void TestParseDouble() {
440
441
" 9332123348274797826204144723168738177180919299881250404026184124858368e+308" ,
441
442
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
442
443
);
444
+ #if 0
445
+ // TODO:
446
+ // Should work at least in full-precision mode...
443
447
TEST_DOUBLE(fullPrecision,
444
448
"0.00000000000000000000000000000000000000000000000000000000000"
445
449
"0000000000000000000000000000000000000000000000000000000000000"
@@ -460,6 +464,7 @@ static void TestParseDouble() {
460
464
"9083625477918694866799496832404970582102851318545139621383772"
461
465
"2826145437693412532098591327667236328125",
462
466
0.0);
467
+ #endif
463
468
// 9007199254740991 * 2^-1074 = (2^53 - 1) * 2^-1074
464
469
TEST_DOUBLE (fullPrecision,
465
470
" 4.450147717014402272114819593418263951869639092703291296046852219449644444042153"
@@ -518,7 +523,10 @@ static void TestParseDouble() {
518
523
" 00000000000000000000000000000000000000000000000000000000000000000000000000000000e-308" ,
519
524
4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
520
525
);
526
+ #if 0
521
527
// ... round up
528
+ // TODO:
529
+ // Should work at least in full-precision mode...
522
530
TEST_DOUBLE(fullPrecision,
523
531
"4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
524
532
"64069530541271189424317838013700808305231545782515453032382772695923684574304409"
@@ -534,6 +542,7 @@ static void TestParseDouble() {
534
542
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e-308",
535
543
4.450147717014402272e-308 // 0x1.fffffffffffffp-1022
536
544
);
545
+ #endif
537
546
// ... round down
538
547
TEST_DOUBLE (fullPrecision,
539
548
" 4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
@@ -571,7 +580,6 @@ static void TestParseDouble() {
571
580
" 99999999999999999999999999999999999999999999999999999999999999999999999999999999e+308" ,
572
581
1.797693134862315708e+308 // 0x1.fffffffffffffp1023
573
582
);
574
- #endif
575
583
576
584
#undef TEST_DOUBLE
577
585
}
@@ -618,7 +626,8 @@ TEST(Reader, ParseNumber_NormalPrecisionError) {
618
626
printf (" ULP Average = %g, Max = %g \n " , ulpSum / count, ulpMax);
619
627
}
620
628
621
- TEST (Reader, ParseNumber_Error) {
629
+ template <bool fullPrecision>
630
+ static void TestParseNumberError () {
622
631
#define TEST_NUMBER_ERROR (errorCode, str, errorOffset, streamPos ) \
623
632
{ \
624
633
char buffer[2048 ]; \
@@ -627,7 +636,7 @@ TEST(Reader, ParseNumber_Error) {
627
636
InsituStringStream s (buffer); \
628
637
BaseReaderHandler<> h; \
629
638
Reader reader; \
630
- EXPECT_FALSE (reader.Parse (s, h)); \
639
+ EXPECT_FALSE (reader.Parse <fullPrecision ? kParseFullPrecisionFlag : 0 > (s, h)); \
631
640
EXPECT_EQ (errorCode, reader.GetParseErrorCode ());\
632
641
EXPECT_EQ (errorOffset, reader.GetErrorOffset ());\
633
642
EXPECT_EQ (streamPos, s.Tell ());\
@@ -686,45 +695,63 @@ TEST(Reader, ParseNumber_Error) {
686
695
" 76789342486548527630221960124609411945308295208500576883815068234246288147391311"
687
696
" 0540827237163350510684586298239947245938479716304835356329624224137216e+308" , 0 , 315 );
688
697
689
- #if 0
690
- // Half way between max-normal and infinity
691
- // Should round to infinity in nearest-even mode.
692
- TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
693
- "1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
694
- "50946649017977587207096330286416692887910946555547851940402630657488671505820681"
695
- "90890200070838367627385484581771153176447573027006985557136695962284291481986083"
696
- "49364752927190741684443655107043427115596995080930428801779041744977920000000000"
697
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
698
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
699
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
700
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
701
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
702
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
703
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
704
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
705
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
706
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000e+308", 0, 1125);
707
- // ...round up
698
+ // TODO:
699
+ // These tests (currently) fail in normal-precision mode
700
+ if (fullPrecision)
701
+ {
702
+ // Half way between max-normal and infinity
703
+ // Should round to infinity in nearest-even mode.
704
+ TEST_NUMBER_ERROR (kParseErrorNumberTooBig ,
705
+ " 1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
706
+ " 50946649017977587207096330286416692887910946555547851940402630657488671505820681"
707
+ " 90890200070838367627385484581771153176447573027006985557136695962284291481986083"
708
+ " 49364752927190741684443655107043427115596995080930428801779041744977920000000000"
709
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
710
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
711
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
712
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
713
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
714
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
715
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
716
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
717
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
718
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000e+308" , 0 , 1125 );
719
+ // ...round up
720
+ TEST_NUMBER_ERROR (kParseErrorNumberTooBig ,
721
+ " 1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
722
+ " 50946649017977587207096330286416692887910946555547851940402630657488671505820681"
723
+ " 90890200070838367627385484581771153176447573027006985557136695962284291481986083"
724
+ " 49364752927190741684443655107043427115596995080930428801779041744977920000000000"
725
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
726
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
727
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
728
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
729
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
730
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
731
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
732
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
733
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
734
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
735
+ " 00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308" , 0 , 1205 );
736
+ }
737
+
708
738
TEST_NUMBER_ERROR (kParseErrorNumberTooBig ,
709
- "1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
710
- "50946649017977587207096330286416692887910946555547851940402630657488671505820681"
711
- "90890200070838367627385484581771153176447573027006985557136695962284291481986083"
712
- "49364752927190741684443655107043427115596995080930428801779041744977920000000000"
713
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
714
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
739
+ " 10000000000000000000000000000000000000000000000000000000000000000000000000000000"
715
740
" 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
716
741
" 00000000000000000000000000000000000000000000000000000000000000000000000000000000"
717
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
718
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
719
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
720
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
721
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
722
- "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
723
- "00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1125);
724
- #endif
742
+ " 0000000000000000000000000000000000000000000000000000000000000000000001" , 0 , 310 );
743
+
725
744
#undef TEST_NUMBER_ERROR
726
745
}
727
746
747
+ TEST (Reader, ParseNumberError_NormalPrecisionDouble) {
748
+ TestParseNumberError<false >();
749
+ }
750
+
751
+ TEST (Reader, ParseNumberError_FullPrecisionDouble) {
752
+ TestParseNumberError<true >();
753
+ }
754
+
728
755
template <typename Encoding>
729
756
struct ParseStringHandler : BaseReaderHandler<Encoding, ParseStringHandler<Encoding> > {
730
757
ParseStringHandler () : str_(0 ), length_(0 ), copy_() {}
0 commit comments