Add a few new API for complex access.

parent c6149370
...@@ -67,8 +67,17 @@ complex_ptr(mrb_state *mrb, mrb_value v) ...@@ -67,8 +67,17 @@ complex_ptr(mrb_state *mrb, mrb_value v)
} }
#endif #endif
static mrb_value void
complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary) mrb_complex_get(mrb_state *mrb, mrb_value cpx, mrb_float *r, mrb_float *i)
{
struct mrb_complex *c = complex_ptr(mrb, cpx);
*r = c->real;
*i = c->imaginary;
}
mrb_value
mrb_complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
{ {
struct RClass *c = mrb_class_get_id(mrb, MRB_SYM(Complex)); struct RClass *c = mrb_class_get_id(mrb, MRB_SYM(Complex));
struct mrb_complex *p; struct mrb_complex *p;
...@@ -80,6 +89,8 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary) ...@@ -80,6 +89,8 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
return mrb_obj_value(comp); return mrb_obj_value(comp);
} }
#define complex_new(mrb, real, imag) mrb_complex_new(mrb, real, imag)
static mrb_value static mrb_value
complex_real(mrb_state *mrb, mrb_value self) complex_real(mrb_state *mrb, mrb_value self)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment