numeric.c: function renaming.
`mrb_num_div_int(mrb,x,y)` -> `mrb_div_int(mrb,x,y)`
`mrb_num_div_flo(mrb,x,y)` -> `mrb_div_flo(x,y)`
They are internal function not supposed to be used outside of the core.
MODIFY
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
@@ -236,8 +236,7 @@ complex_mul(mrb_state *mrb, mrb_value x)
}
#ifndef MRB_NO_FLOAT
-mrb_float mrb_num_div_flo(mrb_state*, mrb_float, mrb_float);
-#define div_flo(x,y) mrb_num_div_flo(NULL, x, y)
+mrb_float mrb_div_flo(mrb_float, mrb_float);
#endif
/* Arithmetic on (significand, exponent) pairs avoids premature overflow in
@@ -276,7 +275,7 @@ static void
div_pair(struct float_pair *q, struct float_pair const *a,
struct float_pair const *b)
{
- q->s = div_flo(a->s, b->s);
+ q->s = mrb_div_flo(a->s, b->s);
q->x = a->x - b->x;
}
@@ -289,7 +288,7 @@ complex_div(mrb_state *mrb, mrb_value self)
a = complex_ptr(mrb, self);
if (mrb_type(rhs) != MRB_TT_COMPLEX) {
mrb_float f = mrb_to_flo(mrb, rhs);
- return complex_new(mrb, div_flo(a->real, f), div_flo(a->imaginary, f));
+ return complex_new(mrb, mrb_div_flo(a->real, f), mrb_div_flo(a->imaginary, f));
}
struct float_pair ar, ai, br, bi;
@@ -332,7 +331,7 @@ complex_div(mrb_state *mrb, mrb_value self)
return complex_new(mrb, F(ldexp)(zr.s, zr.x), F(ldexp)(zi.s, zi.x));
}
-mrb_int mrb_num_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
+mrb_int mrb_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
mrb_value mrb_rational_new(mrb_state *mrb, mrb_int n, mrb_int d);
mrb_value mrb_rational_div(mrb_state *mrb, mrb_value x);
@@ -347,7 +346,7 @@ cpx_int_div(mrb_state *mrb, mrb_value x)
mrb_int a = mrb_integer(x);
if (mrb_integer_p(y)) {
- mrb_int div = mrb_num_div_int(mrb, a, mrb_integer(y));
+ mrb_int div = mrb_div_int(mrb, a, mrb_integer(y));
return mrb_int_value(mrb, div);
}
switch (mrb_type(y)) {
@@ -359,7 +358,7 @@ cpx_int_div(mrb_state *mrb, mrb_value x)
x = complex_new(mrb, (mrb_float)a, 0);
return complex_div(mrb, x);
default:
- return mrb_float_value(mrb, div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
}
}
@@ -384,7 +383,7 @@ cpx_int_quo(mrb_state *mrb, mrb_value x)
x = complex_new(mrb, (mrb_float)a, 0);
return complex_div(mrb, x);
default:
- return mrb_float_value(mrb, div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
}
}
@@ -398,10 +397,10 @@ cpx_flo_div(mrb_state *mrb, mrb_value x)
case MRB_TT_COMPLEX:
return complex_div(mrb, complex_new(mrb, a, 0));
case MRB_TT_FLOAT:
- a = div_flo(a, mrb_float(y));
+ a = mrb_div_flo(a, mrb_float(y));
return mrb_float_value(mrb, a);
default:
- a = div_flo(a, mrb_to_flo(mrb, y));
+ a = mrb_div_flo(a, mrb_to_flo(mrb, y));
return mrb_float_value(mrb, a);
}
}

MODIFY
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
@@ -484,7 +484,7 @@ rational_minus(mrb_state *mrb, mrb_value x)
}
#ifndef MRB_NO_FLOAT
-mrb_float mrb_num_div_flo(mrb_state*, mrb_float, mrb_float);
+mrb_float mrb_div_flo(mrb_float, mrb_float);
#endif
static mrb_value
@@ -517,7 +517,7 @@ rational_add(mrb_state *mrb, mrb_value x)
case MRB_TT_FLOAT:
{
mrb_float z = p1->numerator + mrb_float(y) * p1->denominator;
- return mrb_float_value(mrb, mrb_num_div_flo(mrb, z, (mrb_float)p1->denominator));
+ return mrb_float_value(mrb, mrb_div_flo(z, (mrb_float)p1->denominator));
}
#endif
@@ -563,7 +563,7 @@ rational_sub(mrb_state *mrb, mrb_value x)
default:
{
mrb_float z = p1->numerator - mrb_to_flo(mrb, y) * p1->denominator;
- return mrb_float_value(mrb, mrb_num_div_flo(mrb, z, (mrb_float)p1->denominator));
+ return mrb_float_value(mrb, mrb_div_flo(z, (mrb_float)p1->denominator));
}
#else
default:
@@ -599,7 +599,7 @@ rational_mul(mrb_state *mrb, mrb_value x)
case MRB_TT_FLOAT:
{
mrb_float z = p1->numerator * mrb_float(y);
- return mrb_float_value(mrb, mrb_num_div_flo(mrb, z, (mrb_float)p1->denominator));
+ return mrb_float_value(mrb, mrb_div_flo(z, (mrb_float)p1->denominator));
}
#endif
@@ -608,8 +608,6 @@ rational_mul(mrb_state *mrb, mrb_value x)
}
}
-mrb_int mrb_num_div_int(mrb_state *, mrb_int, mrb_int);
-
mrb_value
mrb_rational_div(mrb_state *mrb, mrb_value x)
{
@@ -643,8 +641,8 @@ mrb_rational_div(mrb_state *mrb, mrb_value x)
#ifndef MRB_NO_FLOAT
case MRB_TT_FLOAT:
{
- mrb_float z = mrb_num_div_flo(mrb, p1->numerator, mrb_to_flo(mrb, y));
- return mrb_float_value(mrb, mrb_num_div_flo(mrb, z, (mrb_float)p1->denominator));
+ mrb_float z = mrb_div_flo(p1->numerator, mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, mrb_div_flo(z, (mrb_float)p1->denominator));
}
#else
mrb_raise(mrb, E_TYPE_ERROR, "non integer division");
@@ -653,6 +651,7 @@ mrb_rational_div(mrb_state *mrb, mrb_value x)
}
#define rational_div mrb_rational_div
+mrb_int mrb_div_int(mrb_state *, mrb_int, mrb_int);
#ifndef MRB_USE_COMPLEX
/* 15.2.8.3.4 */
@@ -666,7 +665,7 @@ rat_int_div(mrb_state *mrb, mrb_value x)
mrb_int a = mrb_integer(x);
if (mrb_integer_p(y)) {
- mrb_int div = mrb_num_div_int(mrb, a, mrb_integer(y));
+ mrb_int div = mrb_div_int(mrb, a, mrb_integer(y));
return mrb_int_value(mrb, div);
}
switch (mrb_type(y)) {
@@ -677,7 +676,7 @@ rat_int_div(mrb_state *mrb, mrb_value x)
case MRB_TT_FLOAT:
mrb_raise(mrb, E_TYPE_ERROR, "non integer multiplication");
#else
- return mrb_float_value(mrb, mrb_num_div_flo(mrb, (mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
#endif
}
}
@@ -704,7 +703,7 @@ rat_int_quo(mrb_state *mrb, mrb_value x)
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non integer multiplication");
#else
- return mrb_float_value(mrb, mrb_num_div_flo(mrb, (mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
#endif
}
}

MODIFY
src/numeric.c
src/numeric.c
@@ -119,7 +119,7 @@ int_pow(mrb_state *mrb, mrb_value x)
}
mrb_int
-mrb_num_div_int(mrb_state *mrb, mrb_int x, mrb_int y)
+mrb_div_int(mrb_state *mrb, mrb_int x, mrb_int y)
{
if (y == 0) {
int_zerodiv(mrb);
@@ -139,6 +139,8 @@ mrb_num_div_int(mrb_state *mrb, mrb_int x, mrb_int y)
return 0;
}
+mrb_float mrb_div_flo(mrb_float x, mrb_float y);
+
/* 15.2.8.3.4 */
/* 15.2.9.3.4 */
/*
@@ -156,13 +158,13 @@ int_div(mrb_state *mrb, mrb_value x)
mrb_int a = mrb_integer(x);
if (mrb_integer_p(y)) {
- mrb_int div = mrb_num_div_int(mrb, a, mrb_integer(y));
+ mrb_int div = mrb_div_int(mrb, a, mrb_integer(y));
return mrb_int_value(mrb, div);
}
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non integer division");
#else
- return mrb_float_value(mrb, (mrb_float)a / mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
#endif
}
@@ -248,12 +250,12 @@ flo_idiv(mrb_state *mrb, mrb_value xv)
mrb_int y, div;
mrb_get_args(mrb, "i", &y);
- div = mrb_num_div_int(mrb, (mrb_int)mrb_float(xv), y);
+ div = mrb_div_int(mrb, (mrb_int)mrb_float(xv), y);
return mrb_int_value(mrb, (mrb_int)div);
}
mrb_float
-mrb_num_div_flo(mrb_state *mrb, mrb_float x, mrb_float y)
+mrb_div_flo(mrb_float x, mrb_float y)
{
if (y != 0.0) {
return x / y;
@@ -273,10 +275,10 @@ flo_div(mrb_state *mrb, mrb_value x)
mrb_float a = mrb_float(x);
if (mrb_float_p(y)) {
- a = mrb_num_div_flo(mrb, a, mrb_float(y));
+ a = mrb_div_flo(a, mrb_float(y));
}
else {
- a = mrb_num_div_flo(mrb, a, mrb_to_flo(mrb, y));
+ a = mrb_div_flo(a, mrb_to_flo(mrb, y));
}
return mrb_float_value(mrb, a);
}

MODIFY
src/vm.c
src/vm.c
@@ -1068,6 +1068,8 @@ check_target_class(mrb_state *mrb)
}
void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self);
+mrb_int mrb_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
+mrb_float mrb_div_flo(mrb_float x, mrb_float y);
MRB_API mrb_value
mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc)
@@ -2364,9 +2366,7 @@ RETRY_TRY_BLOCK:
}
CASE(OP_DIV, B) {
- mrb_int mrb_num_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
#ifndef MRB_NO_FLOAT
- mrb_float mrb_num_div_flo(mrb_state *mrb, mrb_float x, mrb_float y);
mrb_float x, y, f;
#endif
@@ -2376,7 +2376,7 @@ RETRY_TRY_BLOCK:
{
mrb_int x = mrb_integer(regs[a]);
mrb_int y = mrb_integer(regs[a+1]);
- mrb_int div = mrb_num_div_int(mrb, x, y);
+ mrb_int div = mrb_div_int(mrb, x, y);
SET_INT_VALUE(mrb, regs[a], div);
}
NEXT;
@@ -2401,7 +2401,7 @@ RETRY_TRY_BLOCK:
}
#ifndef MRB_NO_FLOAT
- f = mrb_num_div_flo(mrb, x, y);
+ f = mrb_div_flo(x, y);
SET_FLOAT_VALUE(mrb, regs[a], f);
#endif
NEXT;

numeric.c: function renaming.

- `mrb_num_div_int(mrb,x,y)` -> `mrb_div_int(mrb,x,y)`
- `mrb_num_div_flo(mrb,x,y)` -> `mrb_div_flo(x,y)`

They are internal function not supposed to be used outside of the core.