hisl_0016: Usage of blocks that compute relational operators
R2026bAvoid using equality and inequality operators on floating-point data types
Usage: High-Integrity System Modeling
Guideline ID: hisl_0016
Rules
| hisl_0016: Usage of blocks that compute relational operators |
|---|
|
To support the robustness of the operations, avoid using the equality and inequality operators on floating-point data types. Rationale Improve model robustness and prevent unexpected results. Verification Check relational comparisons on floating-point signals (Simulink Check) Example — Correct
Example — Incorrect
Example — Correct Equality comparison operators are not used in floating-point operands.
Example — Incorrect Equality comparison operator == is used in floating-point operands.
Example — Correct To test whether two floating-point variables or expressions are equal, compare the difference of the two variables against a threshold that takes into account the floating-point relative accuracy (eps) and the magnitude of the numbers. The following pattern shows how to test two double-precision input signals, In1 and In2, for equality.
Example — Incorrect Equality comparison operator == is used in floating-point operands.
|
Tips
Due to floating-point precision issues, do not test floating-point expressions for equality (==) or inequality (~=, !=).
Industry Standards
IEC 61508-3, Table A.3 (2) 'Strongly typed programming language'
IEC 61508-3, Table A.3 (3) 'Language subset'
IEC 61508-3, Table A.4 (3) 'Defensive programming'
IEC 62304, 5.5.3 - Software Unit acceptance criteria
ISO 26262-6, Table 1 (1b) 'Use of language subsets'
ISO 26262-6, Table 1 (1c) 'Enforcement of strong typing'
EN 50128, Table A.4 (11) 'Language Subset'
EN 50128, Table A.4 (8) 'Strongly Typed Programming Language'
EN 50128, Table A.3 (1) 'Defensive Programming'
EN 50657, Table A.4 (11) 'Language Subset'
EN 50657, Table A.4 (8) 'Strongly Typed Programming Language'
EN 50657, Table A.3 (1) 'Defensive Programming'
EN 50716, Table A.3 (1) 'Defensive Programming'
DO-331, Section MB.6.3.1.g 'Algorithms are accurate'
DO-331, Section MB.6.3.2.g 'Algorithms are accurate'
MISRA C:2012, Dir 1.1
MISRA C:2023, Dir 1.1



