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 / Has anyone seen this bug or i am doing something wrong ?

Author
Message
Abhishek
11
Years of Service
User Offline
Joined: 17th Aug 2013
Location:
Posted: 11th Feb 2015 03:02
F as Float
F = 10/3

do
Print(F)
Sync()
loop


Output

3.00000000000000

instead of

3.3333333333333333333333333333333


HUH?!?! What and how ??!
unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 11th Feb 2015 03:15 Edited at: 11th Feb 2015 03:22
Try putting a .0 on the end of one of the literals to force floating point math... It's not a bug.

Consider:
F as float
Ten as float = 10
TenInt as integer = 10

F = Ten/3 // F = 3.3333
F = TenInt/3 // F = 3.0

A literal has a primitive type as well.

Using AppGameKit v2 T1 + T2
Systems: Primary: Mac OS X 10.10
Secondary: Windows 7
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 11th Feb 2015 08:34
Yes - basically AGK2 has "vague" expression typing with respect to integers and floats. If all the values in an expression are integers it will calculate it as an integer. If any are floats it will do it as a float. 10 and 3, being integers,means the result is 3.

AGK does not take note of the destination of the expression. If the result of the expression is an integer, it will cast it to a float if the destination is a float (hence printing 3.00000 - if you print(10/3) you'll get 3).

If it's a float, it casts it to an integer, this provides an int() functionality. (You could make a good case you should have an int() anyway).

This also applies to function parameters, you can SetSprite(1.2,3) for example (and it means 1), same with user functions. You could make a case this should generate a compiler warning (loss of data)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 11th Feb 2015 11:52 Edited at: 11th Feb 2015 11:54
automatic data-type conversion is sometimes good sometimes not.
i think its better if the interpreter add this to the code so you can
see what the app will do.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
MikeHart
AGK Bronze Backer
21
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 11th Feb 2015 11:59
Welcome to the world of weak/non typed programming languages.

-----------------------------------------------------------
Using AGK2 Tier 1
unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 11th Feb 2015 15:45
Quote: "Welcome to the world of weak/non typed programming languages. "

It doesn't really have anything to do with that, necessarily. Languages such as C/++ and Java do the same. You have to specify the type of a literal using something like "f" or a decimal point if you want floating point math. It's just that AppGameKit T1 does not have a literal type specifier like "f".

Using AppGameKit v2 T1 + T2
Systems: Primary: Mac OS X 10.10
Secondary: Windows 7
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 11th Feb 2015 16:11 Edited at: 11th Feb 2015 16:34
This is interesting.
This would have stumped me too.
Not sure why it hasn't before.

Quote: "Yes - basically AGK2 has "vague" expression typing with respect to integers and floats. If all the values in an expression are integers it will calculate it as an integer. If any are floats it will do it as a float. 10 and 3, being integers,means the result is 3.

AGK does not take note of the destination of the expression. If the result of the expression is an integer, it will cast it to a float if the destination is a float (hence printing 3.00000 - if you print(10/3) you'll get 3).

If it's a float, it casts it to an integer, this provides an int() functionality. (You could make a good case you should have an int() anyway).

This also applies to function parameters, you can SetSprite(1.2,3) for example (and it means 1), same with user functions. You could make a case this should generate a compiler warning (loss of data) "

Good to know,
Thanks


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

Login to post a reply

Server time is: 2024-11-25 16:26:01
Your offset time is: 2024-11-25 16:26:01