@@ -450,18 +450,18 @@ fileprivate func hexFloat(
450450) -> ParseResult {
451451 var i = start + 2 // Skip leading '0x'
452452 let firstDigitOffset = i
453-
453+ let limit = UInt64 ( 1 ) << 60
454454 var significand : UInt64 = 0
455455
456456 //
457457 // Digits before the binary point
458458 //
459459
460460 // Accumulate the most significant 64 bits...
461- while i < input. count && hexdigit ( input [ i] ) < 16 && significand < ( 1 << 60 ) {
462- significand &<<= 4
463- significand += UInt64 ( hexdigit ( input [ i] ) )
464- i += 1
461+ while i < input. count && hexdigit ( input [ i] ) < 16 && significand < limit {
462+ significand &<<= 4
463+ significand += UInt64 ( hexdigit ( input [ i] ) )
464+ i += 1
465465 }
466466
467467 // Initialize binary exponent to the number of bits we collected above
@@ -521,7 +521,7 @@ fileprivate func hexFloat(
521521 }
522522 }
523523 // Pack more bits into the accumulator (up to 60)
524- while i < input. count && hexdigit ( input [ i] ) < 16 && significand < ( 1 << 60 ) {
524+ while i < input. count && hexdigit ( input [ i] ) < 16 && significand < limit {
525525 significand &<<= 4
526526 significand += UInt64 ( hexdigit ( input [ i] ) )
527527 i += 1
@@ -631,12 +631,12 @@ fileprivate func hexFloat(
631631 && ( targetSignificand & 1 ) == 1 ) ) {
632632 // Round up, test for overflow
633633 targetSignificand += 1
634- if targetSignificand >= ( 1 << targetFormat. significandBits) {
634+ if targetSignificand >= ( UInt64 ( 1 ) << targetFormat. significandBits) {
635635 // Normal overflowed, need to renormalize
636636 targetSignificand >>= 1
637637 binaryExponent += 1
638638 } else if ( binaryExponent < targetFormat. minBinaryExponent
639- && targetSignificand >= ( 1 << ( targetFormat. significandBits - 1 ) ) ) {
639+ && targetSignificand >= ( UInt64 ( 1 ) << ( targetFormat. significandBits - 1 ) ) ) {
640640 // Subnormal overflowed to normal
641641 binaryExponent += 1
642642 }
@@ -1769,7 +1769,7 @@ fileprivate func slowDecimalToBinary(
17691769 count: targetFormat. significandBits,
17701770 remainderNonZero: false )
17711771
1772- if significand >= ( 1 &<< targetFormat. significandBits) {
1772+ if significand >= ( UInt64 ( 1 ) &<< targetFormat. significandBits) {
17731773 significand >>= 1
17741774 binaryExponent &+= 1
17751775 }
@@ -1865,7 +1865,7 @@ fileprivate func slowDecimalToBinary(
18651865 range: quotientRange,
18661866 count: targetFormat. significandBits,
18671867 remainderNonZero: remainderNonZero)
1868- if significand >= ( 1 &<< targetFormat. significandBits) {
1868+ if significand >= ( UInt64 ( 1 ) &<< targetFormat. significandBits) {
18691869 significand >>= 1
18701870 binaryExponent &+= 1
18711871 }
@@ -1889,7 +1889,7 @@ fileprivate func slowDecimalToBinary(
18891889 // exponent. Then we've transitioned from a subnormal to
18901890 // a normal, so the extra overflow bit will naturally get
18911891 // dropped, we just have to bump the exponent.
1892- if significand >= ( 1 &<< ( targetFormat. significandBits &- 1 ) ) {
1892+ if significand >= ( UInt64 ( 1 ) &<< ( targetFormat. significandBits &- 1 ) ) {
18931893 binaryExponent &+= 1
18941894 }
18951895 targetSignificand = significand
0 commit comments