Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Little problem with numbers

Author
Message
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 29th May 2021 12:39
Hello AppGameKit friends,

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

Code:


Output:
I am sorry for poor English
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 29th May 2021 13:13 Edited at: 29th May 2021 13:14
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.



LynxJSA's web games/quizzes - LynxJSA's Android apps
AGK Resource Directory
"Stick to a single main loop (DO...LOOP) and loop through it every frame.
Do everything inside functions.
Use finite state machines to control your game.
Use lots and lots of source files.
Use virtual resolution instead of the default percentage system." - Digital Awakening
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
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#) )


PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 29th May 2021 15:10 Edited at: 29th May 2021 15:12
From the guide:

Quote: "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

-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us

Attachments

Login to view attachments
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
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.

I am sorry for poor English
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
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.

LynxJSA's web games/quizzes - LynxJSA's Android apps
AGK Resource Directory
"Stick to a single main loop (DO...LOOP) and loop through it every frame.
Do everything inside functions.
Use finite state machines to control your game.
Use lots and lots of source files.
Use virtual resolution instead of the default percentage system." - Digital Awakening
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 30th May 2021 15:03

Quote: "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.

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
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
-EdzUp
Patreon: https://www.patreon.com/EdzUp
Buy me a coffee:https://www.buymeacoffee.com/EdzUp
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 30th May 2021 21:17
if windows, this dll?

otherwise: https://forum.thegamecreators.com/thread/224667 ?
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]

Login to post a reply

Server time is: 2024-04-25 17:18:57
Your offset time is: 2024-04-25 17:18:57