Can I use rounding to ensure the determinism of floating point operations?

I am developing a C application that requires floating point determinism. I would also like floating point operations to be fast enough. This includes standard transcendental functions not specified by the IEEE754 as sine and logarithm. The floating point software implementations I reviewed are relatively slow compared to the hardware floating point, so I am considering the possibility of simply rounding up one or two least significant bits from each answer. Losing accuracy is an adequate compromise for my application, but is it enough to provide deterministic results across platforms? All floating point values ​​will double.

I understand that the order of operations is another potential source for variance of floating point results. I have a way to address this already.

It would be great if today we used software implementations of the main hardware implementations with floating point, so I could directly test this hypothesis.

+5
source share
1 answer

As I understand it, you have a software implementation of a transcendental function, such as sin (x), expressed in terms of standard IEEE operations, such as adding and multiplying with a floating point, and you want to make sure that you get the same answer to all machines ( or at least all the cars you care about).

-, : . . IBM IEEE . , IEEEE, FP.

, , , IEEE. , NaNs, NaNs IEEE 754-1985, : HP MIPS, vedrsus . 1

, ?

(1) . , . ( , .) FP. , , , parallelism, FP .

(2) , .

. 32 64 ( C 64- "", Intel x86/x87 80 64 32 . 1 , x86/x87 80 64 , . , , , 32 64 , 80 x87.

(, x86 SSE FP, Intel x87 FP (, () 64 , 80 , , , , , ))

. , underflow . , " ". : , , . . IEEE FORMATS, IEEE ( ). druther IEEE denorms, , .

(3) , ioptions. Older C "" (64-), . , .

(4) :

, ( FP-)

,

double a = ...;
double b = ...;
double c = a *b;
double d = ...;
double e = a*d;
double f = c + e;

f = (a*b) + (a*c);

f = a*(b+c);

, .

, . IEEE - ​​ . IEEE FP, .

. , . : ....

(2) , - . , , FP.

, , sin.

, .

, . . gcc:

-ffp-contract = off --- disable fused multiply add, .

-fexcess precision = standard --- Intel x86/x87

-std = c99 --- C. , , google

, , -funsafe-math -fassociativbe-math

+2

All Articles