VALUE cbasic_subs(int argc, VALUE *argv, VALUE self) { basic_struct *this, *cresult; cresult = basic_new_heap(); VALUE val_a, val_b; Data_Get_Struct(self, basic_struct, this); rb_scan_args(argc, argv, "11", &val_a, &val_b); // 1 mandatory and 1 optional parameter if (argc == 1) { Check_Type(val_a, T_HASH); CMapBasicBasic *cmapbb = mapbasicbasic_new(); VALUE mapbb = Data_Wrap_Struct(rb_cObject, NULL, mapbasicbasic_free, cmapbb); rb_hash_foreach(val_a, insert_entries, mapbb); basic_subs(cresult, this, cmapbb); } else { basic a, b; basic_new_stack(a); basic_new_stack(b); sympify(val_a, a); sympify(val_b, b); basic_subs2(cresult, this, a, b); basic_free_stack(a); basic_free_stack(b); } return Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, cresult); }
VALUE function_twoarg( symengine_exceptions_t (*cwfunc_ptr)(basic_struct *, const basic_struct *, const basic_struct *), VALUE operand1, VALUE operand2) { basic_struct *cresult; VALUE result = Qnil; basic cbasic_operand1; basic_new_stack(cbasic_operand1); sympify(operand1, cbasic_operand1); basic cbasic_operand2; basic_new_stack(cbasic_operand2); sympify(operand2, cbasic_operand2); cresult = basic_new_heap(); symengine_exceptions_t error_code = cwfunc_ptr(cresult, cbasic_operand1, cbasic_operand2); if (error_code == SYMENGINE_NO_EXCEPTION) { result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL, cbasic_free_heap, cresult); basic_free_stack(cbasic_operand1); basic_free_stack(cbasic_operand2); } else { basic_free_stack(cbasic_operand1); basic_free_stack(cbasic_operand2); raise_exception(error_code); } return result; }
int insert_entries(VALUE key, VALUE val, VALUE input) { CMapBasicBasic *cmapbb; Data_Get_Struct(input, CMapBasicBasic, cmapbb); basic ckey, cval; basic_new_stack(ckey); basic_new_stack(cval); sympify(key, ckey); sympify(val, cval); mapbasicbasic_insert(cmapbb, ckey, cval); basic_free_stack(ckey); basic_free_stack(cval); }
VALUE crealdouble_to_float(VALUE self) { VALUE result; basic cbasic_operand1; basic_new_stack(cbasic_operand1); sympify(self, cbasic_operand1); result = rb_float_new(real_double_get_d(cbasic_operand1)); basic_free_stack(cbasic_operand1); return result; }
VALUE cbasic_eq(VALUE self, VALUE operand2) { basic_struct *this; basic cbasic_operand2; basic_new_stack(cbasic_operand2); Data_Get_Struct(self, basic_struct, this); sympify(operand2, cbasic_operand2); VALUE ret_val = basic_eq(this, cbasic_operand2) ? Qtrue : Qfalse; basic_free_stack(cbasic_operand2); return ret_val; }
VALUE cbasic_binary_op(VALUE self, VALUE operand2, void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*)) { basic_struct *this, *cresult; VALUE result; basic cbasic_operand2; basic_new_stack(cbasic_operand2); Data_Get_Struct(self, basic_struct, this); sympify(operand2, cbasic_operand2); cresult = basic_new_heap(); cwfunc_ptr(cresult, this, cbasic_operand2); result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); basic_free_stack(cbasic_operand2); return result; }
VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2){ basic_struct *cresult; VALUE result; basic cbasic_operand1; basic_new_stack(cbasic_operand1); sympify(operand1, cbasic_operand1); unsigned long cbasic_operand2; cbasic_operand2 = NUM2ULONG(operand2); cresult = basic_new_heap(); ntheory_binomial(cresult, cbasic_operand1, cbasic_operand2); result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); basic_free_stack(cbasic_operand1); return result; }
VALUE cbasic_diff(VALUE self, VALUE operand2) { basic_struct *this, *cresult; VALUE result; basic cbasic_operand2; basic_new_stack(cbasic_operand2); Data_Get_Struct(self, basic_struct, this); sympify(operand2, cbasic_operand2); cresult = basic_new_heap(); int status = basic_diff(cresult, this, cbasic_operand2); if (status == 0) { basic_free_stack(cbasic_operand2); basic_free_heap(cresult); return Qnil; } result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); basic_free_stack(cbasic_operand2); return result; }
VALUE check_sympify(VALUE operand2, basic_struct *cbasic_operand2) { basic_struct *temp; VALUE a, b; double f; switch (TYPE(operand2)) { case T_FIXNUM: case T_BIGNUM: get_symintfromval(operand2, cbasic_operand2); break; case T_FLOAT: f = RFLOAT_VALUE(operand2); real_double_set_d(cbasic_operand2, f); break; case T_RATIONAL: a = rb_funcall(operand2, rb_intern("numerator"), 0, NULL); b = rb_funcall(operand2, rb_intern("denominator"), 0, NULL); basic num_basic, den_basic; basic_new_stack(num_basic); basic_new_stack(den_basic); get_symintfromval(a, num_basic); get_symintfromval(b, den_basic); rational_set(cbasic_operand2, num_basic, den_basic); basic_free_stack(num_basic); basic_free_stack(den_basic); break; case T_COMPLEX: a = rb_funcall(operand2, rb_intern("real"), 0, NULL); b = rb_funcall(operand2, rb_intern("imaginary"), 0, NULL); basic real_basic; basic imag_basic; basic_new_stack(real_basic); basic_new_stack(imag_basic); sympify(a, real_basic); sympify(b, imag_basic); basic_const_I(cbasic_operand2); basic_mul(cbasic_operand2, cbasic_operand2, imag_basic); basic_add(cbasic_operand2, cbasic_operand2, real_basic); basic_free_stack(real_basic); basic_free_stack(imag_basic); break; case T_DATA: if (rb_obj_is_kind_of(operand2, c_basic)) { Data_Get_Struct(operand2, basic_struct, temp); basic_assign(cbasic_operand2, temp); break; } #ifdef HAVE_SYMENGINE_MPFR if (strcmp(rb_obj_classname(operand2), "BigDecimal") == 0) { const char *c; c = RSTRING_PTR(rb_funcall(operand2, rb_intern("to_s"), 1, rb_str_new2("F"))); real_mpfr_set_str(cbasic_operand2, c, 200); break; } #endif // HAVE_SYMENGINE_MPFR default: return Qfalse; } return Qtrue; }