Is it a bug? Simple math with weird result. c3p provided

0 favourites
  • 8 posts
From the Asset Store
Match same tiles with each other as fast as you can and earn more score during a limited time!
  • Hi, the problem is simple. As you can see below, that is weird and it's giving me even more weird results in my main project. Am I high? c3p: drive.google.com/file/d/11S2bQsb0jEzPCe77zoOTxEuunbJJlR-V/view

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This has been discussed many times before. Computers can't represent floating point numbers accurately - it doesn't matter how "simple" they may seem.

    en.wikipedia.org/wiki/Floating-point_arithmetic

    If you don't actually need floating point, try to keep your numbers as integers, and scale them to floating point at the last moment when really needed. (That is, multiply by 10 initially, and divide by 10 latter, for example).

  • This has been discussed many times before. Computers can't represent floating point numbers accurately - it doesn't matter how "simple" they may seem.

    https://en.wikipedia.org/wiki/Floating-point_arithmetic

    If you don't actually need floating point, try to keep your numbers as integers, and scale them to floating point at the last moment when really needed. (That is, multiply by 10 initially, and divide by 10 latter, for example).

    So I need to scale them to integer before calculation? Would be ok to store them as floating numbers?

  • I couldn't open your file to see what you are doing, but I'd keep things at integers as long as I could.

  • I couldn't open your file to see what you are doing, but I'd keep things at integers as long as I could.

    Thanks. I've scaled up all my data to integers and I'm only using floating numbers in the calculations. I just don't know the best approach to this problem if we face a scenario where we just can't avoid them. Because, if we store them, for instance 0.6, and multiply by 10, the result would be 6.000000000000001. For that we can use floor but would need to count the decimals to know if it's 10, 100, etc . That's too much work for simple calculations, which brings me the question: do you know what's the most common approach for this situation?

  • Multiplying by 10 won't introduce an error. Multiplying, doing floor, and dividing again is how you deal with this. You have to pick how many significate digits you want.

  • I think the editor is set to stop at 16.

  • Thanks for the explanation.

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