[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: Modulo with negative operands
From: Dirk Laurie <dirk.laurie () gmail ! com>
Date: 2019-04-22 19:45:37
Message-ID: CABcj=tneuTzHkgAmLTPkRwGp1SkNcZCB1tqAhdRWGUroK+YX6A () mail ! gmail ! com
[Download RAW message or body]
Op Ma. 22 Apr. 2019 om 14:11 het Albert Chan <albertmcchan@yahoo.com> geskryf:
> Does anyone write Lua code that uses % negative divisor behavior ?
>
> If we really need a minus sign, It seems better to explicitly say it.
The manual for Lua 5.3 says:
Floor division (//) is a division that rounds the quotient towards
minus infinity, that is, the floor of the division of its operands.
Modulo is defined as the remainder of a division that rounds the
quotient towards minus infinity (floor division).
I.e. % and // are locked together so that a == b*(a//b)+a%b
Previous versions of Lua did not have //, and the discussiion of % was
accordingly longer and may have been confusing to some readers.
It's quite simple now: the result of a%b always lies in the half-open
range from 0 to b, up or down, with b not included.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic