Skip to content
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, simplify, and exactFractions don't interoperate well #2816

Open
nycos62 opened this issue Oct 16, 2022 · 4 comments
Open

BigNumber, simplify, and exactFractions don't interoperate well #2816

nycos62 opened this issue Oct 16, 2022 · 4 comments
Labels
dependencies Pull requests that update a dependency file, or issues that lie primarily in a dependency feature

Comments

@nycos62
Copy link

nycos62 commented Oct 16, 2022

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

@josdejong
Copy link
Owner

math.js uses the Fraction.js library to work with fractions. This library only supports numbers. It has no support for BigNumbers. It would be nice if it could support BigNumbers though :).

If anyone is interested in looking into support for Fractions+Bignumbers please let me know.

@nycos62
Copy link
Author

nycos62 commented Oct 19, 2022

did you see there is a BigFraction type ? max int => BigInt(9007199254740991);

I don't know how to handle bigNumbers into Fractions.js because the type BigNumbers is not included in Fraction.js package :(
https://github.com/infusion/Fraction.js/blob/master/bigfraction.js

@josdejong
Copy link
Owner

Ah, maybe I've seen it in the past but I didn't remember at least. That is a very interesting idea! I guess we first have to implement support for BigInt and then can implement utilizing that with BigFraction.

See the discussion about BigInt: #2737

@nycos62
Copy link
Author

nycos62 commented Oct 20, 2022

I guess we should work hard to turn basic Number type of math.js into infinite integers as in pyhton. you declare any integer, you don't care of the length/type of integer, it handle it. You could also, by the way, use simplify to turn every floating number into almost infinite integer fractions depending on your device settings.

@gwhitney gwhitney changed the title can't use simplify with exactFractions, don't know why BigNumber, simplify, and exactFractions don't interoperate well Oct 3, 2023
@gwhitney gwhitney added feature dependencies Pull requests that update a dependency file, or issues that lie primarily in a dependency labels Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file, or issues that lie primarily in a dependency feature
Projects
None yet
Development

No branches or pull requests

3 participants