Main Content

Single-Precision Design for MATLAB Code

Convert double-precision MATLAB® code to single-precision MATLAB code

Because single precision numbers use only 32 bits, they require less memory than double-precision numbers while still offering many of the benefits of floating point arithmetic. You can convert your double-precision MATLAB code to single-precision using the convertToSingle function at the command line. You can verify the behavior of a single-precision version of your code without modifying the original algorithm.

To use verification options, create a coder.SingleConfig object that you pass to convertToSingle. You can:

  • Test numerics by running the test file with the single precision types applied.

  • Compare double precision and single precision test results using the Simulation Data Inspector or your own plotting functions.

If you have a MATLAB Coder™ license, you can:

  • Generate single-precision C code using the MATLAB Coder app. Use this workflow if your goal is to generate single-precision C code in the most direct way and you do not want to see the intermediate single-precision MATLAB code.

  • Generate single-precision C code using codegen with the -singleC option. Use this workflow when you want to generate single-precision C code in the most direct way and you do not want to see the intermediate single-precision MATLAB code.

  • Generate single-precision MATLAB code using codegen with a coder.SingleConfig object. Use this workflow if you want to see the single-precision MATLAB code or use verification options.

  • Generate single-precision C code using codegen with a coder.SingleConfig object and a code configuration object. Use this workflow to generate single-precision C code when you also want to see the single-precision MATLAB code or use verification options.

Functions

convertToSingleConvert double-precision MATLAB code to single-precision MATLAB code
coder.configCreate configuration object for fixed-point or single-precision conversion

Classes

coder.SingleConfigDouble-precision to single-precision conversion configuration object

Topics