prefix notation and () on newRPL project
|
12-23-2022, 02:59 AM
(This post was last modified: 12-25-2022 06:12 PM by Albert Chan.)
Post: #10
|
|||
|
|||
RE: prefix notation and () on newRPL project
(12-23-2022 12:02 AM)Albert Chan Wrote: How to distinguish subtraction from negation Patched above (op +/-) logic to calc macro (previous post) Also, unary +/- precedence placed below POW, above MUL/DIV, similar to Python/Lua Before: Code: ((+ -) (if (null? (cdr e)) After: Code: ((+ -) (if (null? (cdr e)) Test with calc-expand macro (previous post) scheme> (calc-expand '(2 ^ - 3 ^ 4)) ; op +/- tests (^ 2 (- (^ 3 4))) scheme> (calc-expand '(2 * - 3 / 4)) (/ (* 2 (- 3)) 4) scheme> (calc-expand '(- 2 ^ 3 ^ 4)) ; unary +/- precedence below POW (- (^ 2 (^ 3 4))) scheme> (calc-expand '(- 2 * 3 / 4 )) ; unary +/- precedence above MUL/DIV (/ (* (- 2) 3) 4) And, for Mach number test. Spaces are needed to separate the tokens. scheme> (sqrt (calc 5 *(((((1 + .2 *(350 / 661.5)^ 2)^ 3.5 - 1)* (1 - 6.875E-6 * 25500)^ - 5.2656)+ 1)^ .286 - 1))) 0.8357245351752515 For comparison, we figured precedence rules, then use rpn macro. scheme> (rpn 350 661.5 / 2 ^ .2 * 1 + 3.5 ^ 1 - 1 6.875E-6 25500 * - -5.2656 ^ * 1 + .286 ^ 1 - 5 * sqrt @) 0.8357245351752515 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)