1

Is there exist a method in matlab equivalent to c# method Math.IEEERemainder.

Details about this method can be found here: Is Math.IEEERemainder(x,y) equivalent to x%y?

According to IEEERemainder specifications:

3/2 should be -1

However Matlab method mod(3,2) returns 1 and rem(3,2) also returns 1.

Community
  • 1
  • 1
User1551892
  • 3,236
  • 8
  • 32
  • 52
  • have you seen [`mod`](http://www.mathworks.com/help/matlab/ref/mod.html) and [`rem`](http://www.mathworks.com/help/matlab/ref/rem.html) in MATLAB? Also worth reading [Division and Modulus for Computer Scientists](http://research.microsoft.com/pubs/151917/divmodnote.pdf) – Amro Nov 04 '14 at 14:43

1 Answers1

1

The correct mathematical function would be x-y*round(x/y). The only difference between this expression and Math.IEEERemainder is when the value of x/y is exactly halfway between two integers. In that case, round(x/y) rounds away from zero, while the rounding function in Math.IEEERemainder rounds to the even integer.

A function could look like this:

function out=IEEERemainder(x,y)
x-y.*round(x./y)
end
E. Schiesser
  • 367
  • 4
  • 13