Math BUG

Previous topic - Next topic

Hemlos

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

Code (glbasic) Select
LOCAL a=100.0
LOCAL b=93.0
c=a/b
PRINT c,100,100
SHOWSCREEN
MOUSEWAIT
Code (glbasic) Select

a=100.0/93.0
PRINT a,100,100
SHOWSCREEN
MOUSEWAIT
Bing ChatGpt is pretty smart :O

Neurox

Incredible :(
I've tested your little program with GLBasic 5.360 and 6.034
and I have the same result (1 and 0)
Code (glbasic) Select

a=100/93
b=93/100
PRINT a,10,10
PRINT b,10,20
SHOWSCREEN
MOUSEWAIT
END

[/quote]

Neurox
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Hemlos

Problem solved with a little testing...

a=100.0/93.0
b=93.0/100.0
Bing ChatGpt is pretty smart :O

Kitty Hello

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.

Hemlos

#4
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.
Bing ChatGpt is pretty smart :O

MrTAToad

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.

Hemlos

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
Bing ChatGpt is pretty smart :O

Kitty Hello

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.

Hemlos

Thanks, really need that info in the help file!  :good:
Bing ChatGpt is pretty smart :O

Hemlos

Bing ChatGpt is pretty smart :O