How can I list all possible values of a floating-point data type? I can do this using a union in C or C++ but will that be portable?
How can this be done in other languages? Javascript?
Let's just assume I am using this iteration to map theta
to sin(theta)
.
Take a look at the man pages for nextafter() and nextafterf(). They let you advance from a floating point number to the next closest one. You could use one of these to visit each FP number in order.
How can I list all possible values of a floating-point data type?
By bit-twiddling the IEEE-754 representation of your float value, for a float you need 2^32 different representations assuming 4 Bytes per float would require 16GB of memory.
I assume you need a lookup table for the sine function, simply loop from 0 to 2*PI in steps of your required precision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With