commit b64410a8040cbcb1236a0157d4a12cd100ecaf92
parent 62799933ed51e10c84d6dbc2ee5e541f1fbf35ca
Author: Ed van Bruggen <edvb@uw.edu>
Date: Sun, 12 May 2019 16:10:49 -0700
Rename pow to ^
Diffstat:
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/tibs/lib.tsp b/tibs/lib.tsp
@@ -112,7 +112,7 @@
(define e (exp 1.))
(define (sqr x) (* x x))
-(define (root b p) (pow b (/ 1 p)))
+(define (root b p) (^ b (/ 1 p)))
(define (sqrt x) (root x 2))
(define (cbrt x) (root x 3))
(define (logb b x) (/ (log x) (log b)))
diff --git a/tibs/math.c b/tibs/math.c
@@ -170,6 +170,22 @@ prim_mod(Env env, Val args)
return mk_int((int)num(a) % abs((int)num(b)));
}
+static Val
+prim_pow(Env env, Val args)
+{
+ double bnum, bden;
+ Val b, p;
+ tsp_arg_num(args, "pow", 2);
+ EVAL_CHECK(b, car(args), "pow", EXPRESSION);
+ EVAL_CHECK(p, car(cdr(args)), "pow", EXPRESSION);
+ bnum = pow(num(b), num(p)/den(p));
+ bden = pow(den(b), num(p)/den(p));
+ if (bnum == (int)bnum && bden == (int)bden &&
+ b->t & NUMBER && p->t & NUMBER)
+ return mk_num(b->t, p->t, 0)(bnum, bden);
+ return mk_pair(mk_sym(env, "pow"), mk_pair(b, mk_pair(p, env->nil)));
+}
+
#define PRIM_COMPARE(NAME, OP) \
static Val \
prim_##NAME(Env env, Val args) \
@@ -189,22 +205,6 @@ PRIM_COMPARE(gt, >)
PRIM_COMPARE(lte, <=)
PRIM_COMPARE(gte, >=)
-static Val
-prim_pow(Env env, Val args)
-{
- double bnum, bden;
- Val b, p;
- tsp_arg_num(args, "pow", 2);
- EVAL_CHECK(b, car(args), "pow", EXPRESSION);
- EVAL_CHECK(p, car(cdr(args)), "pow", EXPRESSION);
- bnum = pow(num(b), num(p)/den(p));
- bden = pow(den(b), num(p)/den(p));
- if (bnum == (int)bnum && bden == (int)bden &&
- b->t & NUMBER && p->t & NUMBER)
- return mk_num(b->t, p->t, 0)(bnum, bden);
- return mk_pair(mk_sym(env, "pow"), mk_pair(b, mk_pair(p, env->nil)));
-}
-
#define PRIM_TRIG(NAME) \
static Val \
prim_##NAME(Env env, Val args) \
@@ -245,14 +245,13 @@ tib_env_math(Env env)
tsp_env_name_fn(*, mul);
tsp_env_name_fn(/, div);
tsp_env_fn(mod);
+ tsp_env_name_fn(^, pow);
tsp_env_name_fn(<, lt);
tsp_env_name_fn(>, gt);
tsp_env_name_fn(<=, lte);
tsp_env_name_fn(>=, gte);
- tsp_env_fn(pow);
-
tsp_env_fn(sin);
tsp_env_fn(cos);
tsp_env_fn(tan);