StractOrg / stract

web search done right

Home Page:https://stract.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support '%' as modulo operator in calculator

Ashvith10 opened this issue · comments

When I try calculating 100 % 12, I get 13 as the answer.

Screen Shot 2024-04-05 at 21 15 46

I did not look into the code, but it seems as if x%y is interpreted as (x/100)+y and not as modulo. For modulo one would need x mod y.

Note that we are using fend for evaluating everything in the calculator.

Yea it seems that fend always treats % as a unit. They have an open issue to also support it as a module operator, but it seems that it might not be trivial to implement in their parser (printfn/fend#265).

I kinda want to label this as a bug as I agree this is not what the user expects. I don't know exactly how we should fix it though. I think we could either (in order of ascending difficulty and flexibility):

  1. Hot fix: replace all ([\d]+) *% *([\d]+) with $1 mod $2.
  2. It seems that the maintainer of fend wants this as well, so we might be able to fix it in their parser and upstream it.
  3. Write our own calculator.

Hello, fend maintainer here! I've implemented a fix for this in v1.4.8.

Awesome! Thanks for the heads up