Search code examples
matlabinteger-division

Matlab uint8 division


I found in Matlab, uint8(n) / uint8(255) == 0 when n <127, while uint8(n) / uint8(255) == 1 when n >=127. I don't know how this happened. Since in C/C++, it should be 0 as long as numerator is less than denominator.

Can anyone help me, please?

Thanks!


Solution

  • Here, in the documentation:

    MATLAB® rounds the results when dividing integer data types.

    showing that MATLAB is not C or C++.

    But you can use the idivide function and have control over rounding.