diff --git a/src/number.c b/src/number.c index 1f2e2b9e..4b05dfc3 100644 --- a/src/number.c +++ b/src/number.c @@ -78,6 +78,46 @@ pic_number_abs(pic_state *pic) return pic_float_value(fabs(f)); } +static pic_value +pic_number_floor_quotient(pic_state *pic) +{ + double f,g; + + pic_get_args(pic, "ff", &f, &g); + return pic_float_value(floor(f/g)); +} + +static pic_value +pic_number_floor_remainder(pic_state *pic) +{ + double f,g,q; + + pic_get_args(pic, "ff", &f, &g); + + q = floor(f/g); + return pic_float_value(f - g * q); +} + +static pic_value +pic_number_truncate_quotient(pic_state *pic) +{ + double f,g; + + pic_get_args(pic, "ff", &f, &g); + return pic_float_value(trunc(f/g)); +} + +static pic_value +pic_number_truncate_remainder(pic_state *pic) +{ + double f,g,q; + + pic_get_args(pic, "ff", &f, &g); + + q = trunc(f/g); + return pic_float_value(f - g * q); +} + static pic_value pic_number_floor(pic_state *pic) { @@ -257,6 +297,12 @@ pic_init_number(pic_state *pic) pic_defun(pic, "abs", pic_number_abs); + pic_defun(pic, "floor-quotient", pic_number_floor_quotient); + pic_defun(pic, "floor-remainder", pic_number_floor_remainder); + pic_defun(pic, "truncate-quotient", pic_number_truncate_quotient); + pic_defun(pic, "truncate-remainder", pic_number_truncate_remainder); + pic_gc_arena_restore(pic, ai); + pic_defun(pic, "floor", pic_number_floor); pic_defun(pic, "ceiling", pic_number_ceiling); pic_defun(pic, "truncate", pic_number_truncate);