Other useful math: log2 log10 log1p expm1 hypot
This commit is contained in:
parent
a0f6986832
commit
58cd6f0f4e
@ -17,7 +17,7 @@
|
|||||||
/*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") M(heapDump,"•internal.HeapDump") \
|
/*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") M(heapDump,"•internal.HeapDump") \
|
||||||
/*internal.c*/M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") D(eequal,"•internal.EEqual") A(internalTemp,"•internal.Temp") \
|
/*internal.c*/M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") D(eequal,"•internal.EEqual") A(internalTemp,"•internal.Temp") \
|
||||||
/*internal.c*/D(variation,"•internal.Variation") A(listVariations,"•internal.ListVariations") M(clearRefs,"•internal.ClearRefs") M(unshare,"•internal.Unshare") \
|
/*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") M(sinh,"•math.Sinh") M(cosh,"•math.Cosh") M(tanh,"•math.Tanh") M(asinh,"•math.Asinh") M(acosh,"•math.Acosh") M(atanh,"•math.Atanh") D(gcd,"•math.GCD") D(lcm,"•math.LCM")
|
/* 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") M(sinh,"•math.Sinh") M(cosh,"•math.Cosh") M(tanh,"•math.Tanh") M(asinh,"•math.Asinh") M(acosh,"•math.Acosh") M(atanh,"•math.Atanh") M(cbrt,"•math.Cbrt") M(log2,"•math.Log2") M(log10,"•math.Log10") M(log1p,"•math.Log1p") M(expm1,"•math.Expm1") D(gcd,"•math.GCD") D(lcm,"•math.LCM")
|
||||||
|
|
||||||
#define FOR_PM1(A,M,D) \
|
#define FOR_PM1(A,M,D) \
|
||||||
/*md1.c*/A(tbl,"⌜") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") A(insert,"˝") \
|
/*md1.c*/A(tbl,"⌜") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") A(insert,"˝") \
|
||||||
|
|||||||
@ -360,11 +360,14 @@ AR_F_SCALAR("|", stile, pfmod(x.f, w.f))
|
|||||||
AR_F_SCALAR("⋆⁼",log , log(x.f)/log(w.f))
|
AR_F_SCALAR("⋆⁼",log , log(x.f)/log(w.f))
|
||||||
#undef AR_F_SCALAR
|
#undef AR_F_SCALAR
|
||||||
|
|
||||||
B atan2_c2(B t, B w, B x) {
|
#define MATH(n,N) \
|
||||||
if (isNum(w) && isNum(x)) return m_f64(atan2(x.f, w.f));
|
B n##_c2(B t, B w, B x) { \
|
||||||
P2(atan2)
|
if (isNum(w) && isNum(x)) return m_f64(n(x.f, w.f)); \
|
||||||
thrM("•math.Atan2: Unexpected argument types");
|
P2(n) \
|
||||||
}
|
thrM("•math." #N ": Unexpected argument types"); \
|
||||||
|
}
|
||||||
|
MATH(atan2,Atan2) MATH(hypot,Hypot)
|
||||||
|
#undef MATH
|
||||||
|
|
||||||
static u64 gcd_u64(u64 a, u64 b) {
|
static u64 gcd_u64(u64 a, u64 b) {
|
||||||
if (a == 0) return b;
|
if (a == 0) return b;
|
||||||
|
|||||||
@ -94,10 +94,11 @@ B pow_c1(B t, B x) { if (isF64(x)) return m_f64( exp(x.f)); P1( pow); thrM("
|
|||||||
B log_c1(B t, B x) { if (isF64(x)) return m_f64( log(x.f)); P1( log); thrM("⋆⁼: Getting log of non-number"); }
|
B log_c1(B t, B x) { if (isF64(x)) return m_f64( log(x.f)); P1( log); thrM("⋆⁼: Getting log of non-number"); }
|
||||||
#define MATH(n,N) \
|
#define MATH(n,N) \
|
||||||
B n##_c1(B t, B x) { if (isF64(x)) return m_f64(n(x.f)); P1(n); thrM("•math." #N ": Argument contained non-number"); }
|
B n##_c1(B t, B x) { if (isF64(x)) return m_f64(n(x.f)); P1(n); thrM("•math." #N ": Argument contained non-number"); }
|
||||||
|
MATH(cbrt,Cbrt) MATH(log2,Log2) MATH(log10,Log10) MATH(log1p,Log1p) MATH(expm1,Expm1)
|
||||||
#define TRIG(n,N) MATH(n,N) MATH(a##n,A##n) MATH(n##h,N##h) MATH(a##n##h,A##n##h)
|
#define TRIG(n,N) MATH(n,N) MATH(a##n,A##n) MATH(n##h,N##h) MATH(a##n##h,A##n##h)
|
||||||
TRIG(sin,Sin) TRIG(cos,Cos) TRIG(tan,Tan)
|
TRIG(sin,Sin) TRIG(cos,Cos) TRIG(tan,Tan)
|
||||||
#undef MATH
|
|
||||||
#undef TRIG
|
#undef TRIG
|
||||||
|
#undef MATH
|
||||||
#undef P1
|
#undef P1
|
||||||
|
|
||||||
B lt_c1(B t, B x) { return m_atomUnit(x); }
|
B lt_c1(B t, B x) { return m_atomUnit(x); }
|
||||||
@ -109,8 +110,8 @@ static B mathNS;
|
|||||||
B getMathNS() {
|
B getMathNS() {
|
||||||
if (mathNS.u == 0) {
|
if (mathNS.u == 0) {
|
||||||
#define F(X) inc(bi_##X),
|
#define F(X) inc(bi_##X),
|
||||||
Body* d = m_nnsDesc("sin","cos","tan","asin","acos","atan","atan2","sinh","cosh","tanh","asinh","acosh","atanh","gcd","lcm");
|
Body* d = m_nnsDesc("sin","cos","tan","asin","acos","atan","atan2","sinh","cosh","tanh","asinh","acosh","atanh","cbrt","log2","log10","log1p","expm1","hypot","gcd","lcm");
|
||||||
mathNS = m_nns(d, F(sin)F(cos)F(tan)F(asin)F(acos)F(atan)F(atan2)F(sinh)F(cosh)F(tanh)F(asinh)F(acosh)F(atanh)F(gcd)F(lcm));
|
mathNS = m_nns(d, F(sin)F(cos)F(tan)F(asin)F(acos)F(atan)F(atan2)F(sinh)F(cosh)F(tanh)F(asinh)F(acosh)F(atanh)F(cbrt)F(log2)F(log10)F(log1p)F(expm1)F(hypot)F(gcd)F(lcm));
|
||||||
#undef F
|
#undef F
|
||||||
gc_add(mathNS);
|
gc_add(mathNS);
|
||||||
}
|
}
|
||||||
@ -136,4 +137,6 @@ void arith_init() {
|
|||||||
c(BFn,bi_asinh)->im = sinh_c1;
|
c(BFn,bi_asinh)->im = sinh_c1;
|
||||||
c(BFn,bi_acosh)->im = cosh_c1;
|
c(BFn,bi_acosh)->im = cosh_c1;
|
||||||
c(BFn,bi_atanh)->im = tanh_c1;
|
c(BFn,bi_atanh)->im = tanh_c1;
|
||||||
|
c(BFn,bi_expm1)->im = log1p_c1;
|
||||||
|
c(BFn,bi_log1p)->im = expm1_c1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1551,7 +1551,7 @@ u32* dsv_text[] = {
|
|||||||
U"•file.MapBytes",U"•file.Modified",U"•file.Name",U"•file.Parent",U"•file.Remove",U"•file.Rename",U"•file.Size",U"•file.Type",
|
U"•file.MapBytes",U"•file.Modified",U"•file.Name",U"•file.Parent",U"•file.Remove",U"•file.Rename",U"•file.Size",U"•file.Type",
|
||||||
|
|
||||||
U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.HeapDump",U"•internal.Info",U"•internal.IsPure",U"•internal.ListVariations",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Variation",
|
U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.HeapDump",U"•internal.Info",U"•internal.IsPure",U"•internal.ListVariations",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Variation",
|
||||||
U"•math.Acos",U"•math.Acosh",U"•math.Asin",U"•math.Asinh",U"•math.Atan",U"•math.Atan2",U"•math.Atanh",U"•math.Cos",U"•math.Cosh",U"•math.GCD",U"•math.LCM",U"•math.Sin",U"•math.Sinh",U"•math.Tan",U"•math.Tanh",
|
U"•math.Acos",U"•math.Acosh",U"•math.Asin",U"•math.Asinh",U"•math.Atan",U"•math.Atan2",U"•math.Atanh",U"•math.Cbrt",U"•math.Cos",U"•math.Cosh",U"•math.Expm1",U"•math.GCD",U"•math.Hypot",U"•math.LCM",U"•math.Log10",U"•math.Log1p",U"•math.Log2",U"•math.Sin",U"•math.Sinh",U"•math.Tan",U"•math.Tanh",
|
||||||
U"•rand.Deal",U"•rand.Range",U"•rand.Subset",
|
U"•rand.Deal",U"•rand.Range",U"•rand.Subset",
|
||||||
U"•term.CharB",U"•term.CharN",U"•term.ErrRaw",U"•term.Flush",U"•term.OutRaw",U"•term.RawMode",
|
U"•term.CharB",U"•term.CharN",U"•term.ErrRaw",U"•term.Flush",U"•term.OutRaw",U"•term.RawMode",
|
||||||
NULL
|
NULL
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user