Incorrect evaluation of mixed fractions
Roman-Kerimov opened this issue · 5 comments
For example, "2½".evaluate() returns 1 instead of 2.5
Ah... yes, because it's parsing the 2
, and then the ½
... it sees them as separate tokens, and assumes they're an implicit multiplication.
But I agree that's not ideal. :)
ok, I've got a rudimentary fix in place, but this has actually highlighted a deeper problem with DDMathParser's token resolution.
The current fix is to inject a +
operator in between a number and a fraction, however that will break evaluation for things like 2½ * 2
, because:
- it becomes
2 + ½ * 2
- which becomes
2 + (½ * 2)
- which becomes
2 + 1
- which becomes
3
I'm thinking I'll need to change how resolution is done in order to fully solve this.
I think that this problem can be solved by adding a special addition operator with the highest priority.
@Roman-Kerimov you're right, that's probably a simpler fix than what I was thinking. The fix has been pushed to master
. Thanks!