wking
wking

Reputation: 1353

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!

Upvotes: 0

Views: 1160

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283733

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.

Upvotes: 2

Related Questions