ext/gsl_native/complex.c in gsl-2.1.0.1 vs ext/gsl_native/complex.c in gsl-2.1.0.2

- old
+ new

@@ -39,10 +39,15 @@ vre = rb_ary_entry(obj,0); vim = rb_ary_entry(obj,1); if (!NIL_P(vre)) GSL_SET_REAL(z, NUM2DBL(vre)); if (!NIL_P(vim)) GSL_SET_IMAG(z, NUM2DBL(vim)); break; + case T_COMPLEX: + vre = rb_funcall(obj, rb_intern("real"), 0); + vim = rb_funcall(obj, rb_intern("imag"), 0); + *z = gsl_complex_rect(NUM2DBL(vre), NUM2DBL(vim)); + break; case T_FLOAT: case T_FIXNUM: case T_BIGNUM: *z = gsl_complex_rect(NUM2DBL(obj), 0.0); break; @@ -61,16 +66,21 @@ } static VALUE rb_gsl_complex_new(int argc, VALUE *argv, VALUE klass) { gsl_complex *c = NULL; - VALUE obj; + VALUE obj, vre, vim; obj = Data_Make_Struct(klass, gsl_complex, 0, free, c); switch (argc) { case 1: switch (TYPE(argv[0])) { case T_ARRAY: *c = ary2complex(argv[0]); + break; + case T_COMPLEX: + vre = rb_funcall(argv[0], rb_intern("real"), 0); + vim = rb_funcall(argv[0], rb_intern("imag"), 0); + *c = gsl_complex_rect(NUM2DBL(vre), NUM2DBL(vim)); break; case T_FLOAT: case T_FIXNUM: case T_BIGNUM: Need_Float(argv[0]);