diff --git a/src/builtins.h b/src/builtins.h index 673edfba..399cd107 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -21,10 +21,11 @@ /*internal.c*/D(eequal,"•internal.EEqual") M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") \ /*internal.c*/A(internalTemp,"•internal.Temp") M(iHasFill,"•internal.HasFill") M(iKeep,"•internal.Keep") \ /*internal.c*/D(variation,"•internal.Variation") A(listVariations,"•internal.ListVariations") M(clearRefs,"•internal.ClearRefs") M(unshare,"•internal.Unshare") \ -/* arithm.c*/M(sin,"•math.Sin") M(cos,"•math.Cos") M(tan,"•math.Tan") M(asin,"•math.Asin") M(acos,"•math.Acos") M(atan,"•math.Atan") D(atan2,"•math.Atan2") D(hypot,"•math.Hypot") \ +/* atithd.c*/D(hypot,"•math.Hypot") D(comb,"•math.Comb") D(gcd,"•math.GCD") D(lcm,"•math.LCM") D(atan2,"•math.Atan2") D(atan2ix,"•math.Atan2⁼") D(atan2iw,"•math.Atan2˜⁼") \ +/* arithm.c*/M(sin,"•math.Sin") M(cos,"•math.Cos") M(tan,"•math.Tan") M(asin,"•math.Asin") M(acos,"•math.Acos") M(atan,"•math.Atan") \ /* arithm.c*/M(sinh,"•math.Sinh") M(cosh,"•math.Cosh") M(tanh,"•math.Tanh") M(asinh,"•math.Asinh") M(acosh,"•math.Acosh") M(atanh,"•math.Atanh") \ -/* arithm.c*/M(cbrt,"•math.Cbrt") M(log2,"•math.Log2") M(log10,"•math.Log10") M(log1p,"•math.Log1p") M(expm1,"•math.Expm1") M(fact,"•math.Fact") D(comb,"•math.Comb") M(logfact,"•math.LogFact") \ -/* arithm.c*/M(erf,"•math.Erf") M(erfc,"•math.ErfC") D(gcd,"•math.GCD") D(lcm,"•math.LCM") M(sum,"•math.Sum") +/* arithm.c*/M(cbrt,"•math.Cbrt") M(log2,"•math.Log2") M(log10,"•math.Log10") M(log1p,"•math.Log1p") M(expm1,"•math.Expm1") M(fact,"•math.Fact") M(logfact,"•math.LogFact") \ +/* arithm.c*/M(erf,"•math.Erf") M(erfc,"•math.ErfC") M(sum,"•math.Sum") #define FOR_PM1(A,M,D) \ /* md1.c*/A(tbl,"⌜") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") A(insert,"˝") \ diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index 60fefe6e..e1106397 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -470,14 +470,19 @@ static f64 comb(f64 k, f64 n) { // n choose k } return exp(lgamma(n+1) - lgamma(k+1) - lgamma(j+1)); } -static f64 bqn_atan2(f64 w, f64 x) { return atan2(w+0, x+0); } +static f64 bqn_atan2 (f64 x, f64 w) { return atan2(x+0, w+0); } +static f64 bqn_atan2ix(f64 x, f64 w) { return w * tan(x); } +static f64 bqn_atan2iw(f64 x, f64 w) { return w / (tan(x)+0); } #define MATH(n,N,I) B n##_c2(B t, B w, B x) { \ if (isNum(w) && isNum(x)) return m_f64(I(x.f, w.f)); \ P2(n) \ - thrM("•math." #N ": Unexpected argument types"); \ + thrM("•math." N ": Unexpected argument types"); \ } -MATH(atan2,Atan2,bqn_atan2) MATH(hypot,Hypot,hypot) MATH(comb,Comb,comb) +MATH(atan2,"Atan2",bqn_atan2) +MATH(atan2ix,"Atan2⁼",bqn_atan2ix) +MATH(atan2iw,"Atan2˜⁼",bqn_atan2iw) +MATH(hypot,"Hypot",hypot) MATH(comb,"Comb",comb) #undef MATH static u64 gcd_u64(u64 a, u64 b) { @@ -522,5 +527,6 @@ B lcm_c2(B t, B w, B x) { #undef P2 void arithd_init() { - + c(BFn, bi_atan2)->iw = atan2iw_c2; + c(BFn, bi_atan2)->ix = atan2ix_c2; } diff --git a/test/cases/system.bqn b/test/cases/system.bqn index 4c80f341..ed0b0da3 100644 --- a/test/cases/system.bqn +++ b/test/cases/system.bqn @@ -179,10 +179,20 @@ t0←•MonoTime@ ⋄ ! 0.1≤•Delay 0.1 ⋄ ! 0.1≤(•MonoTime@)-t0 ! {(0 •math.Atan2 𝕩) ≡ (•ParseFloat"-0") •math.Atan2 𝕩} (-≍⊢) ∞∾˜↕3 E←•internal.EEqual ⋄ a←(¯1⊸×≍⊢) (↕3)∾∞∾0÷0 ⋄ {𝕩!(a 𝕏 0)E a 𝕏 •ParseFloat"-0" ⋄ 𝕩!(0 𝕏 a)E(•ParseFloat"-0") 𝕏 a}¨ (⊢∾{𝕏¨}¨) ⟨+,-,×,÷,⋆,√,⌊,⌈,|,¬,∧,∨,<,>,≠,=,≤,≥, •math.Atan2,•math.Comb,•math.Hypot⟩ E←•internal.EEqual ⋄ {! (𝕏 4⥊0) E 𝕏 1↓¯1×π∾4⥊0}¨ (⊢∾{𝕏¨}¨) ⟨+,-,×,÷,⋆,√,⌊,⌈,|,¬, •math.Sin,•math.Cos,•math.Tan,•math.Asin,•math.Acos,•math.Atan,•math.Sinh,•math.Cosh,•math.Tanh,•math.Asinh,•math.Acosh,•math.Atanh,•math.Cbrt,•math.Log2,•math.Log10,•math.Log1p,•math.Expm1,•math.Fact,•math.LogFact,•math.Erf,•math.ErfC⟩ +•internal.EEqual´¨ 1⊏˘¨{⟨•math.Atan2⟜2⁼𝕩, •math.Atan2⟜0⁼𝕩, 2⊸•math.Atan2⁼𝕩, 0⊸•math.Atan2⁼𝕩⟩} (¯1⊸×≍⊢) 1.2‿0 %% 1‿1‿1‿1 {15 𝕏 10}¨ ⟨•math.GCD,•math.LCM⟩ %% 5‿30 -⌊1e5×{0.1 𝕏 0.2}¨ ⟨•math.Atan2,•math.Comb,•math.Hypot⟩ %% 110714‿96959‿22360 +⌊1e5×{0.1 𝕏 0.2}¨ ⟨•math.Atan2,•math.Comb,•math.Hypot,•math.Atan2⁼,•math.Atan2˜⁼⟩ %% 110714‿96959‿22360‿2027‿49331 ⌊1e5×{=˜◶99‿⊢¨ 𝕏 0.1‿3}¨ ⟨•math.Acos,•math.Acosh,•math.Asin,•math.Asinh,•math.Atan,•math.Atanh,•math.Cbrt,•math.Cos,•math.Cosh,•math.Erf,•math.ErfC,•math.Expm1,•math.Fact,•math.Log10,•math.Log1p,•math.Log2,•math.LogFact,•math.Sin,•math.Sinh,•math.Tan,•math.Tanh⟩ %% ⟨147062‿9900000,9900000‿176274,10016‿9900000,9983‿181844,9966‿124904,10033‿9900000,46415‿144224,99500‿¯99000,100500‿1006766,11246‿99997,88753‿2,10517‿1908553,95135‿600000,¯100000‿47712,9531‿138629,¯332193‿158496,¯4988‿179175,9983‿14112,10016‿1001787,10033‿¯14255,9966‿99505⟩ +!"•math.GCD: Inputs other than natural numbers not yet supported" % 1.5 •math.GCD 3 +!"•math.LCM: Inputs other than natural numbers not yet supported" % 3 •math.LCM 1.5 +!"•math.GCD: Unexpected argument types" % "foo" •math.LCM 3 +!"•math.GCD: Unexpected argument types" % 3 •math.GCD {+} +!"•math.Sin: Argument contained non-number" % •math.Sin "foo" +!"•math.Log10: Argument contained non-number" % •math.Log10 "foo" +!"•math.Atan2: Unexpected argument types" % 1 •math.Atan2 'a' +!"•math.Atan2⁼: Unexpected argument types" % 1 •math.Atan2⁼ {⇐} +!"•math.Atan2˜⁼: Unexpected argument types" % {⇐} •math.Atan2˜⁼ 'b' # •rand / •MakeRand 0 (•MakeRand 0).Range¨↕2 %% ⟨⟩‿⟨⟩