コード例 #1
0
ファイル: basemath.c プロジェクト: bitwize/rscheme
static obj complex_mul( cmplx a_r, cmplx b_r )
{
    obj a = a_r.re;
    obj b = a_r.im;
    obj c = b_r.re;
    obj d = b_r.im;

    obj re = basic_minus( basic_mul( a, c ), basic_mul( b, d ) );
    obj im = basic_plus( basic_mul( a, d ), basic_mul( c, b ) );

    RETURN_COMPLEX(re,im);
}
コード例 #2
0
ファイル: basemath.c プロジェクト: bitwize/rscheme
static _rs_inline obj complex_div( cmplx a, cmplx b )
{
    obj cd = basic_plus(basic_mul(b.re, b.re), basic_mul(b.im, b.im));
    obj re = basic_div(basic_plus(basic_mul(a.re, b.re), basic_mul(a.im, b.im)), cd);
    obj im = basic_div(basic_minus(basic_mul(a.im, b.re), basic_mul(a.re, b.im)), cd);
    RETURN_COMPLEX(re,im);
}
コード例 #3
0
ファイル: test_cwrapper.c プロジェクト: Upabjojr/symengine
void test_cwrapper() {
    char* s;
    basic x, y, z;
    basic_init(x);
    basic_init(y);
    basic_init(z);
    symbol_set(x, "x");
    symbol_set(y, "y");
    symbol_set(z, "z");

    s = basic_str(x);
    printf("Symbol : %s\n", s);
    basic_str_free(s);
    basic e;
    basic_init(e);

    integer_set_ui(e, 123);
    s = basic_str(e);
    printf("Integer : %s\n", s);
    basic_str_free(s);

    integer_set_ui(e, 456);
    basic_add(e, e, x);
    basic_mul(e, e, y);
    basic_div(e, e, z);
    s = basic_str(e);
    printf("Basic : %s\n", s);
    basic_str_free(s);

    basic_diff(e, e, z);
    s = basic_str(e);
    printf("Basic : %s\n", s);
    basic_str_free(s);

    rational_set_ui(e, 100, 47);
    s = basic_str(e);

    printf("Rational : %s\n", s);
    printf("Is_a_Symbol %s: %d\n", s, is_a_Symbol(e));
    printf("Is_a_Rational %s: %d\n", s, is_a_Rational(e));
    printf("Is_a_Integer %s: %d\n", s, is_a_Integer(e));

    integer_set_ui(e, 123);
    printf("integer_get_ui 123: %lu\n", integer_get_ui(e));

    integer_set_si(e, -123);
    printf("integer_get_si -123: %ld\n", integer_get_si(e));

    mpz_t test;
    mpz_init(test);

    integer_get_mpz(test, e);
    printf("integer_get_mpz(e): %ld\n", mpz_get_ui(test));

    mpz_clear(test);
    basic_free(e);
    basic_free(x);
    basic_free(y);
    basic_free(z);
    basic_str_free(s);
}
コード例 #4
0
ファイル: basemath.c プロジェクト: bitwize/rscheme
static _rs_inline obj complex_abs( cmplx a )
{
    return basic_plus( basic_mul( a.re, a.re ), basic_mul( a.im, a.im ) );
}
コード例 #5
0
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;
}