[OpenSCAD] boolean logic in openscad
William Adams
william_a_adams at msn.com
Thu Oct 27 00:47:28 CEST 2011
Havint that sort of behavior would be great I think. I would imagine that most people who want to do boolean algebra will be dealing with integer values. But yah, from a completeness standpoint, without an actual separation between float/double, and int types, it could be confusing. Sometimes I need AND, sometimes OR, sometimes XOR. Those are probably the most common cases. Then of course there's the bit shifting operators. They can all be simulated, but the more that are baked in, the better from a performance perspective. -- William
===============================
- Shaping clay is easier than digging it out of the ground.
http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
> Date: Wed, 26 Oct 2011 17:41:25 -0500
> From: hugh.m.bright at gmail.com
> To: openscad at rocklinux.org
> Subject: Re: [OpenSCAD] boolean logic in openscad
>
> If you want to add stuff like this, hack on the following files:
>
> parser.y
> lexer.l
> value.cc
> value.h
> expr.cc
>
> I added bitwise AND in about 20 minutes. The problem is that in Openscad
> you deal with it's Value type, and if that is a NUMBER it is using a
> C++ "double"
> in the underlying code.
>
> This means very weird and/or unexpected results sometimes. (like, what
> shoudl the bitwise AND of 3.4 and 4.6 be? See more by googling
> "bitwise float double"
>
> My version just 'casts' the dobule to unsigned int, then bitwise ANDs
> the two uints,
> and then casts back into double for the resulting Value().
>
> This could cause some very weird and/or unexpected behavior in some cases.
>
> -DB
>
>
> On Wed, Oct 26, 2011 at 1:33 PM, William Adams <william_a_adams at msn.com> wrote:
> > My code reference comes from here:
> > http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
> >
> > Really what I want is to port the simplex noise functions that I have
> > written in C#, but I can't because they require me to use static arrays of
> > values. That has proven to be very cost prohibitive in OpenScad, so I am
> > reimplementing using an approach that does not require any storage. It's a
> > bit slower, but not as slow as the array accesses become over time.
> >
> > -- William
> >
> > ===============================
> > - Shaping clay is easier than digging it out of the ground.
> >
> > http://blog.nanotechstyles.com
> > http://www.thingiverse.com/WilliamAAdams
> > https://github.com/Wiladams
> >
> >
> >
> > ________________________________
> > From: william_a_adams at msn.com
> > To: openscad at rocklinux.org
> > Date: Wed, 26 Oct 2011 18:29:10 +0000
> > Subject: Re: [OpenSCAD] boolean logic in openscad
> >
> > Why yes! In fact, the way I implemented it was:
> >
> > function LSHIFT(x,pos=1) = x * pow(2,pos);
> >
> > and opposite for RSHIFT.
> >
> > Also, sometimes I need '&', sometimes I need '|', and sometimes I need '^'
> > (xor). And sometimes I need NAND, etc. So, I just implement them as simple
> > macros.
> >
> > That way I don't have to remember my powers of 2 whenever I want to use
> > them. So, in this case, it turns into:
> >
> > func(x) = 32BITAND((LSHIFT(x,13)), 2147483648);
> >
> > That's really easy for my small brain to wrap around, because if I do it
> > more than once, it's nice to have it done correctly every time.
> >
> > It would be nice if the boolean algebra were just there, and hex notation
> > was supported. I think hex notation is coming, so that will be nice.
> >
> > -- William
> >
> > ===============================
> > - Shaping clay is easier than digging it out of the ground.
> >
> > http://blog.nanotechstyles.com
> > http://www.thingiverse.com/WilliamAAdams
> > https://github.com/Wiladams
> >
> >
> >
> > Date: Wed, 26 Oct 2011 19:50:09 +0200
> > From: chrysn at fsfe.org
> > To: openscad at rocklinux.org
> > 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[1].)
> >
> > regards
> > chrysn
> >
> > [1] http://mrl.nyu.edu/~perlin/doc/oscar.html#noise
> >
> > --
> > To use raw power is to make yourself infinitely vulnerable to greater
> > powers.
> > -- Bene Gesserit axiom
> >
> > _______________________________________________ OpenSCAD mailing list
> > OpenSCAD at rocklinux.org http://rocklinux.net/mailman/listinfo/openscad
> > _______________________________________________ OpenSCAD mailing list
> > OpenSCAD at rocklinux.org http://rocklinux.net/mailman/listinfo/openscad
> > _______________________________________________
> > OpenSCAD mailing list
> > OpenSCAD at rocklinux.org
> > http://rocklinux.net/mailman/listinfo/openscad
> >
> >
> _______________________________________________
> OpenSCAD mailing list
> OpenSCAD at rocklinux.org
> http://rocklinux.net/mailman/listinfo/openscad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rocklinux.net/pipermail/openscad/attachments/20111027/fedf1fc0/attachment-0001.html
More information about the OpenSCAD
mailing list