Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are all 32 bit floats exactly represented as f64?

Can all IEEE 754 32 bit floating point numbers be represented exactly by a 64 bit floating point number? Stated another way, is a cast from f32 to f64 ever rounded?

like image 560
That 3 Percent Avatar asked Nov 21 '25 21:11

That 3 Percent


1 Answers

Can all IEEE 754 32 bit floating point numbers be represented exactly by a 64 bit floating point number?

Yes. All numeric values of binary32 are in binary64.

Stated another way, is a cast from f32 to f64 ever rounded?

Not usually. Various language like C allow intermediate 32-bit FP calculations to employ wider math and so a cast may narrow (round) results. Yet if the value was truly f32, no rounding error would occur going to f64.


Aside:
The Not-a-number payload of a binary32 is 23 bits and that is fully encodable as a binary64, yet the detailed meaning of those is implementation dependent.

like image 166
chux - Reinstate Monica Avatar answered Nov 24 '25 23:11

chux - Reinstate Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!