public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/33809]  New: Rounding off error in GCC 4.1.2
@ 2007-10-18 10:30 satyaakam at yahoo dot co dot in
  2007-10-18 12:18 ` [Bug c/33809] " ubizjak at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: satyaakam at yahoo dot co dot in @ 2007-10-18 10:30 UTC (permalink / raw)
  To: gcc-bugs

Based on our investigation and the gcc documentation , we think there is a Bug
in GCC 4.1.2

Firstly, according to the doc and our understanding, the error caused by
rounding should be small, for instance, some systems may treat 5.000 as 4.998.
However, in our case, the difference is quit big, about 40% by compare
-0.7240616609 to -0.5413411329464. I think it can't be ignored.

Secondly, -frounding-math and -fno-rounding-math are two gcc options to control
rounding. However, using -O0, for both two options, We got the same value,
-0.7240616609. But using -O3 (or -O1), We got the same value, -0.5413411329464.
This means changing rounding option doesn't affect the result.

Thirdly, in the case, function double ahdlDoFloatDiv(double a, double) is to
return the result of a/b. If I directly use a/b, instead of function, for -O3,
the result is -0.7240616609, the same as -O0. If the issue is caused by
rounding, both two ways should have the same result. But now it is different.

Finally, we simplified the c code as below and can reproduce the problem:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

double ahdlDoFloatDiv (double a, double b)
{
   return a/b;
}

// #define ahdlDoFloatDiv(a, b)  (a/b)

int main()
{
   double pow_tmp = 0;
   printf("%f\n",
           ahdlDoFloatDiv((((((((((2.7182818284590451)) +
(((ahdlDoFloatDiv((((-(((2.7182818284590451)) *
((((((1.00000000000000000000e+00))) * 1.00000000000000000000e+00))))))), ((((
pow_tmp = (2.7182818284590451)) * pow_tmp)))))))))) * (((((2.7182818284590451))
- (((ahdlDoFloatDiv(1.00000000000000000000e+00, (2.7182818284590451)))))))))))
- ((((((((2.7182818284590451)) - (((ahdlDoFloatDiv((((-(((2.7182818284590451))
* ((((((1.00000000000000000000e+00))) * 1.00000000000000000000e+00))))))), ((((
pow_tmp = (2.7182818284590451)) * pow_tmp)))))))))) * (((((2.7182818284590451))
+ (((ahdlDoFloatDiv(1.00000000000000000000e+00,
(2.7182818284590451)))))))))))), (((( pow_tmp = ((((2.7182818284590451)) -
(((ahdlDoFloatDiv(1.00000000000000000000e+00, (2.7182818284590451)))))))) *
pow_tmp))))
           );
   return 0;
}

Please use gcc4.1.2 to compile it under Linux and you can reproduce the bug.
For -O3, the printed value is -0.541341, for -O0, it is -0.724062. If comment
the function ahdlDoFloatDiv  and uncomment the macro definition, both -O0 and
-O3 have the same result,  -0.724062.

This issue causes our problem to producing incorrect values, even lead to
convergence issue.


-- 
           Summary: Rounding off error in GCC 4.1.2
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: satyaakam at yahoo dot co dot in


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33809


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/33809] Rounding off error in GCC 4.1.2
  2007-10-18 10:30 [Bug c/33809] New: Rounding off error in GCC 4.1.2 satyaakam at yahoo dot co dot in
@ 2007-10-18 12:18 ` ubizjak at gmail dot com
  2007-10-18 14:00 ` satyaakam at yahoo dot co dot in
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ubizjak at gmail dot com @ 2007-10-18 12:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ubizjak at gmail dot com  2007-10-18 12:18 -------
What about -ffloat-store?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33809


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/33809] Rounding off error in GCC 4.1.2
  2007-10-18 10:30 [Bug c/33809] New: Rounding off error in GCC 4.1.2 satyaakam at yahoo dot co dot in
  2007-10-18 12:18 ` [Bug c/33809] " ubizjak at gmail dot com
@ 2007-10-18 14:00 ` satyaakam at yahoo dot co dot in
  2007-10-18 14:46 ` rguenth at gcc dot gnu dot org
  2007-10-18 16:27 ` manu at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: satyaakam at yahoo dot co dot in @ 2007-10-18 14:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from satyaakam at yahoo dot co dot in  2007-10-18 14:00 -------
$gcc -ffloat-store round.c
$ ./a.out
-0.724062

$gcc -O3 -ffloat-store round.c
$ ./a.out
-0.541341

$gcc -O0 -ffloat-store round.c
./a.out
-0.724062


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33809


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/33809] Rounding off error in GCC 4.1.2
  2007-10-18 10:30 [Bug c/33809] New: Rounding off error in GCC 4.1.2 satyaakam at yahoo dot co dot in
  2007-10-18 12:18 ` [Bug c/33809] " ubizjak at gmail dot com
  2007-10-18 14:00 ` satyaakam at yahoo dot co dot in
@ 2007-10-18 14:46 ` rguenth at gcc dot gnu dot org
  2007-10-18 16:27 ` manu at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-10-18 14:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2007-10-18 14:46 -------
Your code is undefined.  You have multiple assignments to pow_tmp without
intervening sequence points.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33809


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/33809] Rounding off error in GCC 4.1.2
  2007-10-18 10:30 [Bug c/33809] New: Rounding off error in GCC 4.1.2 satyaakam at yahoo dot co dot in
                   ` (2 preceding siblings ...)
  2007-10-18 14:46 ` rguenth at gcc dot gnu dot org
@ 2007-10-18 16:27 ` manu at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-10-18 16:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2007-10-18 16:27 -------
(In reply to comment #3)
> Your code is undefined.  You have multiple assignments to pow_tmp without
> intervening sequence points.
> 

Do you think it could be interesting to collect these kind of reports as
potential testcases for an improved Wsequence-point (PR16202)?

The only thing to be done is (apart from closing it as invalid) add it as
blocking  bug 16202.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33809


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-10-18 16:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-18 10:30 [Bug c/33809] New: Rounding off error in GCC 4.1.2 satyaakam at yahoo dot co dot in
2007-10-18 12:18 ` [Bug c/33809] " ubizjak at gmail dot com
2007-10-18 14:00 ` satyaakam at yahoo dot co dot in
2007-10-18 14:46 ` rguenth at gcc dot gnu dot org
2007-10-18 16:27 ` manu at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).