S
Scott
Is there a reliable low-overhead approach to testing the limits of
precision for float types on an arbitrary platform?
I'm converting an integer to a real number such that 0<=n<1, and then
converting the real back to an integer. I want to determine the
largest integer (bit-wise) that can be converted in this way and still
have foo(bar(x))==x always true.
Using gcc 2.95.3 on FreeBSD/i386 (also djgpp 2.8.0/DOS) I wrote a BFI
test program to experimentally determine that a float can represent
only 24 bits in this way - at 25 bits there are over 8 million fatal
rounding errors in the range 0-2^25.
One apparent clue is that the IEEE float type has a 23-bit mantissa,
and lets me store 24 bits. Would an IEEE double store 53 bits? But
then, not all platforms use IEEE floats, and don't even have to use a
standard floating-point format internally to store C floating point
types. C only guarantees a minimum range, right?
I don't have the CPU resources to test larger numbers with my naive
approach (my program would take almost 28 centuries to fully explore a
double on my machine). So, is there a more elegant way to find out?
Disclaimer: I know this issue could be considered OT, but I'm
specifically working to solve this in portable standard C.
Thanks,
-Scott
precision for float types on an arbitrary platform?
I'm converting an integer to a real number such that 0<=n<1, and then
converting the real back to an integer. I want to determine the
largest integer (bit-wise) that can be converted in this way and still
have foo(bar(x))==x always true.
Using gcc 2.95.3 on FreeBSD/i386 (also djgpp 2.8.0/DOS) I wrote a BFI
test program to experimentally determine that a float can represent
only 24 bits in this way - at 25 bits there are over 8 million fatal
rounding errors in the range 0-2^25.
One apparent clue is that the IEEE float type has a 23-bit mantissa,
and lets me store 24 bits. Would an IEEE double store 53 bits? But
then, not all platforms use IEEE floats, and don't even have to use a
standard floating-point format internally to store C floating point
types. C only guarantees a minimum range, right?
I don't have the CPU resources to test larger numbers with my naive
approach (my program would take almost 28 centuries to fully explore a
double on my machine). So, is there a more elegant way to find out?
Disclaimer: I know this issue could be considered OT, but I'm
specifically working to solve this in portable standard C.
Thanks,
-Scott