MATLAB: Compiler generated code for TI C2000 device errors with “floating constant is out of range”

compiledoubleEmbedded Coderfloatsingleti c2000

When compiling code that has been generated for a TI C2000 device, I get the following error:
"floating constant is out of range"
How can I fix this?

Best Answer

Simulink generally uses doubles by default for data types, and consequently, the generated code also uses doubles by default. This issue is due to the TI compiler used by Simulink to build the generated code. The TI compiler treats both singles and doubles as 32-bit single-precision floating point numbers (which is atypical for compilers). This is done because using singles on a TI C2000 device is much more efficient than using doubles (since singles are handled in hardware and doubles are handled in software). So because Simulink and the C language expect these numbers to be treated as 64-bit double-precision floats, they are allowed to become much smaller and more precise than what could be stored in a 32-bit single-precision float. When the TI compiler goes to compile the generated code, it tries to fit these very small/precise numbers into 32 bits and fails because it really needs 64 bits.
I recommend that you modify your Simulink model to switch the relevant variables from doubles to singles. This should constrict the values of these variables to within the range of a 32-bit floating point number.