R seems to support an efficient NA value in floating point arrays. How does it represent it internally?
My (perhaps flawed) understanding is that modern CPUs can carry out floating point calculations in hardware, including efficient handling of Inf, -Inf and NaN values. How does NA fit into this, and how is it implemented without compromising performance?
With IEEE floats
+Infand-Infis represented with all bits in the exponent (second till 13. bit) set to one and all bits in the mantissa set to zero, whereas NaN has a non-zero mantissa. R uses different values for the mantissa to representNaNas well asNA_real_. We can use a simple C++ function to make this explicit:Here some source code references.