Curious NaN formatting inconsistency

Ran into some inconsistent behaviour around signed nan values, and not sure whether this is expected behaviour, a formatting inconsistency, or a bug:

let value: Double = -Double.nan

print(-0.0 / 0.0)                   //  nan
print(-(0.0 / 0.0))                 // -nan
print(value.description)            //  nan
print(value)                        // -nan
print(String(describing: value))    //  nan
print(value.debugDescription)       // -nan
ctest() // printf("%f\n", -NAN);    //  nan

Is this inconsistency unintended?


Edit:

Another one:

print(-0.0 * -.infinity) // -nan
print( 0.0 * -.infinity) // -nan
// yet
print(-Double.infinity / .infinity) // nan

There's not one "this" here.
It is intended that the result of negation is distinct from the result of division by zero.
It is intended that debug description shows the sign of NaN and description does not.
It is a bug that arose in 6.2, not 6.1, that print(value) differs from print(value.description).

1 Like