tera
May 28, 2026, 4:46am
1
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
xwu
(Xiaodi Wu)
May 28, 2026, 5:00am
2
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).
opened 05:05AM - 28 May 26 UTC
triage needed
### Description
Given the value -NaN, its `description` is `"nan"` (was and con… tinues to be).
Printing the value itself used to yield `"nan"`, but now it yields `"-nan"` (since Swift 6.2, according to godbolt.org).
This is an unexpected change.
### Reproduction
```swift
let value: Double = -Double.nan
print(value)
// Prints "nan" in 6.1 and earlier
// Prints "-nan" in 6.2 and later
```
### Expected behavior
The output of `print(value)` should match the output of `print(value.description)`. That is, it should be "nan" and not "-nan".
### Environment
swift-driver version: 1.127.14.1 Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
Target: arm64-apple-macosx26.0
### Additional information
_No response_
1 Like