# bug #41894: mod output ML incompatible

 Submitted by: Juan Pablo Carbajal Submitted on: Tue 18 Mar 2014 10:41:14 AM UTC Category: Octave Function Severity: 3 - Normal Priority: 5 - Normal Item Group: Matlab Compatibility Status: Fixed Assigned to: None Originator Name: juanpi Open/Closed: Closed Release: dev Operating System: Any

You are not logged in

## Discussion

Thu 12 Nov 2015 03:03:19 PM UTC, comment #2:

I also see this fixed now. Closing as such.

Also, ML is a programming language https://en.wikipedia.org/wiki/ML_%28programming_language%29 and not short of Matlab.

CarnĂ« Draug <carandraug>
Thu 12 Nov 2015 07:01:59 AM UTC, comment #1:

Checking with 4.0.0 on Windows:

>> Gamma = 1.62e7;
>> duration = 10/Gamma;
>> dt = 0.0025/Gamma;
>> t   = 0:dt:duration;
>> y = mod (t, 0.2/Gamma);
>> find (y==0,3,'first')
ans =

1    81   161

Avinoam Kalma <avinoam>
Tue 18 Mar 2014 10:41:14 AM UTC, original submission:

In the mailing list we have a report about MOD. The matlab implementation indeed corrects the result when roundoff error generates an answer different than expected. Example follows

Gamma = 1.62e7;
duration = 10/Gamma;
dt = 0.0025/Gamma;
t   = 0:dt:duration;
y = mod (t, 0.2/Gamma);
find (y==0,3,'first')

octave
1   241   401

Matlab r2008b
1    81   161

Reading the help of mod in matlab it says that the result of MOD
is x - n.*Y with n = floor(x./Y). If Y is not an integer and the quotient x./Y is within roundoff error of an integer, then n is that integer.

So indeed matlab is giving a result considering roundoff error, I assume they do something like

function m = mod_ml(x,y)
if fix(y) != y
err      = abs (x./y - round(x./y)) < sqrt (eps);
m       = mod (x,y);
m(err) = 0;
endif
endfunction

We could issue a warning as well.

This bug is related to bug #32924

Juan Pablo Carbajal <juanpi>

## Attached Files

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Comment:

No files currently attached

## Dependencies

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by avinoam (Posted a comment)
• -email is unavailable- added by juanpi (Submitted the item)
•

Do you think this task is very important?
This task has 0 encouragements so far.

Only project members can vote.