either single-precision lookup tables, or perhaps a radically different math lib. Annoying that something like that could affect a Perl program...
I'm very unsure of my ground here as I'm not familiar with the other platforms, but it might not be software--Perl or the libs--but the floating point hardware. If their FPU's are only single precision, that might account for the results.
That said, my best efforts to perform the calculation in single precision doesn't get close to the inaccuracies you;re seeing:
#include <stdio.h> float sqrtf( float n ) { float g = n / (float)2.0; while( ( ( g*g ) - n ) > 0.000001 ) { g = ( g + n/g ) / (float)2.0; } return g; } void main( void ) { float a = (float)0.01125, b = (float)-43.22, c = (float)41173.3950 +0009608; float two = 2.0, four = 4.0; float b2 = b * b; float ac4 = four * a * c; float sqrtbit = sqrtf( b2 - ac4 ); float a2 = two * a; float r1 = ( -b + sqrtbit ) / a2; float r2 = ( -b - sqrtbit ) / a2; printf( "b2:%f ac4:%f sqrt:%f a2:%f\n", b2, ac4, sqrtbit, a2 ); printf( "roots: %f , %f\n", r1, r2 ); }
Produces:
C:\test>quads b2:1867.968506 ac4:1852.802856 sqrt:3.894310 a2:0.022500 roots: 2093.969238 , 1747.808472
In reply to Re^3: Calculation discrepancy between Perl versions
by BrowserUk
in thread Calculation discrepancy between Perl versions
by oko1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |