commit 190212ab3579321481115e04bb40758ae2c5ab5d from: Sergey Bronnikov date: Wed Aug 07 10:47:51 2024 UTC rules/python: fix cmp_float_number commit - dfc5337dcdee440d56c2c53264f56fe29b02d8f5 commit + 190212ab3579321481115e04bb40758ae2c5ab5d blob - bf09f1c67359f86dbee6e30cb8f9394ca4d96c7b blob + d826f58cb794884874c554c6bb6a28f47f555fc3 --- rules/python/flakiness/cmp_float_number.py +++ rules/python/flakiness/cmp_float_number.py @@ -2,13 +2,31 @@ m = 5 n = 0.000001 # rule-id: cmp_float_numbers -assert(1.0000 == 1.000000) +assert(n == 1.000000) # rule-id: cmp_float_numbers -assert(1.0000 == m) +assert(6.0001 == m) # rule-id: cmp_float_numbers -assert(m == 1.0000) +assert(m == n) # rule-id: cmp_float_numbers -assert(m == n) +assert(3. == n) +# rule-id: cmp_float_numbers +assert(3.3 == n) +# rule-id: cmp_float_numbers +assert(3.3e2 == n) +# rule-id: cmp_float_numbers +assert(3.3e-1 == n) +# rule-id: cmp_float_numbers +assert(.1e1 == n) +# rule-id: cmp_float_numbers +assert(1.11e12 == n) +# rule-id: cmp_float_numbers +assert(1.3e-1 == n) +# rule-id: cmp_float_numbers +assert(.1e1 == n) +# rule-id: cmp_float_numbers +assert(.2e-14 == n) +# rule-id: cmp_float_numbers +assert(5E6 == n) blob - 1d75f60c8704f3d6235342a897fcccc0f0e64041 blob + d0896fa39812530da4edb918e888f2ef9d8c7620 --- rules/python/flakiness/cmp_float_number.yaml +++ rules/python/flakiness/cmp_float_number.yaml @@ -1,18 +1,21 @@ -# TODO: floating point additions are not associative. (X + Y) + Z is not the same as X + (Y + Z). -# https://en.wikipedia.org/wiki/Associative_property#Nonassociativity_of_floating_point_calculation - rules: -- id: cmp_float_numbers - patterns: - - pattern-either: - - pattern: | - 1.0000 == 1.0000 - message: | - PEP-485, using math.isclose and cmath.isclose functions is recommended - languages: - - python - metadata: - references: - - https://en.wikipedia.org/wiki/IEEE_754 - - https://www.nccs.nasa.gov/images/FloatingPoint_consistency.pdf - severity: WARNING + - id: cmp_float_numbers + patterns: + - pattern-either: + - pattern-inside: ... <> ... + - pattern-inside: ... > ... + - pattern-inside: ... < ... + - pattern-inside: ... >= ... + - pattern-inside: ... <= ... + - pattern-inside: ... == ... + - pattern-regex: ([1-9][0-9]*[eE][1-9][0-9]*|(([1-9][0-9]*\.)|(\.[0-9]+))([0-9]*)?([eE][\-\+]?[1-9][0-9]*)?) + message: | + PEP-485, using math.isclose() and cmath.isclose() functions is + recommended. + languages: + - python + metadata: + references: + - https://en.wikipedia.org/wiki/IEEE_754 + - https://www.nccs.nasa.gov/images/FloatingPoint_consistency.pdf + severity: WARNING