octave-maintainers
[Top][All Lists]
Advanced

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

Re: bad mod function


From: Rik
Subject: Re: bad mod function
Date: Tue, 19 Jun 2018 09:36:06 -0700

On 06/19/2018 08:45 AM, address@hidden wrote:
Subject:
bad mod function - Matlab
From:
Vic Norton <address@hidden>
Date:
06/19/2018 08:08 AM
To:
Octave Maintainers List <address@hidden>
List-Post:
<mailto:address@hidden>
Content-Transfer-Encoding:
quoted-printable
Precedence:
list
MIME-Version:
1.0 (Mac OS X Mail 10.3 \(3273\))
Message-ID:
<address@hidden>
Content-Type:
text/plain; charset=utf-8
Message:
5

The mod function in my Mac system is not working.
———————————————————————————————————

Here is essentially the same script run with Matlab.
This is the way the mod function is supposed to work

%% testmod.m  - test the mod function
%    with Matlab '9.3.0.713579 (R2017b)'

fprintf('-- bad mod function? --\n');
for i = 1 : 11
 fprintf('%4d', i);
 if mod(i, 5) == 1; fprintf('\n'); end
end
fprintf('-- good mod function --\n');
for i = 1 : 11
 fprintf('%4d', i);
 if modxy(i, 5) == 1; fprintf('\n'); end
end

function v = modxy(x, y)  % to replace the faulty mod function
 v = x - y .* floor (x ./ y);
end

%{
testmod
-- bad mod function? --
  1
  2   3   4   5   6
  7   8   9  10  11
-- good mod function --
  1
  2   3   4   5   6
  7   8   9  10  11
%}


For the moment, skip the for loop and more complicated code.  What does the following return when entered on the Octave command line?

mod (5,5)
mod (6,5)
mod (7,5)

It should be 0, 1, and 2 respectively.  If it isn't then there is something wrong with the installation as Dmitri suggested.

--Rik

reply via email to

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