[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why do some math functions return -0
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 20 Sep 2010 09:43:52 -0300
> > Have a look at the Lua reference manual:
> >
> > Modulo is defined as
> >
> > a % b == a - math.floor(a/b)*b
> >
> > That is, it is the remainder of a division that rounds the
> > quotient towards minus infinity.
>
> "Defined as" is not the same as "implemented as". [...]
Then have a look at the code (http://www.lua.org/source/5.1/luaconf.h.html):
#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
As the problem seems to happen only in some platforms, there is a good
chance that something (floor itself?) is messing with the rounding mode.
-- Roberto
- References:
- Re: Why do some math functions return -0, HyperHacker
- Re: Why do some math functions return -0, KHMan
- Re: Why do some math functions return -0, HyperHacker
- Re: Why do some math functions return -0, David Kastrup
- Re: Why do some math functions return -0, Tony Finch
- Re: Why do some math functions return -0, David Kastrup
- Re: Why do some math functions return -0, Tony Finch
- Re: Why do some math functions return -0, David Kastrup
- Re: Why do some math functions return -0, Tony Finch
- Re: Why do some math functions return -0, David Kastrup