If we don't specify a type (a% or a#) what exactly happens?. An example: I want to create a TYPE rectangle, if I do the followirng:
TYPE TRectangle
left
right
width
height
ENDTYPE
How it works?, it is dynamically converted?, it is used as template and then the compiler creates the % and/or the # version when needed/used?.
Because sometimes it is preferable to force the use of the IPU (Integer Processing Unit) instead the FPU, specially on devices. Then, with the prior example, should I do:
1) At use: assign by 'rect.left%=value', this is, referencing always with the % for specify type.
2) Create 2 rectangles:
TYPE TRectangle
left%
right%
width%
height%
ENDTYPE
and
TYPE TRectangleF
left#
right#
width#
height#
ENDTYPE
I'd like to know how GLBasic works internally with this to handle it correctly.
Using # or nothing defines a variable as a floating-point one. To use integer, the variable has to be initially defined with %, after which it can be left off (although I feel its bad practise to). You can do this because a variable retains its type after being defined - although for strings, you do need to keep using $.
Never heard of an IPU though...
To force floating point calculations you need to use decimals. For example 1/100 will give 0 but 1/100.0 will give what you expect. As far as I know, GLBasic is working with integers unless you specify floating point by using a decimal somewhere.
For constants it's using what you type: 1/3 is int/int -> int. 1/3.0 or 1.0/3 is int/float or float/int -> float.
If you make a variable without %#, it will be auto-# (float).