Posted: 29th May 2021 12:39
Hello AppGameKit friends,

please how is this possible?
Can you explain it to me?

Code:


Output:
Posted: 29th May 2021 13:13
I tried to figure out what was going on but I got the same weird results. Tested in AGK2 and AGKS. It's almost as if it doesn't work with it as a single number and breaks it into parts to manage it.

Here's the code I used and a screenshot of my results.

+ Code Snippet
 
  cm1 = 378125999
 cm1# = 378125999
 cm1$ = str(cm1#)

 cm2 = 378125900 
 cm2# = 378125900
 cm2$ = str(cm2#)

 cm3 = 378125199
 cm3# = 378125199
 cm3$ = str(cm3#)

 cm4 = 398125999
 cm4# = 398125999
 cm4$ = str(cm4#)


do
  
    if getrawkeystate(27)=1 then end
    Print("cm1:  " + str(cm1))
	Print("cm1#: " + str(cm1#))
	Print("cm1$:  " + cm1$)
 	Print("=============")
    
	Print("cm2:  " + str(cm2))
	Print("cm2#: " + str(cm2#))
	Print("cm2$:  " + cm2$)
  	Print("=============")
    
    Print("cm3:  " + str(cm3))
	Print("cm3#: " + str(cm3#))
	Print("cm3$:  " + cm3$)
   	Print("=============")
   
	Print("cm4:  " + str(cm4))
	Print("cm4#: " + str(cm4#))
	Print("cm4$:  " + cm4$)

	
    Print( ScreenFPS() )
    sync()
loop 


Posted: 29th May 2021 14:57
cm# = 378125199


This code is assigning an INTEGER literal on the right hand side to a FLOAT (FLOATING POINT) value on the left hand side. If you print CM# it'll convert the FLOAT to a string which has decimal places, these will be zeros given the original conversion was from an Integer. Plenty of solutions, like you could INT() the value prior to display, or just keep CM integer.. etc

Print( int(Cm#) )
Posted: 29th May 2021 15:10
From the guide:

Note that whilst the range for Real numbers is very large its accuracy is limited to 7 significant figures. So you could represent 143670000.0 or 0.000053712, each has 5 significant figures, but not both in the same value 143670000.000053712 as the combined value has 18 significant figures. If you tried to store such a value it would be rounded to 143670000.0


So anything above 7 significant numbers will be rounded up/down/sideways/quantum entangled/teleported/summoned from another dimension/etc

+ Code Snippet
A# = 378125999
B# = 3781259
C# = 9999999
D# = 99999999
E# = 1.000001
F# = 1.0000001



do
    
	Print(A#)
	Print(B#)
	Print("")
	Print(C#)
	Print(D#)
	Print("")
	Print(E#)
	Print(F#)

    Sync()
loop
Posted: 29th May 2021 15:10
Friends, thank you for your support and answers!

@Kevin Picone
Unfortunately, this is not a valid instruction in AGK.

Still: Conversion to INT also doesn't work.

+ Code Snippet
	cm# = 378125999
	cmint = cm#
	print(cmint)
Posted: 29th May 2021 15:56
"So anything above 7 significant numbers will be rounded up/down/sideways/quantum entangled/teleported/summoned from another dimension/etc" - noobstar

I LOL'd.
Posted: 30th May 2021 15:03
Unfortunately, this is not a valid instruction in AGK.


try Floor()

But I suspect your hitting precision errors when converting an integer that big, since floats are lossy and are stored as a type of approximation (for want of better word) , allowing them great numeric range with the same number of bits as the integer, but the trade off is precision, so some information is lost when converting from Integer to Float and vice versa.
Posted: 30th May 2021 19:58
Unfortunately it is not just AppGameKit that has this issue C has been having the same problems since it started decades ago. Basically always use the right variable for the maximum number you wish to store in it

Integers for whole numbers, floats for floating point calculations. C++ introduced double and long long for huge numbers but the trade off is space a standard int is four bytes but a long long is eight as is a double.

If your making any sort of program ALWAYS know limits of variables this way you won't be scratching your head when your unsigned char won't go beyond 0 to 255
Posted: 30th May 2021 21:17
if windows, this dll?

otherwise: https://forum.thegamecreators.com/thread/224667 ?