tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 23fcc88791044fb7b6681bd97c13088a7e6f35a1
parent 932e46a65c3d1c784c434f68221f012d35d9d15e
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Wed, 13 Mar 2019 18:29:19 -0700

Add dec primitive to convert to decimal

Diffstat:
tibs/math.c | 19+++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tibs/math.c b/tibs/math.c @@ -48,6 +48,15 @@ prim_denominator(Env env, Val args) return mk_int(den(a)); } +static Val +prim_dec(Env env, Val args) +{ + Val a; + tsp_arg_num(args, "den", 1); + EVAL_CHECK(a, car(args), "den", NUMBER); + return mk_dec(num(a)/den(a)); +} + /* wrapper functions to be returned by mk_num, all need same arguments */ static Val create_int(double num, double den) @@ -188,10 +197,12 @@ tib_env_math(Env env) tsp_env_fn(numerator); tsp_env_fn(denominator); - tsp_env_name_fn(+, add); - tsp_env_name_fn(-, sub); - tsp_env_name_fn(*, mul); - tsp_env_name_fn(/, div); + tsp_env_fn(dec); + + tsp_env_name_fn(+, add); + tsp_env_name_fn(-, sub); + tsp_env_name_fn(*, mul); + tsp_env_name_fn(/, div); tsp_env_fn(mod); tsp_env_name_fn(<, lt);