guipn/sinful.js

Incorrect results of correctedValue() if product of arguments are too big

Closed this issue · 1 comments

evanp commented

If the product of val and corrFactor is big enough to be represented in exponential notation, the result will be a single-digit integer.

correctedValue(2.3, 1000) will give the correct value, 2300. correctedValue(2.3, 1e21) will give the incorrect value 2. This is because the product 2.3e21 is converted to a string and then passed to parseInt, which will stop at the first non-digit character, so return 2.

This can be fixed by using Math.round instead of parseInt().

evanp commented

Whoops! Wrong project. I should have noted this on chipincode/sinful-math.