summaryrefslogtreecommitdiffhomepage
path: root/src/numeric.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-06-20 12:49:46 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-06-20 12:49:46 +0900
commit49ae2a69f2c3acbb952406768320401cf1769425 (patch)
treefd0b49d898327a1de29e143fb2c68e6991cf710d /src/numeric.c
parent2ffb77586a8ce6f325d2981e2ad88cc9e62ae39b (diff)
downloadmruby-49ae2a69f2c3acbb952406768320401cf1769425.tar.gz
mruby-49ae2a69f2c3acbb952406768320401cf1769425.zip
Add `mrb_get_arg1()` that retrieves single (and only) argument.
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one argument. And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
Diffstat (limited to 'src/numeric.c')
-rw-r--r--src/numeric.c87
1 files changed, 28 insertions, 59 deletions
diff --git a/src/numeric.c b/src/numeric.c
index 07a2d20a8..3977a00c1 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -67,12 +67,11 @@ mrb_int_value(mrb_state *mrb, mrb_float f)
static mrb_value
integral_pow(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
#ifndef MRB_WITHOUT_FLOAT
mrb_float d;
#endif
- mrb_get_args(mrb, "o", &y);
if (mrb_fixnum_p(x) && mrb_fixnum_p(y)) {
/* try ipow() */
mrb_int base = mrb_fixnum(x);
@@ -116,9 +115,8 @@ static mrb_value
integral_idiv(mrb_state *mrb, mrb_value x)
{
#ifdef MRB_WITHOUT_FLOAT
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
if (!mrb_fixnum_p(y)) {
mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
}
@@ -154,9 +152,8 @@ static mrb_value
integral_div(mrb_state *mrb, mrb_value x)
{
#ifdef MRB_WITHOUT_FLOAT
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
if (!mrb_fixnum_p(y)) {
mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value");
}
@@ -271,9 +268,8 @@ flo_to_s(mrb_state *mrb, mrb_value flt)
static mrb_value
flo_minus(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
return mrb_float_value(mrb, mrb_float(x) - mrb_to_flo(mrb, y));
}
@@ -289,9 +285,8 @@ flo_minus(mrb_state *mrb, mrb_value x)
static mrb_value
flo_mul(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
return mrb_float_value(mrb, mrb_float(x) * mrb_to_flo(mrb, y));
}
@@ -351,11 +346,9 @@ flodivmod(mrb_state *mrb, double x, double y, mrb_float *divp, mrb_float *modp)
static mrb_value
flo_mod(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
mrb_float mod;
- mrb_get_args(mrb, "o", &y);
-
flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), 0, &mod);
return mrb_float_value(mrb, mod);
}
@@ -376,9 +369,8 @@ flo_mod(mrb_state *mrb, mrb_value x)
static mrb_value
fix_eql(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
if (!mrb_fixnum_p(y)) return mrb_false_value();
return mrb_bool_value(mrb_fixnum(x) == mrb_fixnum(y));
}
@@ -387,9 +379,8 @@ fix_eql(mrb_state *mrb, mrb_value x)
static mrb_value
flo_eql(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
if (!mrb_float_p(y)) return mrb_false_value();
return mrb_bool_value(mrb_float(x) == mrb_float(y));
}
@@ -410,8 +401,7 @@ flo_eql(mrb_state *mrb, mrb_value x)
static mrb_value
flo_eq(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
- mrb_get_args(mrb, "o", &y);
+ mrb_value y = mrb_get_arg1(mrb);
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
@@ -460,9 +450,8 @@ flo_rev(mrb_state *mrb, mrb_value x)
static mrb_value
flo_and(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
int64_t v1, v2;
- mrb_get_args(mrb, "o", &y);
v1 = (int64_t)mrb_float(x);
v2 = value_int64(mrb, y);
@@ -472,9 +461,8 @@ flo_and(mrb_state *mrb, mrb_value x)
static mrb_value
flo_or(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
int64_t v1, v2;
- mrb_get_args(mrb, "o", &y);
v1 = (int64_t)mrb_float(x);
v2 = value_int64(mrb, y);
@@ -484,9 +472,8 @@ flo_or(mrb_state *mrb, mrb_value x)
static mrb_value
flo_xor(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
int64_t v1, v2;
- mrb_get_args(mrb, "o", &y);
v1 = (int64_t)mrb_float(x);
v2 = value_int64(mrb, y);
@@ -847,9 +834,8 @@ mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y)
static mrb_value
fix_mul(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
return fixnum_mul(mrb, x, y);
}
@@ -894,10 +880,9 @@ fixdivmod(mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp)
static mrb_value
fix_mod(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
mrb_int a, b;
- mrb_get_args(mrb, "o", &y);
a = mrb_fixnum(x);
if (mrb_fixnum_p(y) && a != MRB_INT_MIN && (b=mrb_fixnum(y)) != MRB_INT_MIN) {
mrb_int mod;
@@ -936,9 +921,7 @@ fix_mod(mrb_state *mrb, mrb_value x)
static mrb_value
fix_divmod(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
-
- mrb_get_args(mrb, "o", &y);
+ mrb_value y = mrb_get_arg1(mrb);
if (mrb_fixnum_p(y)) {
mrb_int div, mod;
@@ -975,12 +958,10 @@ fix_divmod(mrb_state *mrb, mrb_value x)
static mrb_value
flo_divmod(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
mrb_float div, mod;
mrb_value a, b;
- mrb_get_args(mrb, "o", &y);
-
flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), &div, &mod);
a = mrb_int_value(mrb, div);
b = mrb_float_value(mrb, mod);
@@ -1003,9 +984,8 @@ flo_divmod(mrb_state *mrb, mrb_value x)
static mrb_value
fix_equal(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
return mrb_bool_value(mrb_fixnum(x) == mrb_fixnum(y));
@@ -1062,9 +1042,8 @@ static mrb_value flo_xor(mrb_state *mrb, mrb_value x);
static mrb_value
fix_and(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
bit_op(x, y, and, &);
}
@@ -1079,9 +1058,8 @@ fix_and(mrb_state *mrb, mrb_value x)
static mrb_value
fix_or(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
bit_op(x, y, or, |);
}
@@ -1096,9 +1074,8 @@ fix_or(mrb_state *mrb, mrb_value x)
static mrb_value
fix_xor(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
bit_op(x, y, or, ^);
}
@@ -1320,9 +1297,8 @@ mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y)
static mrb_value
fix_plus(mrb_state *mrb, mrb_value self)
{
- mrb_value other;
+ mrb_value other = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &other);
return fixnum_plus(mrb, self, other);
}
@@ -1378,9 +1354,8 @@ mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y)
static mrb_value
fix_minus(mrb_state *mrb, mrb_value self)
{
- mrb_value other;
+ mrb_value other = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &other);
return fixnum_minus(mrb, self, other);
}
@@ -1497,10 +1472,9 @@ cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
static mrb_value
integral_cmp(mrb_state *mrb, mrb_value self)
{
- mrb_value other;
+ mrb_value other = mrb_get_arg1(mrb);
mrb_int n;
- mrb_get_args(mrb, "o", &other);
n = cmpnum(mrb, self, other);
if (n == -2) return mrb_nil_value();
return mrb_fixnum_value(n);
@@ -1515,10 +1489,9 @@ cmperr(mrb_state *mrb, mrb_value v1, mrb_value v2)
static mrb_value
integral_lt(mrb_state *mrb, mrb_value self)
{
- mrb_value other;
+ mrb_value other = mrb_get_arg1(mrb);
mrb_int n;
- mrb_get_args(mrb, "o", &other);
n = cmpnum(mrb, self, other);
if (n == -2) cmperr(mrb, self, other);
if (n < 0) return mrb_true_value();
@@ -1528,10 +1501,9 @@ integral_lt(mrb_state *mrb, mrb_value self)
static mrb_value
integral_le(mrb_state *mrb, mrb_value self)
{
- mrb_value other;
+ mrb_value other = mrb_get_arg1(mrb);
mrb_int n;
- mrb_get_args(mrb, "o", &other);
n = cmpnum(mrb, self, other);
if (n == -2) cmperr(mrb, self, other);
if (n <= 0) return mrb_true_value();
@@ -1541,10 +1513,9 @@ integral_le(mrb_state *mrb, mrb_value self)
static mrb_value
integral_gt(mrb_state *mrb, mrb_value self)
{
- mrb_value other;
+ mrb_value other = mrb_get_arg1(mrb);
mrb_int n;
- mrb_get_args(mrb, "o", &other);
n = cmpnum(mrb, self, other);
if (n == -2) cmperr(mrb, self, other);
if (n > 0) return mrb_true_value();
@@ -1554,10 +1525,9 @@ integral_gt(mrb_state *mrb, mrb_value self)
static mrb_value
integral_ge(mrb_state *mrb, mrb_value self)
{
- mrb_value other;
+ mrb_value other = mrb_get_arg1(mrb);
mrb_int n;
- mrb_get_args(mrb, "o", &other);
n = cmpnum(mrb, self, other);
if (n == -2) cmperr(mrb, self, other);
if (n >= 0) return mrb_true_value();
@@ -1609,9 +1579,8 @@ num_infinite_p(mrb_state *mrb, mrb_value self)
static mrb_value
flo_plus(mrb_state *mrb, mrb_value x)
{
- mrb_value y;
+ mrb_value y = mrb_get_arg1(mrb);
- mrb_get_args(mrb, "o", &y);
return mrb_float_value(mrb, mrb_float(x) + mrb_to_flo(mrb, y));
}
#endif