示例#1
0
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);
}
示例#2
0
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);
}
示例#3
0
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;
}
示例#4
0
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;
}
示例#5
0
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;
}
示例#6
0
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;
}
示例#7
0
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;
}
示例#8
0
VALUE cbasic_free_symbols(VALUE self) {
    basic_struct *this, *iterator_basic;
    CSetBasic *symbols = setbasic_new();
    int size = 0;

    Data_Get_Struct(self, basic_struct, this);
    basic_free_symbols(this, symbols);

    size = setbasic_size(symbols);
    VALUE ruby_array = rb_ary_new2(size);
    int i = 0;
    VALUE temp = NULL;
    for(i = 0; i < size; i++) {
        basic_struct *temp_basic = basic_new_heap();
        setbasic_get(symbols, i, temp_basic);
        temp = Data_Wrap_Struct(rb_obj_class(self), NULL , cbasic_free_heap, temp_basic);
        rb_ary_push(ruby_array, temp);
    }
    setbasic_free(symbols);
    return ruby_array;
}
示例#9
0
VALUE cbasic_get_args(VALUE self) {
    basic_struct *this, *iterator_basic;
    CVecBasic *args = vecbasic_new();
    int size = 0;

    Data_Get_Struct(self, basic_struct, this);
    basic_get_args(this, args);

    size = vecbasic_size(args);
    VALUE ruby_array = rb_ary_new2(size);
    int i = 0;
    VALUE temp = NULL;
    for(i = 0; i < size; i++) {
        basic_struct *temp_basic = basic_new_heap();
        vecbasic_get(args, i, temp_basic);
        temp = Data_Wrap_Struct(rb_obj_class(self), NULL , cbasic_free_heap, temp_basic);
        rb_ary_push(ruby_array, temp);
    }
    vecbasic_free(args);
    return ruby_array;
}
示例#10
0
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;
}
示例#11
0
VALUE cbasic_alloc(VALUE klass) {
    basic_struct *struct_ptr = basic_new_heap();
    return Data_Wrap_Struct(klass, NULL, cbasic_free_heap, struct_ptr);
}