MATLAB: How to force integer operation results to wrap on overflow in MATLAB 7.8 (R2009a)

MATLAB

I am attempting to translate an algorithm that was previously developed and tested in C, into a MATLAB function. This algorithm is used to generate a random number, and depends on the C language behavior of wrap on integer overflow. However, since integers saturate on overflow in MATLAB, the algorithm does not work as expected.

Best Answer

The ability to force an integer operation result to wrap on overflow is not available in MATLAB 7.8 (R2009a).
In order to work around this issue, you may use the capability of the Fixed-Point Toolbox to customize overflow modes.
An example that utilizes this capability can be found in the MATLAB online documentation under the heading "Using fimath to Specify Rounding and Overflow Modes".