mirror of
https://github.com/Baidicoot/rpncalc-v4
synced 2024-12-11 18:50:26 +00:00
suffering
This commit is contained in:
parent
c3c39b1fff
commit
a8ec29c216
@ -81,6 +81,13 @@ const addDefn = (name, args, fn) => {
|
||||
}
|
||||
}
|
||||
|
||||
const addConst = (name, typ, val) => {
|
||||
defnOp(name, [{type:typ, val:val}])
|
||||
}
|
||||
|
||||
const unary = (fn, outty) => (args) => [{type:outty, val:fn(args[0])}]
|
||||
const binary = (fn, outty) => (args) => [{type:outty, val:fn(args[0], args[1])}]
|
||||
|
||||
const add = (args) => [{type:"num", val:args[0] + args[1]}];
|
||||
const sub = (args) => [{type:"num", val:args[0] - args[1]}];
|
||||
const div = (args) => [{type:"num", val:args[0] / args[1]}];
|
||||
@ -103,11 +110,23 @@ const eq = (args) => {
|
||||
}
|
||||
}
|
||||
|
||||
const coerce = (args) => [{type:args[1].val, val:args[0].val}]
|
||||
|
||||
addConst("pi", "num", Math.PI);
|
||||
addConst("e", "num", Math.E);
|
||||
addDefn("+", ["num", "num"], add);
|
||||
addDefn("-", ["num", "num"], sub);
|
||||
addDefn("/", ["num", "num"], div);
|
||||
addDefn("*", ["num", "num"], mult);
|
||||
addDefn("^", ["num", "num"], pow);
|
||||
addDefn("sin", ["num"], unary(Math.sin, "num"));
|
||||
addDefn("cos", ["num"], unary(Math.cos, "num"));
|
||||
addDefn("tan", ["num"], unary(Math.tan, "num"));
|
||||
addDefn("asin", ["num"], unary(Math.asin, "num"));
|
||||
addDefn("acos", ["num"], unary(Math.acos, "num"));
|
||||
addDefn("atan", ["num"], unary(Math.atan, "num"));
|
||||
addDefn("ln", ["num"], unary(Math.log, "num"));
|
||||
addDefn("coerce", 2, coerce)
|
||||
addDefn("sqrt", ["num"], root);
|
||||
addDefn("==", 4, eq);
|
||||
addDefn("pair", 2, pair);
|
||||
|
@ -98,11 +98,13 @@ stepb.onclick = _ => {
|
||||
if (!(pos.start === 0 && pos.end === 0)) {
|
||||
insbox.innerHTML = highlight(input, pos.start, pos.end, "green");
|
||||
}
|
||||
/*
|
||||
if (state.stacks.length > 1) {
|
||||
outbox.innerHTML = "... " + prettyprint(state.stacks[state.stacks.length-1]);
|
||||
} else {
|
||||
outbox.innerHTML = prettyprint(state.stacks[0]);
|
||||
}
|
||||
}*/
|
||||
outbox.innerHTML = state.stacks.map(prettyprint).join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user