ErosOlmi
16-07-2008, 22:42
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:
'---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
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:
... (MyDouble - 0.6) AS DOUBLE
... (0.123) AS DOUBLE
or
MyEntityID = tbgl_entityfindbypos( %SCENE1, %TBGL_BOX, cx, cy, (cz - 0.6) as double )
or even casting intermediate expressions as many times as needed (following example exagerated by choice in order to give you the idea):
... (MyExt * (MyDouble + 1.12345) AS DOUBLE * (10 + .598) AS DOUBLE) AS single
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.
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:
'---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
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:
... (MyDouble - 0.6) AS DOUBLE
... (0.123) AS DOUBLE
or
MyEntityID = tbgl_entityfindbypos( %SCENE1, %TBGL_BOX, cx, cy, (cz - 0.6) as double )
or even casting intermediate expressions as many times as needed (following example exagerated by choice in order to give you the idea):
... (MyExt * (MyDouble + 1.12345) AS DOUBLE * (10 + .598) AS DOUBLE) AS single
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.