Bug 12129 - Unexpected loss of floating point precision in assignment
Summary: Unexpected loss of floating point precision in assignment
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-02 05:04 UTC by preciseflight
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description preciseflight 2003-09-02 05:04:39 UTC
#include <stdio.h>

#define OP(x) ((x) * .29425635593220338949)

int main (void) {
        double a = 5671.92506245995003720887;
        double b = OP (a);

        printf ("%d %d\n", (int) OP (a), (int) b);

        return 0;
}

On an i386 (gcc 2.95.4, 3.3), the output is:
1668 1669

Clearly, looking at the code, these 2 numbers should be equal!

However, on a sparc (gcc 2.95.3), the output is correct:
1669 1669
Comment 1 Andrew Pinski 2003-09-02 13:34:17 UTC
This is a non bug, read <http://gcc.gnu.org/bugs.html#nonbugs_general>
Also read bug 323 which is a dup of.

*** This bug has been marked as a duplicate of 323 ***
Comment 2 preciseflight 2003-09-03 05:30:29 UTC
Subject: Re:  Unexpected loss of floating point precision in assignment


Hello,

I'm confused:

> ------- Additional Comments From
pinskia@gcc.gnu.org:
> This is a non bug, read
> <http://gcc.gnu.org/bugs.html#nonbugs_general>
> 
I understand that floating point arithmetic is
inaccurate but I don't understand how _assigning_ a
floating point value to a variable before use could
be any different from the implicit assignment of the
value to a temporary variable (done by the compiler).

> *** This bug has been marked as a duplicate of 323
But this has nothing to do with optimization levels.
I'm compiling with optimization off.


http://search.yahoo.com.au - Yahoo! Search
- Looking for more? Try the new Yahoo! Search
Comment 3 Andrew Pinski 2003-09-03 05:37:06 UTC
assigning it to a temporary variable forces (by placing in memory by having no optimizations) a 
change in floating point precision and causes rounding to take place which causes more havoc 
than you think so this is still a dup of bug 323.