help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question re: floor of integer division


From: Mike Miller
Subject: Re: Question re: floor of integer division
Date: Mon, 24 Feb 2014 09:52:01 -0500

On Mon, Feb 24, 2014 at 08:42:39 -0600, Rhys Ulerich wrote:
> I must be missing something, but I don't understand why floor(i/N)
> behaves differently than floor(i/int32(N)) for N = 128 in the sample
> below...
>
> octave:1> i = 0:639;
> octave:2> S = 5;
> octave:3> N = 128;
> octave:4> qinv = mod(i,N)*S + floor(i/N); min(qinv), max(qinv)
> ans = 0
> ans =  639
> octave:5> qinv = mod(i,N)*S + floor(i/int32(N)); min(qinv), max(qinv)
> ans = 0
> ans = 640

Good question. The difference you are seeing is due to integer
division rules in Octave and Matlab which are different from the rules
you may be used to from C and other programming languages. See

  https://www.gnu.org/software/octave/doc/interpreter/Integer-Arithmetic.html

HTH,

-- 
mike


reply via email to

[Prev in Thread] Current Thread [Next in Thread]