Eros:
Thanks -- That's a winner!
Don
In some circumstances it is necessary to execute numeric expressions and cast result to a specific numeric data type: INTEGER, LONG, DOUBLE, ...
In some special case it is even necessary to CAST intermediate results inside a more complex numeric expression.
So far it was not easy other than writing some obscure code like:
[code=thinbasic]
'---CZ is a DOUBLE
cvd(mkd$(cz - 0.6))
'---Convert a number to a string buffer representing a binary DOUBLE and than get back to a double number
[/code]
or defining a variable of the needed type assigning the result of intermediate expressions, than using that variable to pass value to a function that wants a DOUBLE or use it into more complex expression.
From the next version you will have more options: numeric data casting.
For example, every single math expression can be casted to a numeric type using the syntax: (math expression) AS NumericType
So to return a DOUBLE from a math expression you can type something:
[code=thinbasic]
... (MyDouble - 0.6) AS DOUBLE
... (0.123) AS DOUBLE
[/code]
or
[code=thinbasic]
MyEntityID = tbgl_entityfindbypos( %SCENE1, %TBGL_BOX, cx, cy, (cz - 0.6) as double )
[/code]
or even casting intermediate expressions as many times as needed (following example exagerated by choice in order to give you the idea):
[code=thinbasic]
... (MyExt * (MyDouble + 1.12345) AS DOUBLE * (10 + .59 AS DOUBLE) AS single
[/code]
The above syntax will be valid in any place where a numeric expression is needed, will not influence current scripts, will not slow down execution (it is just an IF more in compiled code) and will be optional at any level.
Hope you like it.
Regards
Eros
_________________________________________________
Attached thinCore.dll. Substitute the one you have into your \thinBasic\ directory
Important: attached file is just for testing. You need to have current latest official thinBasic installed in order to test attached Core.
Updates:
- 2008.07.17: all numeric assignments are now making internal rounding depending on receiving variable type.
- 2008.07.18: also numeric expressions passed to API or, in general, external DLLs functions are now numeric rounded to the numeric type indicated in function prototype (DECLARE statement).
Fixed a bug in #IF/#ENDIF preparsing statement introduced into previous attach.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Eros:
Thanks -- That's a winner!
Don
XPS 1710
Forgot to attach a working thinCore.dll
If someone wants to test it now it is possible.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks Eros,
this is very clean way to handle precision
Thanks,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Update thinCore.dll attached to first post of this thread.
_________________________________________________
All numeric assignments and data retrieving will now internally automatically cast (round) numeric expressions depending on receiving or source numeric variable type.
Regards
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Maxxxxximum coding comfort,
thanks a lot Eros, really amazing and quite unique even across different languages.
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Eros:
Things keep getting better and better for us number-crunchers.
The change you made today makes thinBasic function like FORTRAN in this regard; and that's great.
Thanks.
Don
XPS 1710
I'm happy you are happy
Anyhow, please report any inconvenience, bug or other un-expected behaves.
I did a global check and should have not forgot any place where rounding should take effect but, you know, I'm only human.
I know that remains two places where I need to work on:
- when passing numeric expressions to keywords present in external modules (I need to work on this with people developing modules)
- when passing numeric expressions to external DLL functions (here I think I can easily fix it by next thinBasic version)
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Update thinCore.dll attached to first post of this thread.
_________________________________________________
Also numeric expressions passed to API or, in general, external DLLs functions are now numeric rounded to the numeric type indicated in function prototype (DECLARE statement).
Fixed a bug in #IF/#ENDIF preparsing statement introduced into previous attached thinCore.
Regards
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks Eros,
I like it
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Bookmarks