Esc

float_equality

Finds == or != between two computed floats.

Category pedantic, allow by default.

Off by default; the example is shown with the rule enabled.

Example
#import "Basic";

same_total :: (a: float, b: float, expected: float) -> bool {
    return a + b == expected;
}

main :: () {
    print("%\n", same_total(0.1, 0.2, 0.3));
}
Diagnostic
warning[float_equality]: comparing floats for exact equality
  --> example.jai:4:12
   |
 4 |     return a + b == expected;
   |            ^^^^^^^^^^^^^^^^^
   |
   = help: compare the difference with a tolerance: `abs(a - b) < epsilon`
Fixed
#import "Basic";
#import "Math";

same_total :: (a: float, b: float, expected: float) -> bool {
    return abs(a + b - expected) < 0.000001;
}

main :: () {
    print("%\n", same_total(0.1, 0.2, 0.3));
}

Off by default: exact comparison is often deliberate.