@@ -401,6 +401,178 @@ static void TestParseDouble() {
401
401
TEST_DOUBLE (fullPrecision, " 2.48e-324" , 2.48e-324 );
402
402
TEST_DOUBLE (fullPrecision, " 2.5e-324" , 2.5e-324 );
403
403
404
+ #if 0
405
+ // Test (length + exponent) overflow
406
+ TEST_DOUBLE(fullPrecision, "0e+2147483647", 0.0);
407
+ TEST_DOUBLE(fullPrecision, "0e-2147483648", 0.0);
408
+ TEST_DOUBLE(fullPrecision, "1e-2147483648", 0.0);
409
+ TEST_DOUBLE(fullPrecision, "0e+9223372036854775807", 0.0);
410
+ TEST_DOUBLE(fullPrecision, "0e-9223372036854775808", 0.0);
411
+ #endif
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
418
+
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
+ // 9007199254740991 * 2^971 (max normal)
436
+ TEST_DOUBLE(fullPrecision,
437
+ "1.797693134862315708145274237317043567980705675258449965989174768031572607800285"
438
+ "38760589558632766878171540458953514382464234321326889464182768467546703537516986"
439
+ "04991057655128207624549009038932894407586850845513394230458323690322294816580855"
440
+ "9332123348274797826204144723168738177180919299881250404026184124858368e+308",
441
+ 1.797693134862315708e+308 // 0x1.fffffffffffffp1023
442
+ );
443
+ TEST_DOUBLE(fullPrecision,
444
+ "0.00000000000000000000000000000000000000000000000000000000000"
445
+ "0000000000000000000000000000000000000000000000000000000000000"
446
+ "0000000000000000000000000000000000000000000000000000000000000"
447
+ "0000000000000000000000000000000000000000000000000000000000000"
448
+ "0000000000000000000000000000000000000000000000000000000000000"
449
+ "0000000000000000000024703282292062327208828439643411068618252"
450
+ "9901307162382212792841250337753635104375932649918180817996189"
451
+ "8982823477228588654633283551779698981993873980053909390631503"
452
+ "5659515570226392290858392449105184435931802849936536152500319"
453
+ "3704576782492193656236698636584807570015857692699037063119282"
454
+ "7955855133292783433840935197801553124659726357957462276646527"
455
+ "2827220056374006485499977096599470454020828166226237857393450"
456
+ "7363390079677619305775067401763246736009689513405355374585166"
457
+ "6113422376667860416215968046191446729184030053005753084904876"
458
+ "5391711386591646239524912623653881879636239373280423891018672"
459
+ "3484976682350898633885879256283027559956575244555072551893136"
460
+ "9083625477918694866799496832404970582102851318545139621383772"
461
+ "2826145437693412532098591327667236328125",
462
+ 0.0);
463
+ // 9007199254740991 * 2^-1074 = (2^53 - 1) * 2^-1074
464
+ TEST_DOUBLE(fullPrecision,
465
+ "4.450147717014402272114819593418263951869639092703291296046852219449644444042153"
466
+ "89103305904781627017582829831782607924221374017287738918929105531441481564124348"
467
+ "67599762821265346585071045737627442980259622449029037796981144446145705102663115"
468
+ "10031828794952795966823603998647925096578034214163701381261333311989876551545144"
469
+ "03152612538132666529513060001849177663286607555958373922409899478075565940981010"
470
+ "21612198814605258742579179000071675999344145086087205681577915435923018910334964"
471
+ "86942061405218289243144579760516365090360651414037721744226256159024466852576737"
472
+ "24464300755133324500796506867194913776884780053099639677097589658441378944337966"
473
+ "21993967316936280457084866613206797017728916080020698679408551343728867675409720"
474
+ "757232455434770912461317493580281734466552734375e-308",
475
+ 4.450147717014402272e-308 // 0x1.fffffffffffffp-1022
476
+ );
477
+ // 9007199254740990 * 2^-1074
478
+ TEST_DOUBLE(fullPrecision,
479
+ "4.450147717014401778049173752171719775300846224481918930987049605124880018456471"
480
+ "39035755177760751831052846195619008686241717547743167145836439860405887584484471"
481
+ "19639655002484083577939142623582164522087943959208000909794783876158397872163051"
482
+ "22622675229968408654350206725478309956546318828765627255022767720818849892988457"
483
+ "26333908582101604036318532842699932130356061901518261174396928478121372742040102"
484
+ "17446565569357687263889031732270082446958029584739170416643195242132750803227473"
485
+ "16608838720742955671061336566907126801014814608027120593609275183716632624844904"
486
+ "31985250929886016737037234388448352929102742708402644340627409931664203093081360"
487
+ "70794835812045179006047003875039546061891526346421705014598610179523165038319441"
488
+ "51446491086954182492263498716056346893310546875e-308",
489
+ 4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
490
+ );
491
+ // half way between the two numbers above.
492
+ // round to nearest even.
493
+ TEST_DOUBLE(fullPrecision,
494
+ "4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
495
+ "64069530541271189424317838013700808305231545782515453032382772695923684574304409"
496
+ "93619708911874715081505094180604803751173783204118519353387964161152051487413083"
497
+ "16327252012460602310586905362063117526562176521464664318142050516404363222266800"
498
+ "64743260560117135282915796422274554896821334728738317548403413978098469341510556"
499
+ "19529382191981473003234105366170879223151087335413188049110555339027884856781219"
500
+ "01775450062980622457102958163711745945687733011032421168917765671370549738710820"
501
+ "78224775842509670618916870627821633352993761380751142008862499795052791018709663"
502
+ "46394401564490729731565935244123171539810221213221201847003580761626016356864581"
503
+ "1358486831521563686919762403704226016998291015625e-308",
504
+ 4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
505
+ );
506
+ TEST_DOUBLE(fullPrecision,
507
+ "4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
508
+ "64069530541271189424317838013700808305231545782515453032382772695923684574304409"
509
+ "93619708911874715081505094180604803751173783204118519353387964161152051487413083"
510
+ "16327252012460602310586905362063117526562176521464664318142050516404363222266800"
511
+ "64743260560117135282915796422274554896821334728738317548403413978098469341510556"
512
+ "19529382191981473003234105366170879223151087335413188049110555339027884856781219"
513
+ "01775450062980622457102958163711745945687733011032421168917765671370549738710820"
514
+ "78224775842509670618916870627821633352993761380751142008862499795052791018709663"
515
+ "46394401564490729731565935244123171539810221213221201847003580761626016356864581"
516
+ "13584868315215636869197624037042260169982910156250000000000000000000000000000000"
517
+ "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
518
+ "00000000000000000000000000000000000000000000000000000000000000000000000000000000e-308",
519
+ 4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
520
+ );
521
+ // ... round up
522
+ TEST_DOUBLE(fullPrecision,
523
+ "4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
524
+ "64069530541271189424317838013700808305231545782515453032382772695923684574304409"
525
+ "93619708911874715081505094180604803751173783204118519353387964161152051487413083"
526
+ "16327252012460602310586905362063117526562176521464664318142050516404363222266800"
527
+ "64743260560117135282915796422274554896821334728738317548403413978098469341510556"
528
+ "19529382191981473003234105366170879223151087335413188049110555339027884856781219"
529
+ "01775450062980622457102958163711745945687733011032421168917765671370549738710820"
530
+ "78224775842509670618916870627821633352993761380751142008862499795052791018709663"
531
+ "46394401564490729731565935244123171539810221213221201847003580761626016356864581"
532
+ "13584868315215636869197624037042260169982910156250000000000000000000000000000000"
533
+ "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
534
+ "00000000000000000000000000000000000000000000000000000000000000000000000000000001e-308",
535
+ 4.450147717014402272e-308 // 0x1.fffffffffffffp-1022
536
+ );
537
+ // ... round down
538
+ TEST_DOUBLE(fullPrecision,
539
+ "4.450147717014402025081996672794991863585242658592605113516950912287262231249312"
540
+ "64069530541271189424317838013700808305231545782515453032382772695923684574304409"
541
+ "93619708911874715081505094180604803751173783204118519353387964161152051487413083"
542
+ "16327252012460602310586905362063117526562176521464664318142050516404363222266800"
543
+ "64743260560117135282915796422274554896821334728738317548403413978098469341510556"
544
+ "19529382191981473003234105366170879223151087335413188049110555339027884856781219"
545
+ "01775450062980622457102958163711745945687733011032421168917765671370549738710820"
546
+ "78224775842509670618916870627821633352993761380751142008862499795052791018709663"
547
+ "46394401564490729731565935244123171539810221213221201847003580761626016356864581"
548
+ "13584868315215636869197624037042260169982910156249999999999999999999999999999999"
549
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
550
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999e-308",
551
+ 4.450147717014401778e-308 // 0x1.ffffffffffffep-1022
552
+ );
553
+ // Slightly below half way between max-normal and infinity.
554
+ // Should round down.
555
+ TEST_DOUBLE(fullPrecision,
556
+ "1.797693134862315807937289714053034150799341327100378269361737789804449682927647"
557
+ "50946649017977587207096330286416692887910946555547851940402630657488671505820681"
558
+ "90890200070838367627385484581771153176447573027006985557136695962284291481986083"
559
+ "49364752927190741684443655107043427115596995080930428801779041744977919999999999"
560
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
561
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
562
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
563
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
564
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
565
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
566
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
567
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
568
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
569
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
570
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999"
571
+ "99999999999999999999999999999999999999999999999999999999999999999999999999999999e+308",
572
+ 1.797693134862315708e+308 // 0x1.fffffffffffffp1023
573
+ );
574
+ #endif
575
+
404
576
#undef TEST_DOUBLE
405
577
}
406
578
@@ -499,6 +671,22 @@ TEST(Reader, ParseNumber_Error) {
499
671
" 03685473724737236837236775297525854775297525472975254737236873720170151235473783"
500
672
" 7236737247372368772473723683723456789012E66" , 0 , 283 );
501
673
674
+ #if 0
675
+ // Test (length + exponent) overflow
676
+ TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1e+2147483647", 0, 13);
677
+ TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1e+9223372036854775807", 0, 22);
678
+ TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1e+10000", 0, 8);
679
+ TEST_NUMBER_ERROR(kParseErrorNumberTooBig, "1e+50000", 0, 8);
680
+ #endif
681
+
682
+ // 9007199254740992 * 2^971 ("infinity")
683
+ TEST_NUMBER_ERROR (kParseErrorNumberTooBig ,
684
+ " 1.797693134862315907729305190789024733617976978942306572734300811577326758055009"
685
+ " 63132708477322407536021120113879871393357658789768814416622492847430639474124377"
686
+ " 76789342486548527630221960124609411945308295208500576883815068234246288147391311"
687
+ " 0540827237163350510684586298239947245938479716304835356329624224137216e+308" , 0 , 315 );
688
+
689
+ #if 0
502
690
// Half way between max-normal and infinity
503
691
// Should round to infinity in nearest-even mode.
504
692
TEST_NUMBER_ERROR(kParseErrorNumberTooBig,
@@ -533,7 +721,7 @@ TEST(Reader, ParseNumber_Error) {
533
721
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
534
722
"00000000000000000000000000000000000000000000000000000000000000000000000000000000"
535
723
"00000000000000000000000000000000000000000000000000000000000000000000000000000001e+308", 0, 1125);
536
-
724
+ # endif
537
725
#undef TEST_NUMBER_ERROR
538
726
}
539
727
0 commit comments