This is the mail archive of the ecos-bugs@sourceware.org mailing list for the eCos 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 20804] Misbehavior of printf %e format.


Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=20804

--- Comment #11 from Bernd Edlinger <bernd.edlinger@hotmail.de> 2012-08-14 09:49:47 BST ---
(In reply to comment #7)
> Yes I object, looking at the patch, I don't think it's right. I don't see the
> reason for this:
> -                                if ((ch != 'g' && ch != 'G') || (flags&ALT))
> +                                if (ch == 'f')
> The precision (e.g. 18 in "%.18f") is defined as the number of digits to appear
> after the radix character for e, E, and f conversions, or the maximum number of
> significant digits for g and G conversions. I don't see how the above can fit
> into that, nor do I have confidence that the ALT flag ('#') is correctly
> handled.
Hello,

let me explain this.

For the %f and %g format the ALT means we always have a "." output.
"%#.0f", 3.14  would print "3." here we could add zeros if we want.
while "%.0f", 3.14 would pritn "3", adding zeroes here would be bad..

Why I dont care about the ALT here, is because the precision is > 15,
therefore %.15f and %#.15f produce the same output. always.
and it is safe to append zeros, except in the case where the number
is "NAN" or "INF", but appending 3 zeros to NAN is only a fauxpas.

But to %.15g and %#.15g the ALT flag makes a difference.
if the number has no digits after the "." then
"%.15g", 3.0 prints "3" and adding 3 zeros here would be a bad idea.
while "%#.15g" prints "3.00000000000000", so adding zeros is OK.
that is what was the assumption behind "if ((ch != 'g' && ch != 'G') ||
(flags&ALT))"

But they forgot all about the %e format, and that the %g format defaults
to %e if the number is very small or very large.

Bernd.

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


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