commit dedd483d8cecea0a7910b9f4c39dd4dce26c0481
parent 27a8d7135bbcb8d7cdff4f11ec5e3e8124a46cd5
Author: Ed van Bruggen <edvb@uw.edu>
Date: Sun, 27 Jan 2019 00:50:11 -0800
Rename double to decimal
Diffstat:
3 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/tibs/math.c b/tibs/math.c
@@ -56,7 +56,7 @@ create_rat(double num, double den)
static Val
(*mk_num(Type a, Type b, int isfrac))(double, double)
{
- if (a & DOUBLE || b & DOUBLE)
+ if (a & DECIMAL || b & DECIMAL)
return &create_dub;
if (isfrac || a & RATIO || b & RATIO)
return &create_rat;
@@ -70,10 +70,11 @@ prim_add(Env env, Val args)
tsp_arg_num(args, "+", 2);
EVAL_CHECK(a, car(args), "+", NUMBER);
EVAL_CHECK(b, car(cdr(args)), "+", NUMBER);
- if (a->t & DOUBLE || b->t & DOUBLE)
+ if (a->t & DECIMAL || b->t & DECIMAL)
return mk_dub((a->v.n.num/a->v.n.den) + (b->v.n.num/b->v.n.den));
return (mk_num(a->t, b->t, 0))
- (a->v.n.num * b->v.n.den + a->v.n.den * b->v.n.num, a->v.n.den * b->v.n.den);
+ (a->v.n.num * b->v.n.den + a->v.n.den * b->v.n.num,
+ a->v.n.den * b->v.n.den);
}
static Val
@@ -90,9 +91,11 @@ prim_sub(Env env, Val args)
} else {
EVAL_CHECK(b, car(cdr(args)), "-", NUMBER);
}
- if (a->t & DOUBLE || b->t & DOUBLE)
+ if (a->t & DECIMAL || b->t & DECIMAL)
return mk_dub((a->v.n.num/a->v.n.den) - (b->v.n.num/b->v.n.den));
- return (mk_num(a->t, b->t, 0))(a->v.n.num * b->v.n.den - a->v.n.den * b->v.n.num, a->v.n.den * b->v.n.den);
+ return (mk_num(a->t, b->t, 0))
+ (a->v.n.num * b->v.n.den - a->v.n.den * b->v.n.num,
+ a->v.n.den * b->v.n.den);
}
static Val
@@ -102,9 +105,10 @@ prim_mul(Env env, Val args)
tsp_arg_num(args, "*", 2);
EVAL_CHECK(a, car(args), "*", NUMBER);
EVAL_CHECK(b, car(cdr(args)), "*", NUMBER);
- if (a->t & DOUBLE || b->t & DOUBLE)
+ if (a->t & DECIMAL || b->t & DECIMAL)
return mk_dub((a->v.n.num/a->v.n.den) * (b->v.n.num/b->v.n.den));
- return (mk_num(a->t, b->t, 0))(a->v.n.num * b->v.n.num, a->v.n.den * b->v.n.den);
+ return (mk_num(a->t, b->t, 0))
+ (a->v.n.num * b->v.n.num, a->v.n.den * b->v.n.den);
}
@@ -115,9 +119,10 @@ prim_div(Env env, Val args)
tsp_arg_num(args, "/", 2);
EVAL_CHECK(a, car(args), "/", NUMBER);
EVAL_CHECK(b, car(cdr(args)), "/", NUMBER);
- if (a->t & DOUBLE || b->t & DOUBLE)
+ if (a->t & DECIMAL || b->t & DECIMAL)
return mk_dub((a->v.n.num/a->v.n.den) / (b->v.n.num/b->v.n.den));
- return (mk_num(a->t, b->t, 1))(a->v.n.num * b->v.n.den, a->v.n.den * b->v.n.num);
+ return (mk_num(a->t, b->t, 1))
+ (a->v.n.num * b->v.n.den, a->v.n.den * b->v.n.num);
}
static Val
diff --git a/tisp.c b/tisp.c
@@ -88,7 +88,7 @@ type_str(Type t)
case NONE: return "void";
case NIL: return "nil";
case INTEGER: return "integer";
- case DOUBLE: return "double";
+ case DECIMAL: return "decimal";
case RATIO: return "ratio";
case STRING: return "string";
case SYMBOL: return "symbol";
@@ -149,7 +149,7 @@ vals_eq(Val a, Val b)
return 0;
switch (a->t) {
case INTEGER:
- case DOUBLE:
+ case DECIMAL:
case RATIO:
if (a->v.n.num != b->v.n.num || a->v.n.den != b->v.n.den)
return 0;
@@ -311,7 +311,7 @@ Val
mk_dub(double d)
{
Val ret = emalloc(sizeof(struct Val));
- ret->t = DOUBLE;
+ ret->t = DECIMAL;
ret->v.n.num = d;
ret->v.n.den = 1;
return ret;
@@ -560,7 +560,7 @@ tisp_eval(Env env, Val v)
case NONE:
case NIL:
case INTEGER:
- case DOUBLE:
+ case DECIMAL:
case RATIO:
case STRING:
return v;
@@ -612,7 +612,7 @@ tisp_print(FILE *f, Val v)
case INTEGER:
fprintf(f, "%d", (int)v->v.n.num);
break;
- case DOUBLE:
+ case DECIMAL:
fprintf(f, "%.15g", v->v.n.num);
if (v->v.n.num == (int)v->v.n.num)
fprintf(f, ".0");
diff --git a/tisp.h b/tisp.h
@@ -91,20 +91,20 @@ typedef enum {
NONE = 1 << 0,
NIL = 1 << 1,
INTEGER = 1 << 2,
- RATIO = 1 << 3,
- DOUBLE = 1 << 4,
+ DECIMAL = 1 << 3,
+ RATIO = 1 << 4,
STRING = 1 << 5,
SYMBOL = 1 << 6,
PRIMITIVE = 1 << 7,
FUNCTION = 1 << 8,
PAIR = 1 << 9,
} Type;
-static Type const NUMBER = INTEGER | DOUBLE | RATIO;
+static Type const NUMBER = INTEGER | DECIMAL | RATIO;
struct Val {
Type t; /* NONE, NIL */
union {
- Ratio n; /* INTEGER, DOUBLE, RATIO */
+ Ratio n; /* INTEGER, DECIMAL, RATIO */
char *s; /* STRING, SYMBOL */
Prim pr; /* PRIMITIVE */
Func f; /* FUNCTION */