Commit 50f30b3
committed
stdlib_noniso.cpp: dtostrf(), subtract rounding if number is negative
If we are working with a negative number, then *adding* the rounding
onto the number has the opposite to the intended effect. Need to check
if the number is negative, and if so, subtract the rounding instead of
adding.
It may appear that a cleaner solution to this is to simply move the
"handle negative numbers" block (starting on what is now line 222)
before the "round up to the precision" block (starting on what is now
line 202). However, I don't think this will work without a substantial
re-design of this function, for the following reasons;
Any leading padding must be added before handling a negative number
(adding the '-' char. to output, and then flipping the number's sign for
calculations). And in order to add the right amount of padding, we must run
digitsBe4Decimal first, and in order to guarantee an accurate result
from *that*, the rounding-up must have been done. So there's a fairly
rigid order here.
Oh, and I also removed the 'goto end', and the label, since an if()
work just as well. Can't remember why I even added that in the first
place.1 parent 3f61b65 commit 50f30b3
1 file changed
+14
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
| |||
235 | 239 | | |
236 | 240 | | |
237 | 241 | | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
246 | 251 | | |
247 | 252 | | |
248 | | - | |
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
| |||
0 commit comments