Different sin values ​​for different processors

I am programming an application to calculate some geometric transformations, and while I was testing the program, I based something strange: I ran the test on two different machines, a Z400 workstation with an Intel® Xeon® workstation W3550 and a Z800 with an Intel® Xeon® processor X5560 , and I got different results for one operation:

double x = 24.169408798217777 * sin(0.59420877837561048) / sin(0.97658754841928608) 

With Z400, I got x=16.330508228047432

While Z800 throws this value x=16.330508228047435

The value is different from the last digit, and I do a lot of calculations with this value, so this leads to inconvenience.

I tried to use sinl in order to get additional refueling, but I got the same value for each workstation. What is wrong with it? How can i fix this?

+4
source share
2 answers

The results of the two calculations differ by 1 decimal digit, as you noted, and 1 binary digit, as shown below. Z400 closer matches the correct answer. sin() calculation does not have to be exact with the last binary bit, but accurate to 1 bit. A good implementation of sin() true to the last bit **. Your Z800 is not so good.

 printf("%a\n", 16.330508228047432); printf("%a\n", 16.330508228047435); printf("%a\n", 24.169408798217777 * sin(0.59420877837561048) / sin(0.97658754841928608)); // my PC eclipse 

0x1.0549c2fee85cbp + 4
0x1.0549c2fee85ccp + 4
0x1.0549c2fee85cbp + 4

** Accuracy requirements are not C ++ requirements, nor are IEEE floating point requirements. Trigger s / b functions accurate to 1 ulp (last place). Good trigger libraries are accurate within 0.5 ulp (last place in last place) - the best answer.

+2
source

As suggested, I am going to assume that this is due to some processors that calculate floating point values ​​in 80-bit registers (instead of 64-bit) and only reduce accuracy as late as possible.

In GCC, you can disable this (which will cause all your math to be executed in 64 bits, and also potentially lead to its slow) with -ffloat-store .

There are some additional suggestions for this answer that may also help if 80-bit register is a real problem.

+1
source

Source: https://habr.com/ru/post/1495327/


All Articles