Construct has sporadic issues dividing?

For questions about using Classic.

Post » Fri Sep 14, 2012 7:29 pm

I'm not sure if this is a bug, or... well, I don't really know. If it's a bug I can repost in on the bug tracker. What's happening is Construct very sporadically stops dividing numbers properly. I'll divide 1 / 100 and get 0.00999999658 or something.

I noticed the problem and found out what was happening one time when I attempted a quick bandaid on an unrelated problem I was having by changing the window resolution during a layout transition. When I did this, Construct ceased to divide properly at all, no matter what. Without me doing this, it works correctly MOST of the time. Otherwise, I've tried really hard to repro or determine the pattern of how/why it stops dividing properly, but no go.

I have no idea, is it Construct? Is it my computer? Anybody have any ideas?
B
1
Posts: 5
Reputation: 235

Post » Fri Sep 14, 2012 7:34 pm

I forgot to add it DOES happen to my other testers with versions compiled on my computer.
B
1
Posts: 5
Reputation: 235

Post » Fri Sep 14, 2012 7:39 pm

They're called rounding errors.

This isn't a problem with construct - it's a problem with how computers are designed. People working with other languages have to deal with it too.

The simple explanation - CPUs don't have enough precision to calculate floats (decimals) exactly right, so you often get results like the one you posted.

You can count integers being exact, like 1+1 equaling 2, but you cannot count on 0.1+0.1 equaling 0.2.

Either don't use conditions that require exact floats, or when checking the variable make it an integer instead, like if a variable is 0.1, use "if round(variable*10)=1" instead.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Sat Sep 15, 2012 10:47 am

This was an extremely helpful answer but it was also not the answer I wanted.
B
1
Posts: 5
Reputation: 235


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest