Closed gitKad closed 2 years ago
Thanks for bringing this up.
This is quite funny. Currently, there is no relation defined in math.js to convert Fractions to BigNumbers or vice versa, since it's ambiguous whether you would like to convert to one or the other. But the internally used typed-function
is so clever that it found a conversion that is defined for both: namely converting both to a Complex number :D. Not really the intention.
To solve this, we have the following options:
I think option 1 (convert to BigNumber) would be the best default choice. If you want to have a Fraction as output, you can do so by first converting all arguments to Fractions.
EDIT: there is an option 4, making this behavior configurable
I need more information about how mathjs behave before I can share which options makes more sense for my use case. Would the bignumber type be able to convert to exact fractions involving large numbers numerators or denominators?
Either way, wouldn't the following be a fourth acceptable option?
It indeed depends on the use case what's desired behavior.
math.divide(math.bignumber(num), math.bignumber(den))
. You lose your exact representation.Both aren't nice solutions, that's why we originally didn't want to choose one or the other and throw an error instead. Maybe option 3 is still the best.
There is another interesting discussion here: https://github.com/josdejong/mathjs/issues/694, which is about being able to have the num/den of a Fraction be represented with a BigNumber, and to be able to use BigNumbers and Fractions as the re/im parts of Complex values and the values of Units.
I updated the title of this issue. I think what we should do here is:
none
(defaul) don't convert from BigNumber to Fraction or vice versa but throw an errorbignumber
: convert Fractions to BigNumbersfraction
: convert BigNumbers to Fractions
I can't multiply bignumbers and fractions. Here's a failing test I added to function\arithmetic\multiply.test.js: