Skip to content

Commit 4e26bfd

Browse files
committed
Real Dobule
1 parent 7ddd68e commit 4e26bfd

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

ext/symengine/symengine.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ void Init_symengine() {
6262
rb_define_method(c_integer, "initialize", cinteger_init, 1);
6363
rb_define_method(c_integer, "%", cntheory_mod, 1);
6464

65+
//RealDouble Class
66+
c_real_double = rb_define_class_under(m_symengine, "RealDouble", c_basic);
67+
rb_define_alloc_func(c_double, cbasic_alloc);
68+
6569
//Rational class
6670
c_rational = rb_define_class_under(m_symengine, "Rational", c_basic);
6771
rb_define_alloc_func(c_rational, cbasic_alloc);

ext/symengine/symengine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ VALUE m_symengine;
1010
VALUE c_basic;
1111
VALUE c_symbol;
1212
VALUE c_integer;
13+
VALUE c_real_double;
1314
VALUE c_rational;
1415
VALUE c_complex;
1516
VALUE c_complex_double;

ext/symengine/symengine_utils.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
66
basic_struct *temp;
77
VALUE new_operand2, num, den;
88
VALUE real, imag;
9+
VALUE Rb_Temp_String;
10+
char *s;
911

1012
switch(TYPE(operand2)) {
1113
case T_FIXNUM:
1214
case T_BIGNUM:
1315
GET_SYMINTFROMVAL(operand2, cbasic_operand2);
1416
break;
1517

18+
case T_FLOAT:
19+
Rb_Temp_String = rb_funcall(operand2, rb_intern("to_s"), 0, NULL);
20+
s = StringValueCStr(Rb_Temp_String);
21+
real_double_set_d(this, atof(s));
22+
23+
break;
24+
1625
case T_RATIONAL:
1726
num = rb_funcall(operand2, rb_intern("numerator"), 0, NULL);
1827
den = rb_funcall(operand2, rb_intern("denominator"), 0, NULL);
@@ -66,6 +75,8 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) {
6675
return c_symbol;
6776
case SYMENGINE_INTEGER:
6877
return c_integer;
78+
case SYMENGINE_REAL_DOUBLE:
79+
return c_real_double;
6980
case SYMENGINE_RATIONAL:
7081
return c_rational;
7182
case SYMENGINE_COMPLEX:

0 commit comments

Comments
 (0)