100
100 copied to clipboard
Wrongly translated expressions in 005
In 005: When translating expressions, when a number is divided by a number greater than 10, the result of the operation is not as expected.
Reproduction
(t, r, th) => sin(t / 10)
got black results. I think it was translated to sin(t / 1 * 0)
.
My thoughts
- Wrong in regExp replacement method.
/(\d+)(\w+)/g
should be modified to/(\d+)([a-zA-Z]+)/g
; - I'm not sure if
1/3t
should be translated as(1/3)*t
or1/(3*t)
, the current translation results in the former. If it should be the latter, the correct method should beexp.replace(/(\d+\.?\d?)([a-zA-Z]+)/g, (_, n, x) => `(${n} * ${x})`)
(use brackets to enclose the result, and let number part matches float numbers) - Another problem is that I can't type
3tr
to represent3*t*r
, only get3*tr
and then got an error.