indutny / bn.js

BigNum in pure javascript
MIT License
1.19k stars 150 forks source link

Incorrect multiplication result when using muln() #281

Closed cryguy closed 3 years ago

cryguy commented 3 years ago

With the following inputs, the muln result is wrong

new BN("400000000000000000000000", 10).muln(0.5).toString(10) // gives "48884270296371539476480"
new BN("320000000000000000000000", 10).muln(0.5).toString(10) // gives "8884270296371539476480"

while doing the same thing but with divn works as expected

new BN("400000000000000000000000", 10).divn(2).toString(10) // gives "200000000000000000000000"
new BN("320000000000000000000000", 10).divn(2).toString(10) // gives "160000000000000000000000"
fanatid commented 3 years ago

Fractional numbers are not supported. Same as https://github.com/indutny/bn.js/issues/276.