[OpenSCAD] Modulo ?

Robert Bielik robert.bielik at dirac.se
Fri May 15 08:37:12 EDT 2015


Thanks guys, the reason I asked was because I have a for(i = [0 : 5]) 
and offset = i % 2 and I think it didn't work but now that I wrote that 
out loud, I think
I know the problem :)

Regards
/Robert

doug moen skrev den 2015-05-15 12:56:
> 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 
> <mailto: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 <mailto:Discuss at lists.openscad.org>
>     http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
>
>
> _______________________________________________
> 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/2509dc2e/attachment-0002.html>


More information about the Discuss mailing list