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); }