mirror of
https://github.com/false-schemers/skint.git
synced 2024-12-26 21:58:51 +01:00
{fl,}{exp,log,sin,cos,tan,asin,acos,atan} added
This commit is contained in:
parent
295c62ca39
commit
c11ae4e110
2 changed files with 178 additions and 2 deletions
162
i.c
162
i.c
|
@ -1740,6 +1740,65 @@ define_instruction(jround) {
|
||||||
gonexti();
|
gonexti();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define_instruction(jexp) {
|
||||||
|
ckj(ac);
|
||||||
|
ac = obj_from_flonum(sp-r, exp(flonum_from_obj(ac)));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(jlog) {
|
||||||
|
obj x = ac, y = spop(); ckj(ac);
|
||||||
|
if (likely(!y)) {
|
||||||
|
ac = obj_from_flonum(sp-r, log(flonum_from_obj(ac)));
|
||||||
|
} else {
|
||||||
|
double b; ckj(y); b = flonum_from_obj(y);
|
||||||
|
if (likely(b == 10.0)) ac = obj_from_flonum(sp-r, log10(flonum_from_obj(ac)));
|
||||||
|
else ac = obj_from_flonum(sp-r, log(flonum_from_obj(ac))/log(b));
|
||||||
|
}
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(jsin) {
|
||||||
|
ckj(ac);
|
||||||
|
ac = obj_from_flonum(sp-r, sin(flonum_from_obj(ac)));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(jcos) {
|
||||||
|
ckj(ac);
|
||||||
|
ac = obj_from_flonum(sp-r, cos(flonum_from_obj(ac)));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(jtan) {
|
||||||
|
ckj(ac);
|
||||||
|
ac = obj_from_flonum(sp-r, tan(flonum_from_obj(ac)));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(jasin) {
|
||||||
|
ckj(ac);
|
||||||
|
ac = obj_from_flonum(sp-r, asin(flonum_from_obj(ac)));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(jacos) {
|
||||||
|
ckj(ac);
|
||||||
|
ac = obj_from_flonum(sp-r, acos(flonum_from_obj(ac)));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(jatan) {
|
||||||
|
obj x = ac, y = spop(); ckj(ac);
|
||||||
|
if (likely(!y)) {
|
||||||
|
ac = obj_from_flonum(sp-r, atan(flonum_from_obj(x)));
|
||||||
|
} else {
|
||||||
|
ckj(y);
|
||||||
|
ac = obj_from_flonum(sp-r, atan2(flonum_from_obj(x), flonum_from_obj(y)));
|
||||||
|
}
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
define_instruction(zerop) {
|
define_instruction(zerop) {
|
||||||
obj x = ac;
|
obj x = ac;
|
||||||
|
@ -2085,11 +2144,112 @@ define_instruction(sqrt) {
|
||||||
long x = fixnum_from_obj(ac), y;
|
long x = fixnum_from_obj(ac), y;
|
||||||
if (x < 0) ac = obj_from_flonum(sp-r, (HUGE_VAL - HUGE_VAL));
|
if (x < 0) ac = obj_from_flonum(sp-r, (HUGE_VAL - HUGE_VAL));
|
||||||
else if (y = fxsqrt(x), y*y == x) ac = obj_from_fixnum(y);
|
else if (y = fxsqrt(x), y*y == x) ac = obj_from_fixnum(y);
|
||||||
else ac = obj_from_flonum(sp-r, sqrt((double)x));
|
else ac = obj_from_flonum(sp-r, sqrt((double)x));
|
||||||
} else failactype("number");
|
} else failactype("number");
|
||||||
gonexti();
|
gonexti();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define_instruction(exp) {
|
||||||
|
double x;
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) x = (double)fixnum_from_obj(ac);
|
||||||
|
else if (likely(is_flonum_obj(ac))) x = flonum_from_obj(ac);
|
||||||
|
else failactype("number");
|
||||||
|
ac = obj_from_flonum(sp-r, exp(x));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(log) {
|
||||||
|
double x; obj y = spop();
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) x = (double)fixnum_from_obj(ac);
|
||||||
|
else if (likely(is_flonum_obj(ac))) x = flonum_from_obj(ac);
|
||||||
|
else failactype("number");
|
||||||
|
if (likely(!y)) {
|
||||||
|
ac = obj_from_flonum(sp-r, log(x));
|
||||||
|
} else if (likely(y == obj_from_fixnum(10))) {
|
||||||
|
ac = obj_from_flonum(sp-r, log10(x));
|
||||||
|
} else {
|
||||||
|
double b;
|
||||||
|
if (unlikely(is_fixnum_obj(y))) b = (double)fixnum_from_obj(y);
|
||||||
|
else if (likely(is_flonum_obj(y))) b = flonum_from_obj(y);
|
||||||
|
else failtype(y, "number");
|
||||||
|
if (likely(b == 10.0)) ac = obj_from_flonum(sp-r, log10(x));
|
||||||
|
else ac = obj_from_flonum(sp-r, log(x)/log(b));
|
||||||
|
}
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(sin) {
|
||||||
|
double x;
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) {
|
||||||
|
x = (double)fixnum_from_obj(ac);
|
||||||
|
} else if (likely(is_flonum_obj(ac))) {
|
||||||
|
x = flonum_from_obj(ac);
|
||||||
|
} else failactype("number");
|
||||||
|
ac = obj_from_flonum(sp-r, sin(x));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(cos) {
|
||||||
|
double x;
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) {
|
||||||
|
x = (double)fixnum_from_obj(ac);
|
||||||
|
} else if (likely(is_flonum_obj(ac))) {
|
||||||
|
x = flonum_from_obj(ac);
|
||||||
|
} else failactype("number");
|
||||||
|
ac = obj_from_flonum(sp-r, cos(x));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(tan) {
|
||||||
|
double x;
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) {
|
||||||
|
x = (double)fixnum_from_obj(ac);
|
||||||
|
} else if (likely(is_flonum_obj(ac))) {
|
||||||
|
x = flonum_from_obj(ac);
|
||||||
|
} else failactype("number");
|
||||||
|
ac = obj_from_flonum(sp-r, tan(x));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(asin) {
|
||||||
|
double x;
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) {
|
||||||
|
x = (double)fixnum_from_obj(ac);
|
||||||
|
} else if (likely(is_flonum_obj(ac))) {
|
||||||
|
x = flonum_from_obj(ac);
|
||||||
|
} else failactype("number");
|
||||||
|
ac = obj_from_flonum(sp-r, asin(x));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(acos) {
|
||||||
|
double x;
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) {
|
||||||
|
x = (double)fixnum_from_obj(ac);
|
||||||
|
} else if (likely(is_flonum_obj(ac))) {
|
||||||
|
x = flonum_from_obj(ac);
|
||||||
|
} else failactype("number");
|
||||||
|
ac = obj_from_flonum(sp-r, acos(x));
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
|
define_instruction(atan) {
|
||||||
|
double x; obj y = spop();
|
||||||
|
if (unlikely(is_fixnum_obj(ac))) x = (double)fixnum_from_obj(ac);
|
||||||
|
else if (likely(is_flonum_obj(ac))) x = flonum_from_obj(ac);
|
||||||
|
else failactype("number");
|
||||||
|
if (likely(!y)) {
|
||||||
|
ac = obj_from_flonum(sp-r, atan(x));
|
||||||
|
} else {
|
||||||
|
double b;
|
||||||
|
if (unlikely(is_fixnum_obj(y))) b = (double)fixnum_from_obj(y);
|
||||||
|
else if (likely(is_flonum_obj(y))) b = flonum_from_obj(y);
|
||||||
|
else failtype(y, "number");
|
||||||
|
ac = obj_from_flonum(sp-r, atan2(x, b));
|
||||||
|
}
|
||||||
|
gonexti();
|
||||||
|
}
|
||||||
|
|
||||||
define_instruction(neg) {
|
define_instruction(neg) {
|
||||||
if (likely(is_fixnum_obj(ac))) {
|
if (likely(is_fixnum_obj(ac))) {
|
||||||
ac = obj_from_fixnum(-fixnum_from_obj(ac));
|
ac = obj_from_fixnum(-fixnum_from_obj(ac));
|
||||||
|
|
18
i.h
18
i.h
|
@ -298,13 +298,21 @@ declare_instruction(jgcd, "Jg\0'(j0)", 0, "flgcd", 'p',
|
||||||
declare_instruction(jpow, "Jp", 0, "flexpt", '2', AUTOGL)
|
declare_instruction(jpow, "Jp", 0, "flexpt", '2', AUTOGL)
|
||||||
declare_instruction(jsqrt, "Jt", 0, "flsqrt", '1', AUTOGL)
|
declare_instruction(jsqrt, "Jt", 0, "flsqrt", '1', AUTOGL)
|
||||||
declare_instruction(jtoi, "Ji", 0, "flonum->fixnum", '1', AUTOGL)
|
declare_instruction(jtoi, "Ji", 0, "flonum->fixnum", '1', AUTOGL)
|
||||||
declare_instruction(flop, "J0", 0, "flonum?", '1', AUTOGL)
|
|
||||||
declare_instruction(jmqu, "Jl", 0, "flmodquo", '2', AUTOGL)
|
declare_instruction(jmqu, "Jl", 0, "flmodquo", '2', AUTOGL)
|
||||||
declare_instruction(jmlo, "Jm", 0, "flmodulo", '2', AUTOGL)
|
declare_instruction(jmlo, "Jm", 0, "flmodulo", '2', AUTOGL)
|
||||||
declare_instruction(jfloor, "Jb", 0, "flfloor", '1', AUTOGL)
|
declare_instruction(jfloor, "Jb", 0, "flfloor", '1', AUTOGL)
|
||||||
declare_instruction(jceil, "Jc", 0, "flceiling", '1', AUTOGL)
|
declare_instruction(jceil, "Jc", 0, "flceiling", '1', AUTOGL)
|
||||||
declare_instruction(jtrunc, "Jk", 0, "fltruncate", '1', AUTOGL)
|
declare_instruction(jtrunc, "Jk", 0, "fltruncate", '1', AUTOGL)
|
||||||
declare_instruction(jround, "Jd", 0, "flround", '1', AUTOGL)
|
declare_instruction(jround, "Jd", 0, "flround", '1', AUTOGL)
|
||||||
|
declare_instruction(flop, "J0", 0, "flonum?", '1', AUTOGL)
|
||||||
|
declare_instruction(jexp, "J1", 0, "flexp", '1', AUTOGL)
|
||||||
|
declare_instruction(jlog, "J2\0f", 0, "fllog", 'b', AUTOGL)
|
||||||
|
declare_instruction(jsin, "J3", 0, "flsin", '1', AUTOGL)
|
||||||
|
declare_instruction(jcos, "J4", 0, "flcos", '1', AUTOGL)
|
||||||
|
declare_instruction(jtan, "J5", 0, "fltan", '1', AUTOGL)
|
||||||
|
declare_instruction(jasin, "J6", 0, "flasin", '1', AUTOGL)
|
||||||
|
declare_instruction(jacos, "J7", 0, "flacos", '1', AUTOGL)
|
||||||
|
declare_instruction(jatan, "J8\0f", 0, "flatan", 'b', AUTOGL)
|
||||||
declare_instruction(zerop, "=0", 0, "zero?", '1', AUTOGL)
|
declare_instruction(zerop, "=0", 0, "zero?", '1', AUTOGL)
|
||||||
declare_instruction(posp, ">0", 0, "positive?", '1', AUTOGL)
|
declare_instruction(posp, ">0", 0, "positive?", '1', AUTOGL)
|
||||||
declare_instruction(negp, "<0", 0, "negative?", '1', AUTOGL)
|
declare_instruction(negp, "<0", 0, "negative?", '1', AUTOGL)
|
||||||
|
@ -330,6 +338,14 @@ declare_instruction(mlo, "Nm", 0, "floor-remainder", '2',
|
||||||
declare_instruction(quo, "Nq", 0, "truncate-quotient", '2', AUTOGL)
|
declare_instruction(quo, "Nq", 0, "truncate-quotient", '2', AUTOGL)
|
||||||
declare_instruction(rem, "Nr", 0, "truncate-remainder", '2', AUTOGL)
|
declare_instruction(rem, "Nr", 0, "truncate-remainder", '2', AUTOGL)
|
||||||
declare_instruction(nump, "N0", 0, "number?", '1', AUTOGL)
|
declare_instruction(nump, "N0", 0, "number?", '1', AUTOGL)
|
||||||
|
declare_instruction(exp, "N1", 0, "exp", '1', AUTOGL)
|
||||||
|
declare_instruction(log, "N2\0f", 0, "log", 'b', AUTOGL)
|
||||||
|
declare_instruction(sin, "N3", 0, "sin", '1', AUTOGL)
|
||||||
|
declare_instruction(cos, "N4", 0, "cos", '1', AUTOGL)
|
||||||
|
declare_instruction(tan, "N5", 0, "tan", '1', AUTOGL)
|
||||||
|
declare_instruction(asin, "N6", 0, "asin", '1', AUTOGL)
|
||||||
|
declare_instruction(acos, "N7", 0, "acos", '1', AUTOGL)
|
||||||
|
declare_instruction(atan, "N8\0f", 0, "atan", 'b', AUTOGL)
|
||||||
declare_instruction(intp, "Nw", 0, "integer?", '1', AUTOGL)
|
declare_instruction(intp, "Nw", 0, "integer?", '1', AUTOGL)
|
||||||
declare_instruction(nanp, "Nu", 0, "nan?", '1', AUTOGL)
|
declare_instruction(nanp, "Nu", 0, "nan?", '1', AUTOGL)
|
||||||
declare_instruction(finp, "Nf", 0, "finite?", '1', AUTOGL)
|
declare_instruction(finp, "Nf", 0, "finite?", '1', AUTOGL)
|
||||||
|
|
Loading…
Reference in a new issue