"proper" integer division
Peter L. Søndergaard
peter at sonderport.dk
Tue Mar 11 08:14:14 CDT 2008
I noticed that Octave does integer division by rounding to the nearest
integer (probably for compatibility with Matlab) instead of floor'ing as
in C, so (as mentioned here
http://www.gnu.org/software/octave/doc/interpreter/Integer-Arithmetic.html
)
then int32(5)./int32(8) == 1 and not zero.
Is there a build-in function that will return the correct result, or a
better construction that the following:
% Compute the integer division of a/b
(a-mod(a,b)/b
It would be handy with a simple build-in function that returned the
quotient and the remainder as the "div" function in C does.
Cheers,
Peter.
More information about the Help-octave
mailing list