@@ -38,7 +38,7 @@ function writefixed(buf, pos, v::T,
3838 mant = bits & MANTISSA_MASK
3939 exp = Int ((bits >> 52 ) & EXP_MASK)
4040
41- if exp == 0
41+ if exp == 0 # subnormal
4242 e2 = 1 - 1023 - 52
4343 m2 = mant
4444 else
@@ -53,7 +53,7 @@ function writefixed(buf, pos, v::T,
5353 i = len - 1
5454 while i >= 0
5555 j = p10bits - e2
56- #= @inbounds =# mula, mulb, mulc = POW10_SPLIT[POW10_OFFSET[idx + 1 ] + i + 1 ]
56+ mula, mulb, mulc = POW10_SPLIT[POW10_OFFSET[idx + 1 ] + i + 1 ]
5757 digits = mulshiftmod1e9 (m2 << 8 , mula, mulb, mulc, j + 8 )
5858 if nonzero
5959 pos = append_nine_digits (digits, buf, pos)
@@ -103,7 +103,7 @@ function writefixed(buf, pos, v::T,
103103 end
104104 break
105105 end
106- #= @inbounds =# mula, mulb, mulc = POW10_SPLIT_2[p + 1 ]
106+ mula, mulb, mulc = POW10_SPLIT_2[p + 1 ]
107107 digits = mulshiftmod1e9 (m2 << 8 , mula, mulb, mulc, j + 8 )
108108 if i < blocks - 1
109109 pos = append_nine_digits (digits, buf, pos)
@@ -118,11 +118,11 @@ function writefixed(buf, pos, v::T,
118118 k += 1
119119 end
120120 if lastDigit != 5
121- roundUp = lastDigit > 5
121+ roundUp = lastDigit > 5 ? 1 : 0
122122 else
123123 requiredTwos = - e2 - precision - 1
124124 trailingZeros = requiredTwos <= 0 || (requiredTwos < 60 && pow2 (m2, requiredTwos))
125- roundUp = trailingZeros ? 2 : 1
125+ roundUp = trailingZeros ? 2 : 1 # 2 means round only if odd
126126 end
127127 if maximum > 0
128128 pos = append_c_digits (maximum, digits, buf, pos)
@@ -137,13 +137,13 @@ function writefixed(buf, pos, v::T,
137137 while true
138138 roundPos -= 1
139139 if roundPos == (startpos - 1 ) || (buf[roundPos] == UInt8 (' -' )) || (plus && buf[roundPos] == UInt8 (' +' )) || (space && buf[roundPos] == UInt8 (' ' ))
140+ buf[pos] = UInt8 (' 0' )
140141 buf[roundPos + 1 ] = UInt8 (' 1' )
141142 if dotPos > 1
142143 buf[dotPos] = UInt8 (' 0' )
143144 buf[dotPos + 1 ] = decchar
144145 hasfractional = true
145146 end
146- buf[pos] = UInt8 (' 0' )
147147 pos += 1
148148 break
149149 end
0 commit comments