-
This is potentially related to #2608. I have the following configuration: {
number: "BigNumber",
precision: 60 + 18 + 2,
epsilon: 1e-80,
} I am then trying to run const x = math.bignumber!("115792089237316195423570985008687907853269984665640564039457584007913129639935");
const y = math.bignumber!("0.000000000000000001");
const result = math.sqrt!(x.mul(y)); This produces the result But, as per the result I get on Wolfram, I was expecting the result to be Why is the result not rounded up, and how can I make it be so? Note: this started to happen after I upgraded |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Executing your expression, I get:
Which is indeed the correct answer but contains a rounding error. The You can use math.config({precision: 60+18+2})
const x = math.bignumber("115792089237316195423570985008687907853269984665640564039457.584007913129639935")
const y = math.bignumber("0.000000000000000001")
const result = math.sqrt(x.mul(y))
// "340282366920938463463.37460743176821145599999999999999999999999999999999999999853"
const decimals = 18
const roundedResult = math.round(result, decimals)
// "340282366920938463463.374607431768211456" |
Beta Was this translation helpful? Give feedback.
Executing your expression, I get:
Which is indeed the correct answer but contains a rounding error.
The
BigNumber
data type (powered by Decimal.js) has a higher precision but is still a floating point number type, and hence can have round-off errors.You can use
math.format
ormath.round
to round the result if you want to get rid of the round-off errors: