@@ -57,7 +57,7 @@ function writefixed(buf, pos, v::T,
57
57
mant = bits & MANTISSA_MASK
58
58
exp = Int ((bits >> 52 ) & EXP_MASK)
59
59
60
- if exp == 0
60
+ if exp == 0 # subnormal
61
61
e2 = 1 - 1023 - 52
62
62
m2 = mant
63
63
else
@@ -82,7 +82,7 @@ function writefixed(buf, pos, v::T,
82
82
i = len - 1
83
83
while i >= 0
84
84
j = p10bits - e2
85
- #= @inbounds =# mula, mulb, mulc = POW10_SPLIT[POW10_OFFSET[idx + 1 ] + i + 1 ]
85
+ mula, mulb, mulc = POW10_SPLIT[POW10_OFFSET[idx + 1 ] + i + 1 ]
86
86
digits = mulshiftmod1e9 (m2 << 8 , mula, mulb, mulc, j + 8 )
87
87
if nonzero
88
88
pos = append_nine_digits (digits, buf, pos)
@@ -132,7 +132,7 @@ function writefixed(buf, pos, v::T,
132
132
end
133
133
break
134
134
end
135
- #= @inbounds =# mula, mulb, mulc = POW10_SPLIT_2[p + 1 ]
135
+ mula, mulb, mulc = POW10_SPLIT_2[p + 1 ]
136
136
digits = mulshiftmod1e9 (m2 << 8 , mula, mulb, mulc, j + 8 )
137
137
if i < blocks - 1
138
138
pos = append_nine_digits (digits, buf, pos)
@@ -147,11 +147,11 @@ function writefixed(buf, pos, v::T,
147
147
k += 1
148
148
end
149
149
if lastDigit != 5
150
- roundUp = lastDigit > 5
150
+ roundUp = lastDigit > 5 ? 1 : 0
151
151
else
152
152
requiredTwos = - e2 - precision - 1
153
153
trailingZeros = requiredTwos <= 0 || (requiredTwos < 60 && pow2 (m2, requiredTwos))
154
- roundUp = trailingZeros ? 2 : 1
154
+ roundUp = trailingZeros ? 2 : 1 # 2 means round only if odd
155
155
end
156
156
if maximum > 0
157
157
pos = append_c_digits (maximum, digits, buf, pos)
@@ -166,13 +166,13 @@ function writefixed(buf, pos, v::T,
166
166
while true
167
167
roundPos -= 1
168
168
if roundPos == (startpos - 1 ) || (buf[roundPos] == UInt8 (' -' )) || (plus && buf[roundPos] == UInt8 (' +' )) || (space && buf[roundPos] == UInt8 (' ' ))
169
+ buf[pos] = UInt8 (' 0' )
169
170
buf[roundPos + 1 ] = UInt8 (' 1' )
170
171
if dotPos > 1
171
172
buf[dotPos] = UInt8 (' 0' )
172
173
buf[dotPos + 1 ] = decchar
173
174
hasfractional = true
174
175
end
175
- buf[pos] = UInt8 (' 0' )
176
176
pos += 1
177
177
break
178
178
end
0 commit comments