math.eval doesn't recognise numbers with infinitely repeating decimals i.e. `0.(3)`
math.eval('66.(3)'); returns 198
That's correct. Fraction.js supports this notation, but the expression parser of math.js can't since it conflicts with implicit multiplication.
There is one way to create a Fraction with inifitely repeating decimals, by passing a string to the fraction factory function:
math.fraction('66.(3)')
math.eval('fraction("66.(3)")')
[...] since it conflicts with implicit multiplication
Could we make this possible with the quoted notation?
Math.evaluate("5.'3'") // = 16/3
Math.evaluate("5.'3' ^ 3") // = 4096/27
Thanks for your suggestion Clément. I think that is technically possible, but I doubt if it would help since this is not a common notation (as far as I know).
Thinking about this more, we could consider changing the parser such that it does accept math.eval('66.(3)') as a repeating decimal notation. It is a bit odd to interpret this as an implicit multiplication (the current behavior), since the dot in 66. is meaningless and someone would just enter math.eval('66(3)') instead when wanting to do an implicit multiplication. We would have to think though if it doesn't conflict with other things, but I think it could work.
Anyone interested in working this out in a PR?
this only works if the parenthesis is placed directly after the point
For example 66.2(3) is 66.2 × 3 or 66.23333... ?
but I doubt if it would help since this is not a common notation
The common notation is to add a line over the repeated part, I think that's what the quoted notation try to simulate.
https://en.wikipedia.org/wiki/Repeating_decimal#Notation
this only works if the parenthesis is placed directly after the point
For example
66.2(3)is 66.2 × 3 or 66.23333... ?
argh, you're right, I hadn't thought about that 🤔
We can perhaps consider that if we have something of the form /\d*\.\d*\(\d+\)/ (like 12.34(65)) then it is a decimal repetition.
It would be curious to want to do 12.34 × (56) with parenthesis and implicit multiplication.
That is a good point. So the parsed number should only match digits inside the parenthesis, like 12.34(65), and not something like 12.34(2 + x). I think that can work. It is another special rule around implicit multiplication, but it makes sense I htink.
This examples should be parsed as decimal repetition
12.34(7) => 12.347777…
12.(7) => 12.7777…
.12(7) => 0.127777…
.(7) => 0.7777…
This examples should be parsed as implicit multiplication
1234(7) => 1234 × 7
12.34(7.6) => 12.34 × 7.6
Not sure for this example:
1.2(3)4 => ???
1.2(3)pi => ???
Good, clear summary 👌 .
We can discuss about 1.2(3)4 and 1.2(3)pi: either throw an error or parse the last part as an implicit multiplication. My initial feeling is: the first example 1.2(3)4 simply looks confusing, so maybe best to not allow it and throw an error. The second one doesn't look very odd to me, we could allow that and parse it as 12.3444444... × pi. What do you think?
When implementing this, we should recon the different numeric types that we have: number, BigNumber, and Fraction (which does already have support for this notation in it's constructor function).
What do you think?
I agree, we can't put an implicit multiplication between two numbers, it is like considering that 34 would be equal to 3 × 4.
On the other hand 3pi is unambiguously equal to 3 × pi