Main Content

Disable Support for Integer Overflow or Nonfinites

The code generator produces supporting code for these situations:

  • The result of an integer operation falls outside the range that a data type can represent, known as integer overflow.

  • An operation generates nonfinite values (inf and NaN).

If you know that these situations do not occur, to reduce the size of the generated code and increase its speed, you can suppress generation of the supporting code. However, if you suppress generation of the supporting code and one of these situations occurs, the behavior of the generated code might not match the behavior of the original MATLAB® code.

Disable Support for Integer Overflow

By default, the code generator produces code to handle integer overflow. Overflows saturate to either the minimum or maximum value that the data type can represent. If you know that your code does not depend on integer overflow support, to improve performance, you can disable the generation of the code that handles integer overflow. To disable integer overflow support:

  • In a code generation configuration object for MEX or standalone code (static library, dynamically linked library, or executable program), set the SaturateOnIntegerOverflow property to false.

  • In the MATLAB Coder™ app, set Saturate on integer overflow to No.

Note

Do not disable support for integer overflow unless you know that your code does not depend on it. If you disable the support and run-time checking is enabled, the generated code produces an error for integer overflow. If you disable integer overflow support and also disable run-time checking, the behavior for integer overflow is undefined. Most C compilers wrap on overflow.

To check whether your code depends on integer overflow support:

  1. Disable integer overflow support.

  2. Enable checks to detect integer overflow at run time.

  3. Run the generated code over the full range of input values. If the generated code detects integer overflow, it produces an error.

Disable Support for Nonfinite Numbers

By default, for standalone code (static library, dynamically linked library, or executable program), the code generator produces code to handle nonfinite numbers (inf and NaN). If you know that your code does not depend on nonfinite number support, to improve the performance of the generated code, you can disable the support. To disable nonfinite support:

  • In a code generation configuration object, set the SupportNonFinite property to false.

  • In the MATLAB Coder app, set Support nonfinite numbers to No.

If you disable nonfinite support, test that your generated code behaves as expected.

Related Topics