ext/nmatrix/data/data.cpp in nmatrix-0.0.6 vs ext/nmatrix/data/data.cpp in nmatrix-0.0.7
- old
+ new
@@ -81,26 +81,30 @@
r = NUM2DBL(rb_funcall(other.rval, rb_intern("real"), 0));
i = NUM2DBL(rb_funcall(other.rval, rb_intern("imag"), 0));
break;
case T_FLOAT:
case T_RATIONAL:
+ case T_FIXNUM:
+ case T_BIGNUM:
r = NUM2DBL(other.rval);
i = 0.0;
break;
default:
rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a complex");
}
}
+
template <typename Type>
Rational<Type>::Rational(const RubyObject& other) {
switch (TYPE(other.rval)) {
case T_RATIONAL:
- n = NUM2LONG(rb_funcall(this->rval, rb_intern("numerator"), 0));
- d = NUM2LONG(rb_funcall(this->rval, rb_intern("denominator"), 0));
+ n = NUM2LONG(rb_funcall(other.rval, rb_intern("numerator"), 0));
+ d = NUM2LONG(rb_funcall(other.rval, rb_intern("denominator"), 0));
break;
case T_FIXNUM:
+ case T_BIGNUM:
n = NUM2LONG(other.rval);
d = 1;
break;
case T_COMPLEX:
case T_FLOAT:
@@ -336,9 +340,18 @@
void* ret_val = ALLOC_N(char, size);
rubyval_to_cval(val, dtype, ret_val);
return ret_val;
+}
+
+void nm_init_data() {
+ nm::RubyObject obj(INT2FIX(1));
+ nm::Rational32 x(obj);
+ nm::Rational64 y(obj);
+ nm::Rational128 z(obj);
+ nm::Complex64 a(obj);
+ nm::Complex128 b(obj);
}
} // end of extern "C" block