# A possible solution, was Re: boolean logic in openscad Classic List Threaded 3 messages Open this post in threaded view
|

## A possible solution, was Re: boolean logic in openscad

 > Date: Wed, 26 Oct 2011 19:50:09 +0200 > From: [hidden email] > To: [hidden email] > Subject: Re: [OpenSCAD] boolean logic in openscad > > On Wed, Oct 26, 2011 at 01:36:10PM +0000, William Adams wrote: > > I am wanting to implement a function that has the following pattern > > func(x) = (x<<13) & 0x7fffffff[...]? >   > are you aware that this is just the same as func(x) = (x*8192) % 2147483648; > (that is, in more readable but non-openscad notation, x*(2^13) % 0x80000000)? >   > (at least, if you expect x to behave like an integer -- i couldn't > correlate your sniplet to the source code i found when quickly looking > it up.) >   > regards > chrysn         William,         I am not familair with Perlin functions but I         think Chrysn here comes closest to a solution.         Given his observation that the AND operation         can be replaced by MOD in the case of a group         of contiguious bits, the only missing operator         in OpenSCAD is the shift operator.  No big deal.         Let me go just a bit further to find:                 func(x) = (x<<13) & 0x7fffffff                 func(x) = ((2^13)*x) mod 2^31                 func(x)/2^13 = x mod 2^18                 func(x) = (2^13)*(x mod 2^18)                 func(x) = 8192*(x mod 262144)         which, I believe, can be implemented in many         languages (including OpenSCAD) as                 func(x) = 8192*(x % 262144).         Does that accomplish what you have in mind for         Perlin functions?         Yours,                             Dan