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 / Division bug?

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Apr 2013 09:28
Last time I checked, 17.000015 / 32 does not equal 1.

15.999 or 16.000 divided by 32 will result in 0, but anything over 16 is being rounding up. So best as I figure, and float division being assigned to an integer value gets rounded, with anything over 0.5 rounding up.

My way around this is to use floor() before assigning the result. Was this float to integer rounding intentional or a bug?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Apr 2013 09:43
In math 0.5 is always rounded up to 1. So 16.000/32 should return 1. so it seems like you actually found a different bug than you thought

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Apr 2013 10:46
Quote: "In math 0.5 is always rounded up to 1"

Shouldn't be rounded at all and just truncated like DB always did.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Apr 2013 11:05
why not use 16.0/32.0 (both float) , then you can round self
float / int is bad combination.
in source code for numbers i often write the .0
at numbers without fractional digits if i want have a result as floating-point number .
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Apr 2013 11:44
Getting a grid coordinate from the mouse for a tile-based map, which getPointerX() returns a float(why I have absolutely no idea) and agk has no int command.

It's not a huge issue but just wanted to bring it to attention.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Apr 2013 13:01
you can use
x= getPointerX()
then x is int
pointer use float because 0-100%.
i missing float(x) and int(x#) too.

for a grid i use this:
x#=getpointerx()
y#=getpointery()
x1=Grid(x#,10.0)
y1=Grid(y#,10.0)
setspriteposition(sprite,x1,y1)

function Grid(v#,grid#)

v#=floor(v#/grid#)*grid#

endfunction v#

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Apr 2013 13:08
Quote: "In math 0.5 is always rounded up to 1."

'In math'? One convention is to do that. Another convention is to not to, so that statement isn't really true in general. Casting to an int usually floors the number though.


"I <3 u 2 bbz" - Dark Frager
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Apr 2013 13:54
At least in all my math classes you round up 0.5. That is what is considered normal rounding. Otherwise you specify as round up or down.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 21st Apr 2013 19:16
In straight C++ math, the result of (float)17.50/(int)32 stored in an int variable is zero.

I have never run into a case where int = float/int would round either way. It has always truncated (and I've counted on that in many languages for certain things).

So, assuming the code is storing the value in an integer variable, then Phaelax has come up with a bug.

Phaelax, can you show the exact code that you are using for this bit of calculation?

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Apr 2013 21:55
Quote: "At least in all my math classes you round up 0.5. That is what is considered normal rounding. Otherwise you specify as round up or down."

You have weird math classes then my friend.

Quote: "Phaelax, can you show the exact code that you are using for this bit of calculation?"




It's nothing I need in my final program anyway, just had it temporarily to verify some things.


Quote: "pointer use float because 0-100%."

Not for me it doesn't return 0-100. It returns the pixel coordinate on screen just as DB's mousex() would, except this makes it a float some dumb reason. They must've updated the file help between 1.7 and 1.8(I just updated to the beta) Because before, the help file said even though it returns a float it's guaranteed to be a whole number.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 21st Apr 2013 22:47
Quote: "pointer use float because 0-100%."

This is meant to relate to using the percentage system instead of the virtual system.

Assuming you haven't specifically defined zx or _ZoneX as floats, your code should be returning zero for 17.5/32.

This appears to definitely be a bug. Go ahead and report it on the Google Issues page.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 21st Apr 2013 23:34
I would like to point you to this article on Wikipedia on rounding. In Sweden we round values often as we no longer have coins smaller than 1, but prices may still use 2 decimals. I believe thats how DBP does it too. However, as can be found towards the end of the article, it says that most programming languages still truncates by default.

http://en.wikipedia.org/wiki/Rounding#Types_of_rounding

Quote: "The following tie-breaking rule, called round half up (or round half towards plus infinity), is widely used in many disciplines. That is, half-way values y are always rounded up."



The get pointer commands should use floats because you want floats for all coordinates for smooth movement. Using integer values gives choppy movements.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Apr 2013 00:01
Bug posted.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 22nd Apr 2013 00:13
Every math class I've ever heard of teaches to round 0.5 up to 1.
I have a BS in Mathematics and an AAS in Chemistry.
I also worked in banking for 7 years and GAAP accounting standards are to round up at 0.5.

Everyone but someone following IEEE standards will follow these rules. IEEE says to round to the nearest EVEN integer. I don't really know the reason they did this, but I imagine it is to reduce the number of repeating decimals in computations... then again IEEE was founded in the US where we still refuse to use the metric system...

Check out dFenz on Google Play, Windows, or Mac:
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Apr 2013 01:19
Under what circumstances is the rounding 'supposed' to be done?

Through all of my college (BS in CS) classes (math, programming, astronomy, whatever), I have never seen where int=float/int does anything but truncate. At least, that is what I remember.

I know in languages like Perl,Javascript and PHP, it is necessary to explicitly use a truncation or rounding function to get an integer value from an apparent float divided by an apparent integer. These languages don't have proper variable type definition for numeric variables.

For AppGameKit Basic the variables all have either a default type (based on the name) or an explicit type. So, rounding in this case doesn't make sense to me.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 22nd Apr 2013 02:25
In chemistry and physics we would truncate, but the last decimal may round up.
i.e. 3.14159265 to four decimal places would be 3.1416
We would always round when truncating a number as it attempts to provide the most accurate representation of the original number.

Rounding in this case (17.0/32) doesn't really make sense to me either. I would have expected 0. I thought that division of anything by an integer stored in an integer always gave the floor of the number (i.e. if n < 1 then n = 0). I would also, as you say, expect simple truncation.

AGK 10811 is indeed rounding int = float/int ; int = int / float ; and int = float / float

However, I get the same results in 1076, so it seems like this may be intentional.
I don't like these results though, AppGameKit should stick to conventional programming standards. Same with arrays being one element larger than expected...

Check out dFenz on Google Play, Windows, or Mac:
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Apr 2013 02:30
Quote: "Through all of my college (BS in CS) classes (math, programming, astronomy, whatever), I have never seen where int=float/int does anything but truncate. At least, that is what I remember."

Same here.

Quote: "I also worked in banking for 7 years and GAAP accounting standards are to round up at 0.5."

That is completely different. You're dealing with money, we're talking about computers. Rounding is solely dependent upon the application the math is being used for.

Quote: "AGK should stick to conventional programming standards"

Which is to truncate!

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Apr 2013 05:39
Quote: "Same with arrays being one element larger than expected..."

Yup, that one bugs me as well. Either be one based or zero based, not both at the same time.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 23rd Apr 2013 16:14
Now that it is a core part of the engine we are stuck with rounding up at 0.5. If you need a specific form of rounding you can use the commands Round(), Floor(), Ceil(), or Trunc()
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Apr 2013 16:53
Oh well. I guess you an update the google issue as a "won't fix".

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-11-24 11:36:37
Your offset time is: 2024-11-24 11:36:37