Getting around the rounding limits of 64bit floating point numbers

0 favourites
  • 6 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • On Start of layout:

    -Loop " " from 0 to 15:

    --Add 9x10^loopindex to variable

    I am getting 10000000000000000 (length is 17) as a result instead of 9999999999999999 (length is 16). I assume it has to do with base but I can't figure out how to get the correct value. I get accurate results if looped less than 16 times though. The expected results should have as many 9s equal to how many times it loops.

    ***edit***

    For my project I don't think many users will be entering more than a 15 digit number. I may just limit how many characters can be entered or I may work around the limit. There will still be a limit if I worked around it but it will be a lot higher than 15 digits.

    Also when I changed the title of the post so it will be more accurate for other people and so others can learn from it too.

    Also a ^ is called a caret symbol.

    ====Edit====

    A solution is in this c3p, at least for multiplication, addition and exponents. I feel most people won't need it though and it will probably be better to use 'Add Script' and BigInt than to manually do it as I did.

    The C3P has a few examples on how to do a few specific things that most people won't need. Be sure to disable all groups except for the one you are looking at.

    dropbox.com/s/1v415k8h85jp2wa/Tutorials.c3p

  • I’d imagine it has to do with how numbers in construct are 64bit floating point numbers that only use at most 15-17 significant digits.

    en.m.wikipedia.org/wiki/Double-precision_floating-point_format

  • Looks complicated

  • It’s just further reading. Anyways the gist is numbers only can have 15-17 significant digits.

    So you’re running into the limit and it’s rounding.

  • I found a workaround, but I'm only going to say it pseudocode for now. It is a bit excessive, but will be accurate if done correctly. Most people won't need this, but a few will. I may post an example at a later time.

    You take your input and have it as a string instead of an integer. You then use mid() and loops to select each individual character in the string. You then make conditions and actions depending on what you want to do with it. You basically do addition, subtraction, multiplication and long division as you learned it in school. This allows you to do addition, subtraction, multiplication and division by using each individual number instead of taking the whole number into consideration at once. This means you will have to use int() and C3 built in math for the small in-range numbers. You then take the individual answers as you get them and set them to a string.

    Basically instead of using the built in math in C3 you're only using it for the in-range numbers(5-8, 1+2...etc). You must keep the variable a string, otherwise it may round. You are teaching your event sheet how to add, subtract, multiply and divide using the same logic that you used when you learned to do them on paper. Which means you may need to watch a video to remember how to do it on paper. I watched a video to check to see if I handled things correctly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ashely told me another way around it.

    "If you use the scripting feature, BigInt is now widely supported for high precision integers."

    I don't know enough about this feature right now. It will be something I have to look at later.

    construct3.ideas.aha.io/ideas/C3-I-1629

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