Issue 177030
Summary Add `-Wfloat-equal-non-zero` warning/diagnostic
Labels new issue
Assignees
Reporter ZERICO2005
    I think it would be useful if `-Wfloat-equal` could be ignored when comparing to `0.0`.
* Comparing against `0.0` can be used to detect underflow
* Common `<math.h>` functions can return `0.0`, such as `log(1.0)`
* Under ieee arithmetic, `x - y == 0.0` if and only if `x == y` (although this only works if subnormal values are enabled).


My proposal is that `-Wfloat-equal` be split into two warnings:
* `-Wfloat-equal-non-zero` would ignore the case of `double_value == 0.0`.
* `-Wfloat-equal` would enable `-Wfloat-equal-non-zero` and otherwise behave the exact same as it does now.


Here are few cases that would need to be considered:
```c
double_value == 0.0 // comparing to zero
double_value == -0.0 // comparing to negative zero
double_value == 0 // comparing to a non-float zero
double_value = 1.0e-9999 // comparing to a value that rounds/underflows to zero
double_value = DBL_MIN - DBL_MIN // comparing to a value that is exactly zero
double_value = DBL_TRUE_MIN // comparing to a subnormal value
if (double_value) {} // implicit conversion to bool
```

`-Wfloat-equal` could also be split into more warnings, if it would also be useful to ignore the case of comparing to `+1.0` or `-1.0`.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to