public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* double error
@ 2003-01-31 18:44 Bob Hou
  2003-01-31 19:01 ` Bob Hou
  2003-01-31 19:07 ` Andreas Conz
  0 siblings, 2 replies; 4+ messages in thread
From: Bob Hou @ 2003-01-31 18:44 UTC (permalink / raw)
  To: gcc, gcc, yhou

Hi,
I have the following simple code and expect the results are all the
same.
However the output is following: (The code is compiled with gcc under
Redhat8.0. )

The result is : 0
The result is : 0
The result is : -2.22045e-15

The code is also tested on MS VS6.0
and it give the same answers (zero).

Could you tell me whether it's a bug or I did sth wrong?
Thanks,

/*--------------- test.c---------------------------*/
#include<stdio.h>

int main()
{
  double fi = 0.7509;
  double fj = 100.0;
  double fk, fk1, fk2 ;
   fk = fj*fi - fj*fi;
   fk1 = 0.7509*100.0 - 0.7509*100.0;
   fk2 = fj*fi - 0.7509*100.0;
   printf("The result is : %g\n", fk);
   printf("The result is : %g\n", fk1);
   printf("The result is : %g\n", fk2);

   return 0;
}
/*-----------------end-----------------------------*/

--
__________________________________________________________
Dr. Bob (Yuqian) Hou
Certre for Vision Research
Rm0002B, CSB
York University
4700 Keele Street
North York, Ontario
Canada M3J 1P3

Tel: (416) 736-2100 ext. 66117
Fax: (416) 736-5814


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

* double error
  2003-01-31 18:44 double error Bob Hou
@ 2003-01-31 19:01 ` Bob Hou
  2003-01-31 19:07 ` Andreas Conz
  1 sibling, 0 replies; 4+ messages in thread
From: Bob Hou @ 2003-01-31 19:01 UTC (permalink / raw)
  To: gcc, gcc, yhou

Hi,
I have the following simple code and expect the results are all the
same.
However the output is following: (The code is compiled with gcc under
Redhat8.0. )

The result is : 0
The result is : 0
The result is : -2.22045e-15

The code is also tested on MS VS6.0
and it give the same answers (zero).

Could you tell me whether it's a bug or I did sth wrong?
Thanks,

/*--------------- test.c---------------------------*/
#include<stdio.h>

int main()
{
  double fi = 0.7509;
  double fj = 100.0;
  double fk, fk1, fk2 ;
   fk = fj*fi - fj*fi;
   fk1 = 0.7509*100.0 - 0.7509*100.0;
   fk2 = fj*fi - 0.7509*100.0;
   printf("The result is : %g\n", fk);
   printf("The result is : %g\n", fk1);
   printf("The result is : %g\n", fk2);

   return 0;
}
/*-----------------end-----------------------------*/

--
__________________________________________________________
Dr. Bob (Yuqian) Hou
Certre for Vision Research
Rm0002B, CSB
York University
4700 Keele Street
North York, Ontario
Canada M3J 1P3

Tel: (416) 736-2100 ext. 66117
Fax: (416) 736-5814


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

* Re: double error
  2003-01-31 18:44 double error Bob Hou
  2003-01-31 19:01 ` Bob Hou
@ 2003-01-31 19:07 ` Andreas Conz
  2003-01-31 19:12   ` Andreas Conz
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Conz @ 2003-01-31 19:07 UTC (permalink / raw)
  To: Bob Hou; +Cc: gcc, gcc

On Fri, 31 Jan 2003, Bob Hou wrote:

Hi Bob,

you have hit a typical floatingpoint user error.
This are doubles, not real numbers!

for doubles a,b,c:
it could be that a+b+c != c+b+a

Take a look at the following link from the "GCC Further Reading: page:
http://www.validlab.com/goldberg/paper.pdf

> Hi,
> I have the following simple code and expect the results are all the
> same.
> However the output is following: (The code is compiled with gcc under
> Redhat8.0. )
>
> The result is : 0
> The result is : 0
> The result is : -2.22045e-15

This is the same.

> The code is also tested on MS VS6.0
> and it give the same answers (zero).

You could get different results at different optimisation levels at
different compilers.

> Could you tell me whether it's a bug or I did sth wrong?
> Thanks,


mit freundliche Gruessen / kind regards
Andreas Conz

WWW    http://www.neuro.informatik.uni-kassel.de/~andreasc
e-mail andreasc@neuro.informatik.uni-kassel.de



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

* Re: double error
  2003-01-31 19:07 ` Andreas Conz
@ 2003-01-31 19:12   ` Andreas Conz
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Conz @ 2003-01-31 19:12 UTC (permalink / raw)
  To: Bob Hou; +Cc: gcc, gcc

On Fri, 31 Jan 2003, Bob Hou wrote:

Hi Bob,

you have hit a typical floatingpoint user error.
This are doubles, not real numbers!

for doubles a,b,c:
it could be that a+b+c != c+b+a

Take a look at the following link from the "GCC Further Reading: page:
http://www.validlab.com/goldberg/paper.pdf

> Hi,
> I have the following simple code and expect the results are all the
> same.
> However the output is following: (The code is compiled with gcc under
> Redhat8.0. )
>
> The result is : 0
> The result is : 0
> The result is : -2.22045e-15

This is the same.

> The code is also tested on MS VS6.0
> and it give the same answers (zero).

You could get different results at different optimisation levels at
different compilers.

> Could you tell me whether it's a bug or I did sth wrong?
> Thanks,


mit freundliche Gruessen / kind regards
Andreas Conz

WWW    http://www.neuro.informatik.uni-kassel.de/~andreasc
e-mail andreasc@neuro.informatik.uni-kassel.de



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

end of thread, other threads:[~2003-01-31 18:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-31 18:44 double error Bob Hou
2003-01-31 19:01 ` Bob Hou
2003-01-31 19:07 ` Andreas Conz
2003-01-31 19:12   ` Andreas Conz

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).