This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/32448] [3.3 / 3.4 / 4.1 / 4.2 / 4.3 Regression] abs / printf bug
- From: "rob1weld at aol dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jun 2007 18:49:38 -0000
- Subject: [Bug c/32448] [3.3 / 3.4 / 4.1 / 4.2 / 4.3 Regression] abs / printf bug
- References: <bug-32448-13830@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #15 from rob1weld at aol dot com 2007-06-23 18:49 -------
>Andrew Pinski
>abs converts the float/double to an integer type so this is not a bug.
>Uros Bizjak
>The non-problem you are going after is in printf(). It takes variable arguments
>from the stack and interprets them according to the format string. Argument are
>pushed to the stack by the caller without any other communication with callee,
>so it is obvious that format string _must_ reflect the type of values on stack.
>Also note, that %f inherently converts float type to double, so your values on
>the stack are FUBAR as far as printf is concerned.
So what we end up with is something like this:
main(){
printf("%f %f %f %f\n", abs(1234.5678), fabs(1234.5678),
abs((int)1234.5678), abs((int)(1234.5678)));
}
and here is the incorrect output:
639356954161190327651780598819979664641251888147947213308332781758079574424033219293612810237966089410023577192498425554519097800758249636139201808050627475876578945300496861358730667076856621948936720606078976728760320.000000
0.000000 -0.007810 -0.000000
The first and third values are obviously wrong.
The second and fourth values agree - so (in theory) that is the "correct"
answer - according to the way that GCC is intended to operate (as per what
Andrew says).
If the "correct" answer is zero (without concerning ourselves if it is plus
zero or minus zero) then why are the _third_ and _fourth_ answer different!
abs((int)1234.5678) = -0.007810
abs((int)(1234.5678)) = -0.000000
Should the cast work without the extra parentheses.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32448