Thu 26 Jun 2014 06:21:25 PM UTC, original submission:
As reported in this thread
http://lists.gnu.org/archive/html/help-octave/2014-06/msg00349.html
while in Matlab the result is reported to be zero.
In function xrem() in liboctave/numeric/lo-mappers.h (tip of
default branch), for
xrem (x, y) and q defined as q := x / y,
there is a case distinction for abs(x) <= 1 or > 1. For abs(x) > 1, q is adjusted to an integer if its calculated deviation from an integer is less than roughly the accuracy (epsilon * q) with which q is represented (by a double in this case), which seems ok. But for abs(x) <= 1, the assumed accuracy of q seems to be just epsilon, not epsilon * q. A test showed me that if the case
abs(x) <= 1 were not treated special, the result would be zero (eps was 2.22044604925031e-16, abs(q-94) was greater than eps (1.42108547152020e-14, this is the special treatment of abs(x) <= 1), and abs(q-94)/94 was less than eps (1.51179305480872e-16, this is without the special treatment)).
The special treatment of abs(x) <= 1 is done the same way also for xmod.
I don't see the reason for this special treatment. It was introduced with this changeset:
changeset: 11209:94d9d412a2a0
user: John W. Eaton <jwe@octave.org>
date: Tue Nov 09 00:57:49 2010 -0500
summary: improve Matlab compatibility of rem and mod
when the code was still in lo-mappers.cc, not lo-mappers.h. If Matlab compatibility was the reason, than according to the current user report the reason does not apply anymore.
|