VALUE cbasic_coerce(VALUE self, VALUE other) { basic_struct *cbasic_operand2; cbasic_operand2 = basic_new_heap(); sympify(other, cbasic_operand2); VALUE new_other = Data_Wrap_Struct(Klass_of_Basic(cbasic_operand2), NULL , cbasic_free_heap, cbasic_operand2); return rb_assoc_new(new_other, self); }
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; }
VALUE cbasic_unary_op(VALUE self, void (*cwfunc_ptr)(basic_struct*, const basic_struct*)) { basic_struct *this, *cresult; VALUE result; Data_Get_Struct(self, basic_struct, this); cresult = basic_new_heap(); cwfunc_ptr(cresult, this); result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); return result; }
VALUE cntheory_lucas(VALUE self, VALUE operand1){ basic_struct *cresult; VALUE result; unsigned long cbasic_operand1; cbasic_operand1 = NUM2ULONG(operand1); cresult = basic_new_heap(); ntheory_lucas(cresult, cbasic_operand1); result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); return result; }
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; }