type casting.....

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

type casting.....

bboett
Hello!
i am rewriting a hinge lib, and to be sure to have a valid setup, i wanted to check if the imputed value is uneven (??)
that's when i noted, there doesn't seem to be typecasting in openscad?

how do i achieve: x - 2*int(x/2) != 0 ?

i searched in the archives, but i only found on how to find out what type is in the var, but not how to cast it....

thanks in advance!
--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: type casting.....

nophead
There is no type casting because their is only one number type in OpenSCAD. You could use floor(x/2) as that will be an integer value held in a floating point type. The is also ceil() and round().

On Sun, 12 Apr 2020 at 10:41, Bruno Boettcher <[hidden email]> wrote:
Hello!
i am rewriting a hinge lib, and to be sure to have a valid setup, i wanted to check if the imputed value is uneven (??)
that's when i noted, there doesn't seem to be typecasting in openscad?

how do i achieve: x - 2*int(x/2) != 0 ?

i searched in the archives, but i only found on how to find out what type is in the var, but not how to cast it....

thanks in advance!
--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: type casting.....

nophead
To test oddness x % 2 is useful.

On Sun, 12 Apr 2020 at 10:52, nop head <[hidden email]> wrote:
There is no type casting because their is only one number type in OpenSCAD. You could use floor(x/2) as that will be an integer value held in a floating point type. The is also ceil() and round().

On Sun, 12 Apr 2020 at 10:41, Bruno Boettcher <[hidden email]> wrote:
Hello!
i am rewriting a hinge lib, and to be sure to have a valid setup, i wanted to check if the imputed value is uneven (??)
that's when i noted, there doesn't seem to be typecasting in openscad?

how do i achieve: x - 2*int(x/2) != 0 ?

i searched in the archives, but i only found on how to find out what type is in the var, but not how to cast it....

thanks in advance!
--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: type casting.....

bboett
ahh modulo! yes, nice one thanks!
that did it!

Am So., 12. Apr. 2020 um 11:54 Uhr schrieb nop head <[hidden email]>:
To test oddness x % 2 is useful.

On Sun, 12 Apr 2020 at 10:52, nop head <[hidden email]> wrote:
There is no type casting because their is only one number type in OpenSCAD. You could use floor(x/2) as that will be an integer value held in a floating point type. The is also ceil() and round().

On Sun, 12 Apr 2020 at 10:41, Bruno Boettcher <[hidden email]> wrote:
Hello!
i am rewriting a hinge lib, and to be sure to have a valid setup, i wanted to check if the imputed value is uneven (??)
that's when i noted, there doesn't seem to be typecasting in openscad?

how do i achieve: x - 2*int(x/2) != 0 ?

i searched in the archives, but i only found on how to find out what type is in the var, but not how to cast it....

thanks in advance!
--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


--
ciao
Bruno

===========================================
http://nohkumado.eu/, http://aikido.nohkumado.eu/,
http://aikido.zorn.free.fr

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org