@@ -38,7 +38,7 @@ function writefixed(buf, pos, v::T,
38
38
mant = bits & MANTISSA_MASK
39
39
exp = Int ((bits >> 52 ) & EXP_MASK)
40
40
41
- if exp == 0
41
+ if exp == 0 # subnormal
42
42
e2 = 1 - 1023 - 52
43
43
m2 = mant
44
44
else
@@ -53,7 +53,7 @@ function writefixed(buf, pos, v::T,
53
53
i = len - 1
54
54
while i >= 0
55
55
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 ]
57
57
digits = mulshiftmod1e9 (m2 << 8 , mula, mulb, mulc, j + 8 )
58
58
if nonzero
59
59
pos = append_nine_digits (digits, buf, pos)
@@ -103,7 +103,7 @@ function writefixed(buf, pos, v::T,
103
103
end
104
104
break
105
105
end
106
- #= @inbounds =# mula, mulb, mulc = POW10_SPLIT_2[p + 1 ]
106
+ mula, mulb, mulc = POW10_SPLIT_2[p + 1 ]
107
107
digits = mulshiftmod1e9 (m2 << 8 , mula, mulb, mulc, j + 8 )
108
108
if i < blocks - 1
109
109
pos = append_nine_digits (digits, buf, pos)
@@ -118,11 +118,11 @@ function writefixed(buf, pos, v::T,
118
118
k += 1
119
119
end
120
120
if lastDigit != 5
121
- roundUp = lastDigit > 5
121
+ roundUp = lastDigit > 5 ? 1 : 0
122
122
else
123
123
requiredTwos = - e2 - precision - 1
124
124
trailingZeros = requiredTwos <= 0 || (requiredTwos < 60 && pow2 (m2, requiredTwos))
125
- roundUp = trailingZeros ? 2 : 1
125
+ roundUp = trailingZeros ? 2 : 1 # 2 means round only if odd
126
126
end
127
127
if maximum > 0
128
128
pos = append_c_digits (maximum, digits, buf, pos)
@@ -137,13 +137,13 @@ function writefixed(buf, pos, v::T,
137
137
while true
138
138
roundPos -= 1
139
139
if roundPos == (startpos - 1 ) || (buf[roundPos] == UInt8 (' -' )) || (plus && buf[roundPos] == UInt8 (' +' )) || (space && buf[roundPos] == UInt8 (' ' ))
140
+ buf[pos] = UInt8 (' 0' )
140
141
buf[roundPos + 1 ] = UInt8 (' 1' )
141
142
if dotPos > 1
142
143
buf[dotPos] = UInt8 (' 0' )
143
144
buf[dotPos + 1 ] = decchar
144
145
hasfractional = true
145
146
end
146
- buf[pos] = UInt8 (' 0' )
147
147
pos += 1
148
148
break
149
149
end
0 commit comments