josdejong / josdejong/mathjs

BigNumber, simplify, and exactFractions don't interoperate well

Open
#2,816 4 comments 0 reactions 0 assignees View on GitHub
dependencies feature
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Hello,

is there any chance to use bigNumbers and simplify ?

my config is this :
```
math.config({
number: 'BigNumber', // Default type of number:
// 'number' (default), 'BigNumber', or 'Fraction'
precision: 509 // Number of significant digits for BigNumbers
})
```

```
const f = math.parse('2/3+3');
const simplified = math.simplify(f,{},{exactFractions:true});
console.log(simplified.toString());
```
I get :
`3.6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667`

the correct answer should be :
`11 / 3`

if I use this config, I loose my precious bigNumbers and fall on number format which I want to avoid
```
math.config({
number: 'number', // Default type of number:
// 'number' (default), 'BigNumber', or 'Fraction'
precision: 509 // Number of significant digits for BigNumbers
})
math.simplify('(3/2)^20').toString()
'3.486784401e+9 / 1.048576e+6'
```

If only I could get this format with bigNumbers :'(
```
math.simplify('(3/2)^20').toString()
'3486784401 / 1048576'
```

Am I missing something ? I haven't found any details in the documentation about simplify with bigNumbers

Kind regards,
Nicolas

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.