0 Favourites

Construct has sporadic issues dividing?

This forum is currently in read-only mode.
  • 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?

  • I forgot to add it DOES happen to my other testers with versions compiled on my computer.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

  • This was an extremely helpful answer but it was also not the answer I wanted.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
0 Favourites
Construct 3 any news?
889 125,562
uzumiapps's avatar
Unread hot topic
353 32,065
yojona's avatar
Unread hot topic
300 118,413
blackhornet's avatar