From 90b691be67e19141b8eff2f2db8b9bd2e25f3524 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 28 Oct 2013 00:33:10 +0900 Subject: [PATCH] add exact/inexact function --- src/number.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/number.c b/src/number.c index 69c9ca03..e54a6553 100644 --- a/src/number.c +++ b/src/number.c @@ -360,6 +360,26 @@ pic_number_expt(pic_state *pic) return pic_float_value(h); } +static pic_value +pic_number_inexact(pic_state *pic) +{ + double f; + + pic_get_args(pic, "f", &f); + + return pic_float_value(f); +} + +static pic_value +pic_number_exact(pic_state *pic) +{ + double f; + + pic_get_args(pic, "f", &f); + + return pic_int_value((int)round(f)); +} + void pic_init_number(pic_state *pic) { @@ -407,4 +427,8 @@ pic_init_number(pic_state *pic) pic_defun(pic, "sqrt", pic_number_sqrt); pic_defun(pic, "expt", pic_number_expt); pic_gc_arena_restore(pic, ai); + + pic_defun(pic, "inexact", pic_number_inexact); + pic_defun(pic, "exact", pic_number_exact); + pic_gc_arena_restore(pic, ai); }