Forbidden real comparisons#
Forbidden real comparisons
Description#
Comparisons of real values are not allowed: = (20, 21, 22, 23, 24, 25)
The parameter defines the list of comparison operators to consider,
using their code, with the following syntax: <code> [, <code>]*
(default value: 20, 21, 22, 23, 24, 25
).
The codes are defined in the user documentation:
######## ==== Operator Code ######## ==== < 20 <= 21 > 22 >= 23 = 24 <> 25 ######## ====
Rationale#
Real numbers shall not be compared but with appropriate justified tolerance.
Verification#
The rule registers to the operator calls, and raises a violation for each call which satisfies all these conditions:
The called operator is one of those listed in the rule’s parameter.
One of the operands is float, for example
float32
orfloat64
.
Message: Real comparison in <expression>
Note
A polymorphic type shall be constrained as real
to be considered as float
,
even if the operator has instantiations with float parameters.
Resolution#
Use a comparison operator with tolerance.
Customization#
N/A.