Signed NaN Values

Based on the IEEE specification: "When either the input or the result is NaN, this standard does not interpret the sign of NaN." However, printf prints NaN values ​​as signed: NaN or -nan Can someone tell me the ruleset (from the specification?), When NaN and when -nan prints For example, I checked that printf(-1.0f) prints -nan Thanks you

+4
source share
1 answer

The base representation of NaN contains a signed bit, and this is what printf looks at when deciding whether it should print minus or not.

The reason the standard states that the sign bit should be ignored is to allow things like negation or absolute, just change the sign bit, without being forced to check if the input value was NaN.

+5
source

Source: https://habr.com/ru/post/1390401/


All Articles