Modulo evaluating incorrectly

0 favourites
  • 4 posts
  • Link to .capx file (required!):

    I'm not allowed to post links so I will try breaking the link up so it is not recognized.

    https://

    docs.google.com/file/d/0B1keSNvq9c4JZ3VYVFJTZlU4WUE/edit?usp=sharing

    Steps to reproduce:

    1. run project in debug mode

    2. notice that module expression (which outputs to the modulo variable every tick) evaluates incorrectly.

    Observed result:

    416%(32/5) evaluates to 6.4

    Expected result:

    416%(32/5) evaluates to 0

    Browsers affected:

    Chrome: yes

    Firefox: yes

    Internet Explorer: yes

    Operating system & service pack:

    Windows 7 Ultimate 64-bit SP1

    Construct 2 version:

    Release 146 (64-bit/Steam)

  • More information/context is available in /topic78529 in case it is helpful.

  • The expression is constant so is actually evaluated by the editor at preview/export time.

    The editor (like the Javascript engine probably also does) uses double-precision floats for calculations. In this case the expression 32 / 5 evaluates not to 6.4, but to 6.4000000000000004. This is a normal result in computers: they do not perform calculations to infinite precision, and small rounding errors usually occur. It then calculates 416 % 6.4000000000000004 which is 6.3999999999999773. Somehow this gets rounded to 6.4 during export or display, which is unfortunate, but again not unexpected due to the fairly imprecise nature of floating point numbers in computers.

    So, closing as won't fix - you can't ever expect floating point calculations to be exactly precise in computers, using any framework or language on any system. You need to make sure you build in tolerances.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Ashley. Still learning, sorry for taking up your time.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)