Skip to content

Comparison of NaN differs between json and float #3409

Closed
@misos1

Description

@misos1

Description

https://json.nlohmann.me/api/basic_json/operator_le/

Compares whether one JSON value lhs is less than or equal to another JSON value rhs by calculating #cpp !(rhs < lhs).

This means that <= always has the opposite result to > even for NaN. Which gives weird results like json(NAN) <= json(NAN) is true but json(NAN) < json(NAN) is false while json(NAN) == json(NAN) is also false #514.

Reproduction steps

printf("%i %i\n", json(NAN) <= json(NAN), NAN <= NAN);
printf("%i %i\n", json(NAN) < json(NAN), NAN < NAN);

Expected vs. actual results

Actual:

1 0
0 0

Expected:

0 0
0 0

Minimal code example

No response

Error messages

No response

Compiler and operating system

clang

Library version

3.7.0

Validation

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions