Commit 587fb69
authored
fix: order -NaN below +NaN in Literal comparison (#861)
## What
`Literal::operator<=>` orders a negative NaN as greater than a positive
NaN, the opposite of the total ordering documented and tested in this
file. `CompareFloat` returns `lhs_is_negative <=> rhs_is_negative` for
the both-NaN case, so `-NaN <=> +NaN` is `true <=> false` = `greater`.
The adjacent comment says "-NAN < NAN", and
`FloatSpecialValuesComparison` / `DoubleSpecialValuesComparison` assert
`-NaN < -Infinity < ... < +Infinity < +NaN`, both of which this branch
contradicts.
Fixes #860.
## How
Swap the operands so a negative sign bit sorts below a positive one:
```cpp
return rhs_is_negative <=> lhs_is_negative;
```
## Testing
The existing `FloatNaNComparison` / `DoubleNaNComparison` tests only
cover same-sign NaN pairs (qNaN vs sNaN, which are equivalent), so the
mixed-sign case was unexercised. Added `FloatSignedNaNComparison` and
`DoubleSignedNaNComparison` asserting `-NaN < +NaN` and the reverse.
Verified fail-without (the new tests report `greater`/`less` swapped) /
pass-with. Full `expression_test` passes (495 tests).1 parent 75b7d24 commit 587fb69
2 files changed
Lines changed: 32 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
434 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
435 | 437 | | |
436 | 438 | | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
| 439 | + | |
448 | 440 | | |
449 | 441 | | |
450 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
209 | 210 | | |
210 | 211 | | |
211 | 212 | | |
212 | | - | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
217 | 228 | | |
218 | 229 | | |
219 | 230 | | |
| |||
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
263 | | - | |
264 | 274 | | |
265 | | - | |
| 275 | + | |
266 | 276 | | |
267 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
268 | 289 | | |
269 | 290 | | |
270 | 291 | | |
| |||
0 commit comments