a=100/93 equals "1", this should be 1.0752688172043010752688172043011
b=93/100 equals "0" , this should be 0.93
really need decimal math for 3d, with sin and cos, and even for simple 2d operations like a loadbar
EDIT: found 2 solutions
LOCAL a=100.0
LOCAL b=93.0
c=a/b
PRINT c,100,100
SHOWSCREEN
MOUSEWAIT
a=100.0/93.0
PRINT a,100,100
SHOWSCREEN
MOUSEWAIT
Incredible :(
I've tested your little program with GLBasic 5.360 and 6.034
and I have the same result (1 and 0)
a=100/93
b=93/100
PRINT a,10,10
PRINT b,10,20
SHOWSCREEN
MOUSEWAIT
END
[/quote]
Neurox
Problem solved with a little testing...
a=100.0/93.0
b=93.0/100.0
Right. integer numbers are interger for the compiler. If you're doing a division of const values, the compiler will substitute it with the result already. So if you need fraction points, add a .0 to and of the numbers to force a double conversion.
gernot could you add that info to the "math" in help file, about adding a decimal to the values?
BTW i tested this with the 3d math in making objects. no luck in making straight "evenly spaced" lines with and without sin/cos , i was already using the decimals here originally.
Wondering if it would be possible to have a FLOAT() command - which would automatically convert to a floating point value (and would be the opposite of INTEGER()) - this would save having to multiply everything by 1.0 in order to force a conversion to a real value.
Quote from: MrTAToad on 2008-Oct-14
Wondering if it would be possible to have a FLOAT() command - which would automatically convert to a floating point value (and would be the opposite of INTEGER()) - this would save having to multiply everything by 1.0 in order to force a conversion to a real value.
You have to divide by 1.0
No, the problem just occours, when you write an integer constant, or use an integer with integers.
LOCAL i%, j%, a#, b#
i% =5
a# = 5 // zuweisung an double, passt
b# = 14/8 // integer/ingeger -> integer -> 1
j = j/i // integer/integer -> integer -> 1/5=0
i=3
j = a/i // double/integer -> double -> 5/3 = 1.667
j = i/a // integer/double -> double -> 3/5 = 0.60
Zusammenfassend: Das Problem besteht nur bei Divisionen, und dann auch nur, wenn beide Operanden ein Integer sind.
Thanks, really need that info in the help file! :good:
Im not done with you yet Senior Gernot :'(
http://www.glbasic.com/forum/index.php?topic=2422.msg18324#msg18324 (http://www.glbasic.com/forum/index.php?topic=2422.msg18324#msg18324)