hisl_0004: Usage of natural logarithm and base 10 logarithm operations
R2026bProtect against invalid inputs to logarithm operations
Usage: High-Integrity System Modeling
Guideline ID: hisl_0004
Rules
| hisl_0004: Usage of natural logarithm and base 10 logarithm operations | |
|---|---|
| A | Protect the input from going negative. Rationale Support generation of robust code. Verification Check usage of log and log10 operations (Simulink Check) Example — Incorrect Logarithm operation with negative real input produces NaN output.
Example — Correct Abs block protects the logarithm input from going negative. The following plot displays the resulting output for input values ranging from -100 to 100.
|
| B | Protect the input from equaling zero. Rationale Support generation of robust code. Verification Check usage of log and log10 operations (Simulink Check) Example — Incorrect Logarithm operation with zero input produces -inf output.
Example — Correct MinMax block with a Constant block set to eps protects the logarithm input from equaling zero. The following plot displays the resulting output for input values ranging from -100 to 100.
|
| C | Account for complex numbers as the output value. Rationale Support generation of robust code. Verification Check usage of log and log10 operations (Simulink Check) Example — Correct Setting Output Data to Complex on the logarithm block produces valid complex output for negative inputs instead of NaN.
|
Tips
If you set the output data type to complex, the natural logarithm and base 10 logarithm functions output complex values for negative input values. If you set the output data type to real, the functions output
NANfor negative numbers, and minus infinity (-inf) for zero values.
Industry Standards
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(1d) 'Use of defensive implementation techniques'EN 50128, Table A.4 (11) 'Language Subset'
EN 50128, Table A.3 (1) 'Defensive Programming'EN 50657, Table A.4 (11) 'Language Subset'
EN 50657, Table A.3 (1) 'Defensive Programming'EN 50716, Table A.3 (1) 'Defensive Programming'
DO-331, Section MB.6.3.2.g 'Algorithms are accurate'
MISRA C:2012, Dir 4.1
MISRA C:2023, Dir 4.1
INT33-C. Ensure that division and remainder operations do not result in divide-by-zero errors






