Skip to content

Commit 90cbfec

Browse files
committed
BigDecimal to RealMPFR
1 parent 9cdab35 commit 90cbfec

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

ext/symengine/ruby_real_mpfr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ VALUE crealmpfr_init(VALUE self, VALUE num_value, VALUE prec_value) {
1717
c = RSTRING_PTR(num_value);
1818
real_mpfr_set_str(cresult, c, prec);
1919
break;
20+
case T_DATA:
21+
c = rb_obj_classname(num_value);
22+
if(strcmp(c, "BigDecimal") == 0){
23+
c = RSTRING_PTR( rb_funcall(num_value, rb_intern("to_s"), 1, rb_str_new2("F")) );
24+
real_mpfr_set_str(cresult, c, prec);
25+
break;
26+
}
2027
default:
2128
rb_raise(rb_eTypeError, "Invalid Type: Float, BigDecimal or String required.");
2229
break;

ext/symengine/symengine_utils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ void sympify(VALUE operand2, basic_struct *cbasic_operand2) {
6161
break;
6262

6363
case T_DATA:
64+
c = rb_obj_classname(operand2);
65+
if(strcmp(c, "BigDecimal") == 0){
66+
c = RSTRING_PTR( rb_funcall(operand2, rb_intern("to_s"), 1, rb_str_new2("F")) );
67+
real_mpfr_set_str(cbasic_operand2, c, 200);
68+
break;
69+
}
70+
6471
Data_Get_Struct(operand2, basic_struct, temp);
6572
basic_assign(cbasic_operand2, temp);
6673
break;
67-
68-
case T_OBJECT:
69-
a = rb_funcall(operand2, rb_intern("class"), 0, NULL);
70-
b = rb_funcall(a, rb_intern("to_s"), 0, NULL);
71-
*c = RSTRING_PTR( b );
72-
printf("%s\n", c);
73-
break;
7474
}
7575
}
7676

0 commit comments

Comments
 (0)