Logic and Bit Operations
hisl_0016: Usage of blocks that compute relational operators
| ID: Title | hisl_0016: Usage of blocks that compute relational operators | ||
|---|---|---|---|
| Description | To support the robustness of the operations, avoid using the equality and inequality operators on floating-point data types. | ||
| Notes | Due to floating-point precision issues, do not test floating-point expressions for equality (==) or inequality (~=, !=). | ||
| Rationale | Improve model robustness and prevent unexpected results. | ||
| Model Advisor Checks | Check relational comparisons on floating-point signals (Simulink Check) | ||
| References |
| ||
| See Also | Relational Operations | ||
| Last Changed | R2021b | ||
| Examples | Ex: 1 Example — Correct
Example — Incorrect
Ex: 2 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
| ||
hisl_0017: Usage of blocks that compute relational operators (2)
| ID: Title | hisl_0017: Usage of blocks that compute relational operators (2) | ||
|---|---|---|---|
| Description | To support unambiguous behavior in the generated code, when using blocks that compute relational operators, including Relational Operator, Compare To Constant, Compare to Zero, and Detect Change | ||
| A | Set block parameter Output
data type to Boolean. | ||
| B | For Relational Operator blocks, verify that input signals are of the same data type. | ||
| Rationale | A, B | Support generation of code that produces unambiguous behavior. | |
| Model Advisor Checks | Check usage of Relational Operator blocks (Simulink Check) | ||
| References |
| ||
| See Also | hisl_0016: Usage of blocks that compute relational operators | ||
| Last Changed | R2018a | ||
hisl_0018: Usage of Logical Operator block
| ID: Title | hisl_0018: Usage of Logical Operator block | ||
|---|---|---|---|
| Description | To support unambiguous behavior of generated code, when using the Logical Operator block, | ||
| A | Set block parameter
Output data type to
| ||
| B | Ensure input signals are of type
| ||
| Prerequisites | |||
| Rationale | A, B | Avoid ambiguous behavior of generated code. | |
| Model Advisor Checks | Check usage of Logical Operator blocks (Simulink Check) | ||
| References |
| ||
| Last Changed | R2017b | ||
hisl_0019: Usage of bitwise operations
| ID: Title | hisl_0019: Usage of bitwise operations | ||
|---|---|---|---|
| Description | To support unambiguous behaviour, when using bitwise operations, | ||
| A | Avoid bitwise operations on signed integer data types. | ||
| Notes | Bitwise operations are not meaningful on signed integers due to unpredictable behaviour. For example, a shift operation might move the sign bit into the number, or a numeric bit into the sign bit. | ||
| Rationale | A | Support unambiguous behavior of generated code. | |
| Model Advisor Checks | Check usage of bit operation blocks (Simulink Check) | ||
| References |
| ||
| See Also | hisl_0073: Usage of bit-shift operations | ||
| Last Changed | R2024a | ||



