huh ? variables

Blitz3D Forums/Blitz3D Programming/huh ? variables

PaulJG(Posted 2003) [#1]
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. :(


Beaker(Posted 2003) [#2]
max=10
min=8

diff#=float(max)/min


PaulJG(Posted 2003) [#3]
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 !)


soja(Posted 2003) [#4]
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


PaulJG(Posted 2003) [#5]
The DIFF var is defined as a FLOAT. No floating point maths is happening with the original 2 INTS.


Floyd(Posted 2003) [#6]
Read the Expressions section of the Blitz Language Reference.

It explains exactly how expressions are evaluated.


(tu) sinu(Posted 2003) [#7]
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.