Contenuto principale

himl_0010: MATLAB code with logical operators and functions

R2026b

Use logical data types for logical operators and logical functions

Usage: High-Integrity System Modeling

Guideline ID: himl_0010

Rules

himl_0010: MATLAB® code with logical operators and functions

For logical operators and logical functions in MATLAB code, use logical data types

Rationale

  • Prevent unexpected results

Verification

Check usage of logical operators and functions in MATLAB Function blocks (Simulink Check)

Example — Correct

  • ~myLogical
    (myInt8 > int8(4)) && myLogical
    xor(myLogical1,myLogical2)
    

Example — Incorrect

  • ~myInt8
    myInt8 && myDouble
    

Tips

  • Logical operators: &&, ||, ~

  • Logical functions: and, or, not, xor

Industry Standards

  • IEC 61508-3, Table A.3 (2) 'Strongly typed programming language'
    IEC 61508-3, Table A.3 (3) 'Language subset'

  • 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 (8) 'Strongly Typed Programming Language'
    EN 50128, Table A.4 (11) 'Language Subset'

  • EN 50657, Table A.4 (8) 'Strongly Typed Programming Language'
    EN 50657, Table A.4 (11) 'Language Subset'

  • DO-331, Section MB.6.3.1.g 'Algorithms are accurate'
    DO-331, Section MB.6.3.2.g 'Algorithms are accurate'

Version History

Introduced in R2014a

expand all