huh ? variables
Blitz3D Forums/Blitz3D Programming/huh ? variables
| ||
max=10 min=8 diff#=max/min The answer comes out as 1.0 ????? What the hell am I doing wrong ????? Feeling very fragile at the mo. :( |
| ||
max=10 min=8 diff#=float(max)/min |
| ||
Thats the one !, thanks MB. Although thats the first time I've had to use the float command, whats really strange is I'm doing the samekind of thing earlier in my proggie - and it works fine. But here.. it just stopped dead !!!. Anyway, thanks - I can stop banging my head against the wall now. (appologies for posting in the 3d thread, but it is part of a 3d program and I needed a quick answer - honest !) |
| ||
If the variables involved are declared as floats to begin with, it will use float division. Otherwise it uses integer division. e.g. max#=10 min#=8 diff#=max/min |
| ||
The DIFF var is defined as a FLOAT. No floating point maths is happening with the original 2 INTS. |
| ||
Read the Expressions section of the Blitz Language Reference. It explains exactly how expressions are evaluated. |
| ||
what it is doing is calculating the first 2 values as integers(10/8) then passing the result value to diff# so the result is rounded down to 1 before diff gets it. |