diff options
Diffstat (limited to 'mrbgems/mruby-complex/src')
| -rw-r--r-- | mrbgems/mruby-complex/src/complex.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c index fe66e0e37..66176c3c1 100644 --- a/mrbgems/mruby-complex/src/complex.c +++ b/mrbgems/mruby-complex/src/complex.c @@ -2,7 +2,6 @@ #include <mruby/class.h> #include <mruby/numeric.h> #include <mruby/presym.h> -#include <math.h> #ifdef MRB_NO_FLOAT # error Complex conflicts with 'MRB_NO_FLOAT' configuration @@ -50,7 +49,7 @@ static struct RBasic* complex_alloc(mrb_state *mrb, struct RClass *c, struct mrb_complex **p) { struct RComplex *s; - s = (struct RComplex*)mrb_obj_alloc(mrb, MRB_TT_COMPLEX, c); + s = MRB_OBJ_ALLOC(mrb, MRB_TT_COMPLEX, c); #ifdef COMPLEX_INLINE *p = &s->r; #else @@ -184,7 +183,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 +204,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 +226,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 +268,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 +280,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 +351,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 +376,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 +390,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); } } @@ -429,10 +424,10 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb) mrb_define_method(mrb, comp, "/", complex_div, MRB_ARGS_REQ(1)); mrb_define_method(mrb, comp, "quo", complex_div, MRB_ARGS_REQ(1)); mrb_define_method(mrb, comp, "==", complex_eq, MRB_ARGS_REQ(1)); - mrb_define_method(mrb, mrb->integer_class, "/", cpx_int_div, MRB_ARGS_REQ(1)); /* overrride */ - mrb_define_method(mrb, mrb->integer_class, "quo", cpx_int_quo, MRB_ARGS_REQ(1)); /* overrride */ - mrb_define_method(mrb, mrb->float_class, "/", cpx_flo_div, MRB_ARGS_REQ(1)); /* overrride */ - mrb_define_method(mrb, mrb->float_class, "quo", cpx_flo_div, MRB_ARGS_REQ(1)); /* overrride */ + mrb_define_method(mrb, mrb->integer_class, "/", cpx_int_div, MRB_ARGS_REQ(1)); /* override */ + mrb_define_method(mrb, mrb->integer_class, "quo", cpx_int_quo, MRB_ARGS_REQ(1)); /* override */ + mrb_define_method(mrb, mrb->float_class, "/", cpx_flo_div, MRB_ARGS_REQ(1)); /* override */ + mrb_define_method(mrb, mrb->float_class, "quo", cpx_flo_div, MRB_ARGS_REQ(1)); /* override */ } void |
