Skip to content

Comparison floating points causes warning #2909

Closed
@Finkman

Description

@Finkman

Treating warnings as errors causes Werror=float-equal on gcc 9.3 on NDEBUG

What is the issue you have?

I use JSON as an in-source library and compile the project with Werror and gcc 9.3.
json.hpp:14830:84 is then pointed out to be "unsafe".
The intention of that line is clear to me, but it should be considered to find a warning-free solution.

Please describe the steps to reproduce the issue.

Can you provide a small but working code example?

What is the expected behavior?

And what is the actual behavior instead?

Which compiler and operating system are you using?

  • Compiler: gcc 9.3.0
  • Operating system: Ubuntu 20.04

Which version of the library did you use?

  • latest release version 3.9.1
  • other release - please state the version: ___
  • the develop branch commit: eb488bb

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below
[build] /home/fins/development/tqswip/tqs-wip-printer/libs/json/single_include/nlohmann/json.hpp:14830:84: error: comparing floating point with == or != is unsafe [-Werror=float-equal]
[build] 14830 |                 static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
[build]       |       

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions