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.

Newcomers AppGameKit Corner / [SOLVED] Floating point arithmatic help please

Richard Stevens
User Offline
Joined: 14th Jan 2020
Posted: 23rd Jul 2020 17:26
I'm part way through my first 'masterpiece', and I came across a bit of an odd one when calculating something or other.. essentially it can be boiled down to:

Return 0? Surely it should return 0.5?

Sorry If I'm missing something blazingly obvious!

The author of this post has marked a post as an answer.

Go to answer

Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 23rd Jul 2020 18:06 Edited at: 23rd Jul 2020 18:07
This post has been marked by the post author as the answer.
if you use:
X = 1.0/2

then you get 0.5 as the answer like you expected.

If you don't specify floating point literal numbers in a calculation, then AppGameKit takes those numbers as integers. The integer answer of 1/2 is zero.
Valued Member
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd Jul 2020 18:14
Additional note:

1.0/2 will give the same result as 1/2.0

If you use one float in your calcs, the result will also be a float ( if the result variable is a float ).


Coders don't die, they just gosub without return
Richard Stevens
User Offline
Joined: 14th Jan 2020
Posted: 24th Jul 2020 11:51
Thanks. I thought it must be related to something along those line, but thought as X had already been marked as a float AppGameKit would consider calculations performed on it as float. I guess not !

Thanks, all working now.

Login to post a reply

Server time is: 2020-09-30 17:06:45
Your offset time is: 2020-09-30 17:06:45