[OpenSCAD] Modulo ?

doug moen doug at moens.org
Fri May 15 06:56:53 EDT 2015


Be warned that if you are looking for the modulus function as it is
normally defined in mathematics
(eg, as defined here: http://mathworld.wolfram.com/Mod.html)
then a % m is only equal to a mod m when the arguments are non-negative.

0 % 3 == 0    0 mod 3 == 0
1 % 3 == 1    1 mod 3 == 1
2 % 3 == 2    2 mod 3 == 2
3 % 3 == 0    3 mod 3 == 0

If the first argument is negative, you won't get the expected result.

-1 % 3 == -1  -1 mod 3 == 2

You can define the mod function like this (with correct behaviour for
negative arguments):

function mod(a,m) = a - m*floor(a/m);



On 15 May 2015 at 02:43, Chow Loong Jin <hyperair at debian.org> wrote:

> On Fri, May 15, 2015 at 08:07:03AM +0200, Robert Bielik wrote:
> > Hi all,
> >
> > New to OpenSCAD, fantastic tool! However I miss a modulo operator, or
> have I
> > missed it ? :)
>
> You mean arithmetic modulo? That's %.
>
> --
> Kind regards,
> Loong Jin
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20150515/bf50ced8/attachment-0002.html>


More information about the Discuss mailing list