This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/5044] printf doesn't take the rounding mode into account


------- Additional Comments From vincent+libc at vinc17 dot org  2008-04-18 23:58 -------
(In reply to comment #10)
> For example 0.5001 is really 0x1.000d1b71758e20p-1

In my example, the exact value doesn't matter: the rounding to two digits will
be the same for any good approximation to 0.5001 (denoted ~0.5001 below).

> "Otherwise, the source value is bounded by two adjacent decimal strings L < U,
> both having DECIMAL_DIG significant digits; the value of the resultant decimal
> string D should satisfy L <= D <= U, with the extra stipulation that the error
> should have a correct sign for the current rounding direction."
> 
> This implies that either L or U (.50 or .51) are allowed!

No: if .50 is output, the error does not have a correct sign in rounding upward,
since 0.50 < ~0.5001. So, only .51 is allowed here. Now, this part of the ISO C
standard does not apply anyway since 2 digits are required and 2 <= DECIMAL_DIG.
You need to look at the beginning of the paragraph:

"For e, E, f, F, g, and G conversions, if the number of significant decimal
digits is at most DECIMAL_DIG, then the result should be correctly rounded."

and the correctly-rounded value is .51 here.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=5044

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]