> I was surprised by this, so I wrote a program to test. Indeed, 180 / 
> (float)M_PI is
> less precise:
> 
> (float)(180 / M_PI) = 57.29577636718750000 (0x1.ca5dc0p+5) (0x42652ee0)
> (180 / (float)M_PI) = 57.29577636718750000 (0x1.ca5dc0p+5) (0x42652ee0)
> 57.295779513082321F = 57.29578018188476562 (0x1.ca5dc2p+5) (0x42652ee1)

It seems the precision loss was because pi has ultimate precision bits.
As division is not correctly rounded, but multiply is correctly rounded.
So I tried 180 * M_1_PI_F, (M_1_PI_F stands for 1.0/pi) the value is still 
(0x1.ca5dc0p+5) (0x42652ee0)
The correct value of 180/m_pi is 0x1.ca5dc1a63p+5.
When it is represented using single floating point, the guard bits are '110'  
(comes from 1a).
Using round to even rule, should be round-up. Then we got 0x1.ca5dc2p+5
The patch is good!
> 
> A difference of one bit. :)
> _______________________________________________
> Beignet mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/beignet
_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to