ryanbarr / harvest-monster

A tool to help you sell Path of Exile Harvest crafts on The Forbidden Trove.
https://www.harvestmonster.com
GNU General Public License v3.0
10 stars 1 forks source link

Floating point issues causing incorrect sorts, formatted values, and sums. #15

Closed ryanbarr closed 2 years ago

ryanbarr commented 2 years ago

Describe the bug Due to floating point precision in JavaScript being less-than-ideal, there are a number of cases where converting to the exalt value and from the exalt value back to chaos is causing inconsistencies.

  1. When parsing craft values from exalt to chaos, then back to exalt, it's possible to add or lose a chaos because of lost "precision". For example, 0.059ex is 10.679c and 0.05ex is 9.05c and the expected chaos value from TFT is 10c. Deciding how to get there is tricky without a significant sample of test data and given the prices are fluctuating finding good sample data is tricky.
  2. When totaling the value of a crafting inventory, multiplying the quantity (n) of a craft by its exalt price results in a n degree of separation from the actual value. Take the same example from above: multiplying 0.059 for the price of a resist change craft by a quantity of 3 results in 0.177ex, or 33c (ceiling) when the actual sum should be 30c as each craft should be 10c. However, if you use the standard tricks to get the precision by doing (parseInt(0.059 * 100) * quantity) / 100 * price you end up with 27c.

To Reproduce Steps to reproduce the behavior:

  1. All current values showcase this issue.

Expected behavior Prices should be always accurate to their total chaos value.

Screenshots N/A

Additional context Moving to chaos prices for everything and using division and modulus to determine exalt values and remainders leaves us in a position where no floats are required.

ryanbarr commented 2 years ago

Resolved with 42bcd0c