Implicit conversion between Fraction or BigNumber #2587
Unanswered
chrisbansart
asked this question in
Q&A
Replies: 1 comment 2 replies
-
It could be related to the matrix implementations using separate functions for element wise operations: |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I try to extend arithmetic operations with custom behaviors. Thanks to typed functions, I can set a default behavior for types operations. For instance, in the code below, I've chosen to convert into Fraction all operations that mix Fractions and bignumbers.
That works great and it prevents "exception : Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction."
Thus :
math.multiply(math.fraction(1/2),math.bignumber(3.0)) // gives Object { s: 1, n: 3, d: 2 } which is a Fraction
My code
Nevertheless I've faced more complicated cases where I'd like to apply this kind of conversions btw a Matrix containing fraction or bignumber with a scalar fraction or bignumber
In this case :
math.multiply([math.fraction(1,2),5],math.bignumber(1)) // raises error "TypeError: Cannot implicitly convert a Fraction to BigNumber or vice versa. Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction."
But math.multiply([math.fraction(1,2),2],1) works well
I imagine that my new type definitions don't apply element-wise in a matrix? but why ?
Any help would be greatly appreciated
Chris
Beta Was this translation helpful? Give feedback.
All reactions