Does casting to or from a double and a float preserve infinity and NaN?

23

When casting double infinity to float and vice versa, will it still be infinity? Is it the same with NaN?

Share
Improve this question
2
  • 2
    related/dupe: stackoverflow.com/questions/14773142/… – NathanOliver Apr 6 at 13:05
  • 6
    @NathanOliver: Strictly speaking that covers only half the cases asked here. In IEEE754, there are many more 64-bit NaN's than there are 32 bit NaN's, so it matters if you start with 32 or 64 bits. The linked question assumes you start with 32 bits; this question also considers the case where you start with one of the 64 bit NaN's. And since there are more than 4 billion 64-bit NaN's, the pigeonhole principle tells us that you cannot preserve the NaN payload (the exact binary NaN representation) – MSalters Apr 6 at 19:13

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

React Native - Image Cache