[Rd] Modulus Bug (PR#7409)

Prof Brian D Ripley ripley at stats.ox.ac.uk
Thu Dec 9 16:39:25 CET 2004


On Thu, 9 Dec 2004, Thomas Lumley wrote:

> On Thu, 9 Dec 2004 ripley at stats.ox.ac.uk wrote:
>
> > This is nothing to do with integers: 1e18 and 11 are doubles here.
> >
> > It is a result of rounding error: 1e18/11 is not representable accurately,
> > and this should have been a warning to you that your calculations were
> > unreasonable.
>
> It was -- the poster originally asked about large integer representations
> and said he was planning to use other software for large integers.

Ah, but that's not in this bug report.

> At the time I said that the fact %% didn't give some sort of error or
> warning was a bug, and was planning to return either a warning or NA or
> NaN if
>    abs(x1)>1/.Machine$double.eps
>
>  	-thomas

I've done that (a warning) but it needed caching .Machine at C level to
make it reasonably efficient.  I've also done a second pass to ensure
the result is within range (even if possible nonsense).

>
> > The C code is
> >
> > double myfmod(double x1, double x2)
> > {
> >     double q = x1 / x2;
> >     return x1 - floor(q) * x2;
> > }
> >
> > We can improve the answer, but what you are doing is fundamentally flawed
> > and it is hard to detect whether rounding error has affected this. A
> > warning rather than an error seems appropriate.
> >
> > If you really want to do things like this, try the gmp package (which
> > seems to give the wrong answer here) or a more appropriate calculator.
> >
> >
> > On Thu, 9 Dec 2004 Robert.McGehee at geodecapital.com wrote:
> >
> >> R Developers,
> >>
> >> 1000000000000000000 %% 11
> >> [1] -32
> >>
> >> I now understand that integers cannot be larger than
> >> .Machine$integer.max, but because the above produces a result than is
> >> patently wrong instead of an error, I'm reporting this as a bug.
> >
> > --
> > Brian D. Ripley,                  ripley at stats.ox.ac.uk
> > Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> > University of Oxford,             Tel:  +44 1865 272861 (self)
> > 1 South Parks Road,                     +44 1865 272866 (PA)
> > Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> >
> > ______________________________________________
> > R-devel at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list