-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BigNumber.pow doesn't work for negative numbers #925
Comments
That seems like what is happening in your above example and this is certainly a bug. I’ll address it ASAP. Thanks! |
It seems negative values are not supported, in general, by BN.js, which kind makes sense in the context of a big number library. I think the solution will be throwing in the event there is a negative exponent. Looking more closely at what you are trying to do above, the result you would expect is 0 though. Consider: // BigNumbers do not support fractions, so this would be 0.00000001, which is 0 to a BigNumber
const a = eth.BigNumber.from(10).pow(-8);
// This times 0 is 0
const b = eth.utils.parseEther('1').mul(a); What you more likely want to do is use the parseUnits (or if you wish more control, the FixedNumber class directly): const b = eth.utils.parseUnits("1", 18 - 8).toString();
// "10000000000" |
This has been addressed in 5.0.4. I don't know it will help you the way you want it to, but the |
Closing this now, but if you still have problems, please re-open this issue. Thanks! :) |
Does the function silently use absolute value?
The text was updated successfully, but these errors were encountered: