big number calculation #2377
-
Hi! I have tried: the answer should be 30 but I got 0 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Please read the docs on how to use bignumbers. In your example you're creating a regular number |
Beta Was this translation helpful? Give feedback.
-
ok that was a bit difficult but I got the success:
|
Beta Was this translation helpful? Give feedback.
-
So why this example doesn't work?
|
Beta Was this translation helpful? Give feedback.
-
You're first creating a number, and then turning the number into a BigNumber. But by then you've already lost you're precision. You can do import { create, all } from 'mathjs'
const math = create(all)
let x = math.bignumber('6277101735386680764176071790128604881410404459395608870912')
let result = math.bitAnd(math.rightArithShift(x, 16), 2 ** 16 - 1)
console.log(result.toString()) // 30 or import { create, all } from 'mathjs'
const math = create(all, { number: 'BigNumber'})
const result = math.evaluate('(6277101735386680764176071790128604881410404459395608870912 >> 16) & (2 ^ 16 - 1)')
console.log(result.toString()) // 30 or create a |
Beta Was this translation helpful? Give feedback.
ok that was a bit difficult but I got the success: