Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Two impleme...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 10 Topic 45893 of 47035
Post > Topic >>

Re: Two implementations of simple math equation yield different

by Greg Herlihy <greghe@[EMAIL PROTECTED] > May 13, 2008 at 03:15 AM

On May 13, 2:42=A0am, James Kanze <james.ka...@[EMAIL PROTECTED]
> wrote:
> On May 13, 7:16 am, Avi <avner-moshkov...@[EMAIL PROTECTED]
> wrote:
> > double f2 =3D e1 + e2;
> > The difference is calculated as follows:
> > double diff =3D f2-f1;
> > I expect the difference to be exactly 0 but instead, I get a
> > tiny value. =A0Could someone explain the reason for differences
> > in the result?
>
> It's very implementation dependent.
>
> > I'm compiling with gcc
>
> More to the point, you're compiling on a machine which uses
> extended precision in its floating point unit, and its floating
> point registers. =A0(An Intel, perhaps.)
>
> The reason for this freedom is speed. =A0Forcing the results of
> each operation to be rounded to double can be done, but would
> slow things down considerably (at least on Intel). =A0And for the
> most part, increased precision is not considered a defect.

But the extended floating point precision is a defect if - as in this
case - consistent numeric results are required. Fortunately, all Intel
x86 chips since the Pentium 3 sup****t double precision (64-bit)
floating point in their SSE units. So, the solution would be to have
the compiler generate SSE floating point instructions ("-msse2 -
mfpmath=3Dsse") instead of 387 instructions. According to the gcc
do***entation, this strategy has other benefits as well:

"The resulting code should be considerably faster in the majority of
cases and avoid the numerical instability problems of 387 code, but
may break some existing code that expects tem****aries to be 80-bit."

Greg
 




 10 Posts in Topic:
Two implementations of simple math equation yield different resu
Avi <avner-moshkovitz@  2008-05-12 22:16:30 
Re: Two implementations of simple math equation yield different
Paavo Helde <nobody@[E  2008-05-13 00:34:44 
Re: Two implementations of simple math equation yield different
"Alf P. Steinbach&qu  2008-05-13 07:37:47 
Re: Two implementations of simple math equation yield different
James Kanze <james.kan  2008-05-13 02:42:18 
Re: Two implementations of simple math equation yield different
Greg Herlihy <greghe@[  2008-05-13 03:15:20 
Re: Two implementations of simple math equation yield different
Avi <avner-moshkovitz@  2008-05-13 10:00:55 
Re: Two implementations of simple math equation yield different
Avi <avner-moshkovitz@  2008-05-13 10:02:01 
Re: Two implementations of simple math equation yield different
Victor Bazarov <v.Abaz  2008-05-13 13:25:30 
Re: Two implementations of simple math equation yield different
Avi <avner-moshkovitz@  2008-05-13 10:52:29 
Re: Two implementations of simple math equation yield different
James Kanze <james.kan  2008-05-14 01:04:47 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:42:30 CDT 2008.