From 148f94e2c539202b063c98cc175377f445f48c43 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 2 Feb 2022 22:30:09 -0500 Subject: =?UTF-8?q?Check=20number=20of=20arguments=20for=20=E2=80=A2math?= =?UTF-8?q?=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bqn.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/bqn.js b/docs/bqn.js index edac15b5..8e6d6398 100644 --- a/docs/bqn.js +++ b/docs/bqn.js @@ -599,10 +599,16 @@ let primitives = dynsys(state => { return list(gl.map((g,i) => list([g,rt[i]]))); }); +let mathfn = f => { + f.prim=null; let p=runtime[61](f,0); // ⚇ + return f!==Math.atan2 && f!==Math.hypot + ? ((x,w) => {if ( has(w)) throw Error("Left argument not allowed"); return p(x);}) + : ((x,w) => {if (!has(w)) throw Error("Left argument required"); return p(x,w);}); +} let trig = "cos cosh sin sinh tan tanh".split(" "); let mathns = obj2ns(Math, trig.concat(trig.map(n=>"a"+n),"LN10 LN2 LOG10E LOG2E cbrt expm1 hypot log10 log1p log2 round trunc atan2".split(" ")), - f=>typeof f==="function"?(f.prim=null,runtime[61](f,0)):f + f=>typeof f==="function"?mathfn(f):f ); trig.map((_,i)=>{let f=mathns[i],g=mathns[i+trig.length]; f.inverse=g; g.inverse=f;}); -- cgit v1.2.3