google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.56k stars 3.19k forks source link

[C++] Comparing floats safely #8220

Closed fliiiix closed 5 months ago

fliiiix commented 5 months ago

This will allow the code to be compiled with -Wfloat-equal

vendor/flatbuffers/include/flatbuffers/base.h:465:69:
  error: comparing floating point with == or != is unsafe [-Werror,-Wfloat-equal]
template<typename T> inline bool IsTheSameAs(T e, T def) { return e == def; }

Im not 100% happy because it will still break when FLATBUFFERS_NAN_DEFAULTS is defined.

fliiiix commented 5 months ago

tbh after handling the inf cases i dislike this solution even more :sweat_smile: