Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signed NaN values

Tags:

c

printf

nan

Based on "IEEE" spec : "When either an input or result is NaN, this standard does not interpret the sign of a NaN." However the printf prints NaN values as signed:nan or -nan Can someone point me the set of rules(from spec?) when nan and when -nan is printed For example , I checked that printf(-1.0f) prints -nan Thank you

like image 774
Yakov Avatar asked Jan 11 '12 09:01

Yakov


1 Answers

The underlying representation of a NaN contains a sign bit, and this is what printf looks at when deciding if it should print the minus or not.

The reason why the standard says that the sign bit should be ignored is to allow things like negate or absolute to simply modify the sign bit, without being forced to check if the input value was NaN.

like image 168
Lindydancer Avatar answered Oct 04 '22 08:10

Lindydancer