summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/mruby-complex/src/complex.c24
-rw-r--r--mrbgems/mruby-io/src/file.c2
-rw-r--r--mrbgems/mruby-io/src/io.c4
-rw-r--r--mrbgems/mruby-kernel-ext/src/kernel.c8
-rw-r--r--mrbgems/mruby-numeric-ext/src/numeric_ext.c6
-rw-r--r--mrbgems/mruby-pack/src/pack.c2
-rw-r--r--mrbgems/mruby-rational/src/rational.c42
-rw-r--r--mrbgems/mruby-sprintf/src/sprintf.c8
-rw-r--r--mrbgems/mruby-string-ext/src/string.c2
-rw-r--r--mrbgems/mruby-struct/src/struct.c4
10 files changed, 47 insertions, 55 deletions
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c
index fe66e0e37..447a8f9c0 100644
--- a/mrbgems/mruby-complex/src/complex.c
+++ b/mrbgems/mruby-complex/src/complex.c
@@ -184,7 +184,7 @@ complex_add(mrb_state *mrb, mrb_value x)
default:
{
- mrb_float z = mrb_to_flo(mrb, y);
+ mrb_float z = mrb_as_float(mrb, y);
return mrb_complex_new(mrb, p1->real+z, p1->imaginary);
}
}
@@ -205,7 +205,7 @@ complex_sub(mrb_state *mrb, mrb_value x)
default:
{
- mrb_float z = mrb_to_flo(mrb, y);
+ mrb_float z = mrb_as_float(mrb, y);
return mrb_complex_new(mrb, p1->real-z, p1->imaginary);
}
}
@@ -227,16 +227,12 @@ complex_mul(mrb_state *mrb, mrb_value x)
default:
{
- mrb_float z = mrb_to_flo(mrb, y);
+ mrb_float z = mrb_as_float(mrb, y);
return mrb_complex_new(mrb, p1->real*z, p1->imaginary*z);
}
}
}
-#ifndef MRB_NO_FLOAT
-mrb_float mrb_div_flo(mrb_float, mrb_float);
-#endif
-
/* Arithmetic on (significand, exponent) pairs avoids premature overflow in
complex division */
struct float_pair {
@@ -273,7 +269,7 @@ static void
div_pair(struct float_pair *q, struct float_pair const *a,
struct float_pair const *b)
{
- q->s = mrb_div_flo(a->s, b->s);
+ q->s = mrb_div_float(a->s, b->s);
q->x = a->x - b->x;
}
@@ -285,8 +281,8 @@ 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, mrb_div_flo(a->real, f), mrb_div_flo(a->imaginary, f));
+ mrb_float f = mrb_as_float(mrb, rhs);
+ return complex_new(mrb, mrb_div_float(a->real, f), mrb_div_float(a->imaginary, f));
}
struct float_pair ar, ai, br, bi;
@@ -356,7 +352,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, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_float((mrb_float)a, mrb_as_float(mrb, y)));
}
}
@@ -381,7 +377,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, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_float((mrb_float)a, mrb_as_float(mrb, y)));
}
}
@@ -395,10 +391,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 = mrb_div_flo(a, mrb_float(y));
+ a = mrb_div_float(a, mrb_float(y));
return mrb_float_value(mrb, a);
default:
- a = mrb_div_flo(a, mrb_to_flo(mrb, y));
+ a = mrb_div_float(a, mrb_as_float(mrb, y));
return mrb_float_value(mrb, a);
}
}
diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c
index 03a6a070d..b9e1eca03 100644
--- a/mrbgems/mruby-io/src/file.c
+++ b/mrbgems/mruby-io/src/file.c
@@ -497,7 +497,7 @@ mrb_file_truncate(mrb_state *mrb, mrb_value self)
mrb_value lenv = mrb_get_arg1(mrb);
fd = mrb_io_fileno(mrb, self);
- length = mrb_int(mrb, lenv);
+ length = mrb_as_int(mrb, lenv);
if (mrb_ftruncate(fd, length) != 0) {
mrb_raise(mrb, E_IO_ERROR, "ftruncate failed");
}
diff --git a/mrbgems/mruby-io/src/io.c b/mrbgems/mruby-io/src/io.c
index 234d7b1fc..0c79660a8 100644
--- a/mrbgems/mruby-io/src/io.c
+++ b/mrbgems/mruby-io/src/io.c
@@ -169,7 +169,7 @@ mrb_io_mode_to_flags(mrb_state *mrb, mrb_value mode)
}
else {
int flags = 0;
- mrb_int flags0 = mrb_int(mrb, mode);
+ mrb_int flags0 = mrb_as_int(mrb, mode);
switch (flags0 & MRB_O_ACCMODE) {
case MRB_O_RDONLY:
@@ -1415,7 +1415,7 @@ mrb_io_sync(mrb_state *mrb, mrb_value self)
static off_t
value2off(mrb_state *mrb, mrb_value offv)
{
- return (off_t)mrb_int(mrb, offv);
+ return (off_t)mrb_as_int(mrb, offv);
}
/*
diff --git a/mrbgems/mruby-kernel-ext/src/kernel.c b/mrbgems/mruby-kernel-ext/src/kernel.c
index 7afa6fa5f..ec5dc4a5e 100644
--- a/mrbgems/mruby-kernel-ext/src/kernel.c
+++ b/mrbgems/mruby-kernel-ext/src/kernel.c
@@ -32,7 +32,7 @@ mrb_f_caller(mrb_state *mrb, mrb_value self)
}
}
else {
- lev = mrb_int(mrb, v);
+ lev = mrb_as_int(mrb, v);
if (lev < 0) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative level (%v)", v);
}
@@ -40,8 +40,8 @@ mrb_f_caller(mrb_state *mrb, mrb_value self)
}
break;
case 2:
- lev = mrb_int(mrb, v);
- n = mrb_int(mrb, length);
+ lev = mrb_as_int(mrb, v);
+ n = mrb_as_int(mrb, length);
if (lev < 0) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative level (%v)", v);
}
@@ -131,7 +131,7 @@ mrb_f_float(mrb_state *mrb, mrb_value self)
{
mrb_value arg = mrb_get_arg1(mrb);
- return mrb_Float(mrb, arg);
+ return mrb_to_float(mrb, arg);
}
#endif
diff --git a/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/mrbgems/mruby-numeric-ext/src/numeric_ext.c
index dbc7f39d9..00b13174f 100644
--- a/mrbgems/mruby-numeric-ext/src/numeric_ext.c
+++ b/mrbgems/mruby-numeric-ext/src/numeric_ext.c
@@ -15,7 +15,7 @@ mrb_int_allbits(mrb_state *mrb, mrb_value self)
mrb_int n, m;
mrb_get_args(mrb, "i", &m);
- n = mrb_int(mrb, self);
+ n = mrb_as_int(mrb, self);
return mrb_bool_value((n & m) == m);
}
@@ -31,7 +31,7 @@ mrb_int_anybits(mrb_state *mrb, mrb_value self)
mrb_int n, m;
mrb_get_args(mrb, "i", &m);
- n = mrb_int(mrb, self);
+ n = mrb_as_int(mrb, self);
return mrb_bool_value((n & m) != 0);
}
@@ -47,7 +47,7 @@ mrb_int_nobits(mrb_state *mrb, mrb_value self)
mrb_int n, m;
mrb_get_args(mrb, "i", &m);
- n = mrb_int(mrb, self);
+ n = mrb_as_int(mrb, self);
return mrb_bool_value((n & m) == 0);
}
diff --git a/mrbgems/mruby-pack/src/pack.c b/mrbgems/mruby-pack/src/pack.c
index 9b462b1b8..bdcd262da 100644
--- a/mrbgems/mruby-pack/src/pack.c
+++ b/mrbgems/mruby-pack/src/pack.c
@@ -1205,7 +1205,7 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary)
#ifndef MRB_NO_FLOAT
else if (type == PACK_TYPE_FLOAT) {
if (!mrb_float_p(o)) {
- mrb_float f = mrb_to_flo(mrb, o);
+ mrb_float f = mrb_as_float(mrb, o);
o = mrb_float_value(mrb, f);
}
}
diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c
index 0e3581f9a..15189dd88 100644
--- a/mrbgems/mruby-rational/src/rational.c
+++ b/mrbgems/mruby-rational/src/rational.c
@@ -255,20 +255,20 @@ rational_s_new(mrb_state *mrb, mrb_value self)
}
else {
mrb_float numf = (mrb_float)numerator;
- mrb_float denomf = mrb_to_flo(mrb, denomv);
+ mrb_float denomf = mrb_as_float(mrb, denomv);
return rational_new_f(mrb, numf/denomf);
}
}
else {
- mrb_float numf = mrb_to_flo(mrb, numv);
+ mrb_float numf = mrb_as_float(mrb, numv);
mrb_float denomf;
if (mrb_integer_p(denomv)) {
denomf = (mrb_float)mrb_integer(denomv);
}
else {
- denomf = mrb_to_flo(mrb, denomv);
+ denomf = mrb_as_float(mrb, denomv);
}
return rational_new_f(mrb, numf/denomf);
}
@@ -278,7 +278,7 @@ rational_s_new(mrb_state *mrb, mrb_value self)
#ifndef MRB_NO_FLOAT
static mrb_float
-rat_to_flo(struct mrb_rational *p)
+rat_float(struct mrb_rational *p)
{
mrb_float f;
@@ -296,7 +296,7 @@ static mrb_value
rational_to_f(mrb_state *mrb, mrb_value self)
{
struct mrb_rational *p = rational_ptr(mrb, self);
- return mrb_float_value(mrb, rat_to_flo(p));
+ return mrb_float_value(mrb, rat_float(p));
}
#endif
@@ -346,8 +346,8 @@ rational_m(mrb_state *mrb, mrb_value self)
return rational_new_i(mrb, mrb_integer(a), mrb_integer(b));
}
else {
- mrb_float x = mrb_to_flo(mrb, a);
- mrb_float y = mrb_to_flo(mrb, b);
+ mrb_float x = mrb_as_float(mrb, a);
+ mrb_float y = mrb_as_float(mrb, b);
return rational_new_f(mrb, x/y);
}
#endif
@@ -436,7 +436,7 @@ rational_cmp(mrb_state *mrb, mrb_value x)
#ifndef MRB_NO_FLOAT
case MRB_TT_FLOAT:
{
- mrb_float a = rat_to_flo(p1), b = mrb_to_flo(mrb, y);
+ mrb_float a = rat_float(p1), b = mrb_as_float(mrb, y);
if (a > b)
return mrb_fixnum_value(1);
else if (a < b)
@@ -458,7 +458,7 @@ rational_cmp(mrb_state *mrb, mrb_value x)
#endif
#ifdef MRB_USE_COMPLEX
case MRB_TT_COMPLEX:
- x = mrb_complex_new(mrb, rat_to_flo(p1), 0);
+ x = mrb_complex_new(mrb, rat_float(p1), 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(cmp), 1, y);
#endif
default:
@@ -480,10 +480,6 @@ rational_minus(mrb_state *mrb, mrb_value x)
return rational_new(mrb, -n, p->denominator);
}
-#ifndef MRB_NO_FLOAT
-mrb_float mrb_div_flo(mrb_float, mrb_float);
-#endif
-
static mrb_value
rational_add(mrb_state *mrb, mrb_value x)
{
@@ -514,7 +510,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_div_flo(z, (mrb_float)p1->denominator));
+ return mrb_float_value(mrb, mrb_div_float(z, (mrb_float)p1->denominator));
}
#endif
@@ -551,7 +547,7 @@ rational_sub(mrb_state *mrb, mrb_value x)
#if defined(MRB_USE_COMPLEX)
case MRB_TT_COMPLEX:
- x = mrb_complex_new(mrb, rat_to_flo(p1), 0);
+ x = mrb_complex_new(mrb, rat_float(p1), 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(sub), 1, y);
#endif
@@ -559,8 +555,8 @@ rational_sub(mrb_state *mrb, mrb_value x)
case MRB_TT_FLOAT:
default:
{
- mrb_float z = p1->numerator - mrb_to_flo(mrb, y) * p1->denominator;
- return mrb_float_value(mrb, mrb_div_flo(z, (mrb_float)p1->denominator));
+ mrb_float z = p1->numerator - mrb_as_float(mrb, y) * p1->denominator;
+ return mrb_float_value(mrb, mrb_div_float(z, (mrb_float)p1->denominator));
}
#else
default:
@@ -596,7 +592,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_div_flo(z, (mrb_float)p1->denominator));
+ return mrb_float_value(mrb, mrb_div_float(z, (mrb_float)p1->denominator));
}
#endif
@@ -630,7 +626,7 @@ mrb_rational_div(mrb_state *mrb, mrb_value x)
#if defined(MRB_USE_COMPLEX)
case MRB_TT_COMPLEX:
- x = mrb_complex_new(mrb, rat_to_flo(p1), 0);
+ x = mrb_complex_new(mrb, rat_float(p1), 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
#endif
@@ -638,8 +634,8 @@ mrb_rational_div(mrb_state *mrb, mrb_value x)
#ifndef MRB_NO_FLOAT
case MRB_TT_FLOAT:
{
- mrb_float z = mrb_div_flo((mrb_float)p1->numerator, mrb_to_flo(mrb, y));
- return mrb_float_value(mrb, mrb_div_flo(z, (mrb_float)p1->denominator));
+ mrb_float z = mrb_div_float((mrb_float)p1->numerator, mrb_as_float(mrb, y));
+ return mrb_float_value(mrb, mrb_div_float(z, (mrb_float)p1->denominator));
}
#else
mrb_raise(mrb, E_TYPE_ERROR, "non integer division");
@@ -673,7 +669,7 @@ rational_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_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_float((mrb_float)a, mrb_as_float(mrb, y)));
#endif
}
}
@@ -700,7 +696,7 @@ rational_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_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_float((mrb_float)a, mrb_as_float(mrb, y)));
#endif
}
}
diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c
index 1a3b10957..3fd052d5d 100644
--- a/mrbgems/mruby-sprintf/src/sprintf.c
+++ b/mrbgems/mruby-sprintf/src/sprintf.c
@@ -230,7 +230,7 @@ check_name_arg(mrb_state *mrb, int posarg, const char *name, size_t len)
tmp_v = GETNEXTARG(); \
p = t; \
} \
- num = mrb_int(mrb, tmp_v); \
+ num = mrb_as_int(mrb, tmp_v); \
} while (0)
static const char *
@@ -908,8 +908,8 @@ retry:
v = mrb_integer(val);
break;
default:
- val = mrb_Integer(mrb, val);
- goto bin_retry;
+ v = mrb_as_int(mrb, val);
+ break;
}
switch (*p) {
@@ -1060,7 +1060,7 @@ retry:
mrb_int need = 6;
char fbuf[64];
- fval = mrb_float(mrb_Float(mrb, val));
+ fval = mrb_as_float(mrb, val);
if (!isfinite(fval)) {
const char *expr;
const mrb_int elen = 3;
diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c
index 3a9926525..158cb5193 100644
--- a/mrbgems/mruby-string-ext/src/string.c
+++ b/mrbgems/mruby-string-ext/src/string.c
@@ -35,7 +35,7 @@ str_casecmp_p(const char *s1, mrb_int len1, const char *s2, mrb_int len2)
static mrb_value
int_chr_binary(mrb_state *mrb, mrb_value num)
{
- mrb_int cp = mrb_int(mrb, num);
+ mrb_int cp = mrb_as_int(mrb, num);
char c;
mrb_value str;
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c
index 54afefd74..df76d7a33 100644
--- a/mrbgems/mruby-struct/src/struct.c
+++ b/mrbgems/mruby-struct/src/struct.c
@@ -435,7 +435,7 @@ mrb_struct_aref(mrb_state *mrb, mrb_value s)
if (mrb_symbol_p(idx)) {
return struct_aref_sym(mrb, s, mrb_symbol(idx));
}
- return struct_aref_int(mrb, s, mrb_int(mrb, idx));
+ return struct_aref_int(mrb, s, mrb_as_int(mrb, idx));
}
static mrb_value
@@ -499,7 +499,7 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
return mrb_struct_aset_sym(mrb, s, mrb_symbol(idx), val);
}
- i = mrb_int(mrb, idx);
+ i = mrb_as_int(mrb, idx);
if (i < 0) i = RSTRUCT_LEN(s) + i;
if (i < 0) {
mrb_raisef(mrb, E_INDEX_ERROR,