| Mathematics | ![]() |
Warnings for Integer Data Types
You can use the intwarning('on') command to make MATLAB return a warning message when it converts a number outside the range of an integer data type to that data type or when the result of an arithmetic operation overflows. For example,
intwarning('on') int16(50000) Warning: Out of range value converted to intmin('int16') or intmax('int16'). ans = 32767
There are four possible warning messages that you can turn on using intwarning. The following example illustrates all four warning messages.
intwarning('on') int8([NaN Inf pi])+1000 Warning: NaN converted to int8(0). Warning: Out of range value converted to intmin('int8') or intmax('int8'). Warning: Conversion rounded non-integer floating point value to nearest int8 value. Warning: Out of range value or NaN computed in integer arithmetic. ans = 127 127 127
To turn these warnings off (their default state when you start MATLAB), enter
Turning Warnings On or Off Temporarily
When writing M-files that contain integer data types, it is sometimes convenient to temporarily turn integer warnings on and then return the states of the warnings ('on' or 'off') to their previous settings. The following commands illustrate how to do this:
oldState = intwarning('on'); int8(200) Warning: Out of range value converted to intmin('int8') or intmax('int8'). ans = 127 intwarning(oldState)
To temporarily turn the warnings off, change the first line of the preceding code to
| Example -- Digitized Signals | Single-Precision Mathematics | ![]() |
© 1994-2005 The MathWorks, Inc.