VikeStep / Clicker-Heroes-Calculator

Simple Clicker Heroes Calculator for determining the best next purchase
6 stars 7 forks source link

Integer Precision #1

Open VikeStep opened 10 years ago

VikeStep commented 10 years ago

When dealing with integers/decimals of more than 16 digits the remaining numbers are rounded off. For example the Base DPS for Frostleaf is: 74,698,063,240,394,348,429,312 however it comes out as 7.469806324039436e+22

Possible Solutions

  1. Convert all integers into base64 and then into strings and use a library that can add, subtract, divide and multiply base64 numbers. Converting Frostleaf's DPS into base64 becomes: P0WPfDdZ5gAAA
  2. Work around it and leave it as is (may encounter small issues later for example precision errors caused issues in the original Excel Spreadsheet with Critical Click DPS)
  3. Use some other library that can handle big integers. (e.g. http://www-cs-students.stanford.edu/~tjw/jsbn/)
LMLB commented 9 years ago

I just want to note that numbers in Flash are the same kind of floating point numbers as the ones in javascript, and the game uses the regular flash numbers. It's just that calculating the same thing in different ways can lead to different results, e.g. 1e+30 - 1e+30 + 1 is 1 but 1 + 1e+30 - 1e+30 is 0.