Re:Show HN: I made a web-based notepad with a built in unit ...
by brospars on Wednesday August 17, 2022 @06:05AM
(#32494296)
There is something wrong with the order of operations. When I type 2+2*2-6 i get -6 which should be 0.
[ Parent
| on HN ]
Re:Show HN: I made a web-based notepad with a built in unit ...
by sneak on Wednesday August 17, 2022 @06:08AM
(#32494313)
I would think this might be the first unit test one would write for a calculator program.
Re:Show HN: I made a web-based notepad with a built in unit ...
by simonz05 on Wednesday August 17, 2022 @07:27AM
(#32494791)
Yep, this should be evaluated as `(- (+ 2 (* 2 2)) 6)`
Re:Show HN: I made a web-based notepad with a built in unit ...
by unsafecast on Wednesday August 17, 2022 @06:07AM
(#32494308)
It looks like APL order? Right-to-left.
Re:Show HN: I made a web-based notepad with a built in unit ...
by JackFr on Wednesday August 17, 2022 @10:35PM
(#32504576)
No. It’s not right to left. It’s just weird:
3 ^ 1 * 2 6
3 ^ 1 / 2 1.73205
3 ^ 1 + 2 5
3 ^ 1 - 2 1
Re:Show HN: I made a web-based notepad with a built in unit ...
by unsafecast on Thursday August 18, 2022 @09:40AM
(#32509427)
Huh.
Re:Show HN: I made a web-based notepad with a built in unit ...
by bdwjn on Wednesday August 17, 2022 @06:11AM
(#32494333)
Oh there's more:
9 - 3 ^ 2 = 0
9 -3 ^ 2 = 18 ???
pi = 3.1415926536
2 pi = 5.1415926536 ???
sin(3.1415926536 radians) = -0
sin(pi radians) = Incompatible units ???
Re:Show HN: I made a web-based notepad with a built in unit ...
by wizofaus on Wednesday August 17, 2022 @06:12AM
(#32494342)
Seems to assume + if an arithmetic operator is missing?
Re:Show HN: I made a web-based notepad with a built in unit ...
by tonyonodi on Wednesday August 17, 2022 @06:30AM
(#32494443)
This is correct, the idea is that you can type things like "6 foot 3 inches" and have it evaluate as an addition. But the example shown above is definitely a problem, I'll try to think of a work around.
Re:Show HN: I made a web-based notepad with a built in unit ...
by wizofaus on Wednesday August 17, 2022 @07:26AM
(#32494778)
I'd think that rule only makes sense after a symbol representing a unit (including potentially 6'3"). Certainly <number> <named constant> should logically assume multiplication.