ruby-mpfi 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/Manifest.txt +62 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +48 -0
- data/Rakefile +26 -0
- data/ext/mpfi/extconf.rb +10 -0
- data/ext/mpfi/func_mpfi_extention.c +52 -0
- data/ext/mpfi/func_mpfi_extention.h +2 -0
- data/ext/mpfi/make_c_source.rb +115 -0
- data/ext/mpfi/ruby_mpfi.c +1452 -0
- data/ext/mpfi/ruby_mpfi.h +39 -0
- data/ext/mpfi/ruby_mpfr.h +38 -0
- data/ext/mpfi/yasnippet_mpfi.el +44 -0
- data/ext/mpfi_complex/mpfi/extconf.rb +10 -0
- data/ext/mpfi_complex/mpfi/func_mpfi_extention.h +2 -0
- data/ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.c +130 -0
- data/ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.h +35 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfi.h +39 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfi_complex.c +217 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfi_complex.h +15 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfr.h +38 -0
- data/ext/mpfi_matrix/mpfi/extconf.rb +9 -0
- data/ext/mpfi_matrix/mpfi/func_mpfi_extention.h +2 -0
- data/ext/mpfi_matrix/mpfi/func_mpfi_matrix.c +795 -0
- data/ext/mpfi_matrix/mpfi/func_mpfi_matrix.h +103 -0
- data/ext/mpfi_matrix/mpfi/func_mpfr_matrix.h +72 -0
- data/ext/mpfi_matrix/mpfi/func_ruby_mpfi_complex.h +35 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi.h +39 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_complex.h +15 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c +1200 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.h +13 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfr.h +38 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfr_matrix.h +13 -0
- data/lib/mpfi/matrix.rb +188 -0
- data/lib/mpfi/version.rb +3 -0
- data/ruby-mpfi.gemspec +35 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/mpfi/generate_number_module.rb +48 -0
- data/spec/mpfi/mpfi_alloc_spec.rb +55 -0
- data/spec/mpfi/mpfi_diam_arithmetic_spec.rb +25 -0
- data/spec/mpfi/mpfi_interval_arithmetic_spec.rb +105 -0
- data/spec/mpfi/mpfi_interval_functions_spec.rb +95 -0
- data/spec/mpfi/mpfi_math_functions_spec.rb +16 -0
- data/spec/mpfi/mpfi_set_operation_spec.rb +102 -0
- data/spec/mpfi/ruby-mpfi_spec.rb +11 -0
- data/spec/mpfi/spec_helper.rb +10 -0
- data/spec/mpfi_complex/spec_helper.rb +10 -0
- data/spec/mpfi_matrix/generate_matrix_arguments.rb +65 -0
- data/spec/mpfi_matrix/mpfi_matrix_alloc_spec.rb +134 -0
- data/spec/mpfi_matrix/mpfi_matrix_arithmetic_spec.rb +156 -0
- data/spec/mpfi_matrix/mpfi_matrix_interval_func_spec.rb +30 -0
- data/spec/mpfi_matrix/mpfi_matrix_set_element_spec.rb +55 -0
- data/spec/mpfi_matrix/mpfi_matrix_set_operation_spec.rb +71 -0
- data/spec/mpfi_matrix/mpfi_matrix_string_spec.rb +32 -0
- data/spec/mpfi_matrix/mpfi_matrix_subdivision_spec.rb +14 -0
- data/spec/mpfi_matrix/mpfi_square_matrix_spec.rb +37 -0
- data/spec/mpfi_matrix/mpfi_vector_spec.rb +15 -0
- data/spec/mpfi_matrix/spec_helper.rb +19 -0
- data/spec/spec.opts +1 -0
- data/tasks/extconf.rake +36 -0
- metadata +132 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
#ifndef _RUBY_MPFI_H_
|
2
|
+
#define _RUBY_MPFI_H_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <ruby.h>
|
6
|
+
#include <mpfr.h>
|
7
|
+
#include <mpfi.h>
|
8
|
+
#include <mpfi_io.h>
|
9
|
+
#include "func_mpfi_extention.h"
|
10
|
+
#include "ruby_mpfr.h"
|
11
|
+
|
12
|
+
typedef __mpfi_struct MPFI;
|
13
|
+
|
14
|
+
VALUE r_mpfi_class, r_mpfi_math;;
|
15
|
+
|
16
|
+
#define r_mpfi_make_struct(ruby_var, c_var) { ruby_var = Data_Make_Struct(r_mpfi_class, MPFI, 0, r_mpfi_free, c_var); }
|
17
|
+
#define r_mpfi_make_struct_init(ruby_var, c_var) { r_mpfi_make_struct(ruby_var, c_var); mpfi_init(c_var); }
|
18
|
+
#define r_mpfi_make_struct_init2(ruby_var, c_var, prec) { r_mpfi_make_struct(ruby_var, c_var); mpfi_init2(c_var, prec); }
|
19
|
+
#define r_mpfi_get_struct(c_var, ruby_var) { Data_Get_Struct(ruby_var, MPFI, c_var); }
|
20
|
+
|
21
|
+
#define r_mpfi_temp_alloc(c_var) { c_var=ALLOC_N(MPFI, 1); }
|
22
|
+
#define r_mpfi_temp_alloc_init(c_var) { r_mpfi_temp_alloc(c_var); mpfi_init(c_var); }
|
23
|
+
#define r_mpfi_temp_alloc_init2(c_var, prec) { r_mpfi_temp_alloc(c_var); mpfi_init2(c_var, prec); }
|
24
|
+
#define r_mpfi_temp_free(c_var) { mpfi_clear(c_var); free(c_var); }
|
25
|
+
|
26
|
+
#define r_mpfi_left_ptr(c_var) (&((c_var)->left))
|
27
|
+
#define r_mpfi_right_ptr(c_var) (&((c_var)->right))
|
28
|
+
|
29
|
+
void r_mpfi_free(void *ptr);
|
30
|
+
VALUE r_mpfi_make_new_fi_obj(MPFI *ptr);
|
31
|
+
VALUE r_mpfi_new_fi_obj(VALUE obj);
|
32
|
+
void r_mpfi_set_robj(MPFI *ptr, VALUE obj);
|
33
|
+
|
34
|
+
int r_mpfi_subdivision2(int num, MPFI *ret, mpfi_t x);
|
35
|
+
|
36
|
+
void r_mpfi_set_function_state(int num);
|
37
|
+
VALUE r_mpfr_get_function_state(VALUE self);
|
38
|
+
|
39
|
+
#endif /* _RUBY_MPFI_H_ */
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#ifndef _RUBY_MPFR_H_
|
2
|
+
#define _RUBY_MPFR_H_
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <mpfr.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
|
8
|
+
typedef __mpfr_struct MPFR;
|
9
|
+
|
10
|
+
VALUE r_mpfr_class, r_mpfr_math;
|
11
|
+
|
12
|
+
#define r_mpfr_make_struct(ruby_var, c_var) { ruby_var = Data_Make_Struct(r_mpfr_class, MPFR, 0, r_mpfr_free, c_var); }
|
13
|
+
#define r_mpfr_make_struct_init(ruby_var, c_var) { r_mpfr_make_struct(ruby_var, c_var); mpfr_init(c_var); }
|
14
|
+
#define r_mpfr_make_struct_init2(ruby_var, c_var, prec) { r_mpfr_make_struct(ruby_var, c_var); mpfr_init2(c_var, prec); }
|
15
|
+
#define r_mpfr_get_struct(c_var, ruby_var) { Data_Get_Struct(ruby_var, MPFR, c_var); }
|
16
|
+
|
17
|
+
#define r_mpfr_temp_alloc(var) { var=ALLOC_N(MPFR, 1); }
|
18
|
+
#define r_mpfr_temp_alloc_init(var) { r_mpfr_temp_alloc(var); mpfr_init(var); }
|
19
|
+
#define r_mpfr_temp_alloc_init2(var, prec) { r_mpfr_temp_alloc(var); mpfr_init2(var, prec); }
|
20
|
+
#define r_mpfr_temp_free(var) { mpfr_clear(var); free(var); }
|
21
|
+
|
22
|
+
#define r_mpfr_check_number(c_val) { if(mpfr_number_p(c_val) == 0) rb_raise(rb_eArgError, "Not an ordinary number."); }
|
23
|
+
#define r_mpfr_check_positive_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) <= 0) rb_raise(rb_eArgError, "Not a positive number."); }
|
24
|
+
#define r_mpfr_check_non_negative_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) < 0) rb_raise(rb_eArgError, "Not a non negative number."); }
|
25
|
+
#define r_mpfr_check_negative_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) >= 0) rb_raise(rb_eArgError, "Not a negative number."); }
|
26
|
+
#define r_mpfr_check_non_positive_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) > 0) rb_raise(rb_eArgError, "Not a non positive number."); }
|
27
|
+
|
28
|
+
void r_mpfr_free(void *ptr);
|
29
|
+
VALUE r_mpfr_new_fr_obj(VALUE obj);
|
30
|
+
void r_mpfr_set_robj(MPFR *ptr, VALUE obj, mp_rnd_t rnd);
|
31
|
+
|
32
|
+
mp_rnd_t r_mpfr_rnd_from_value(VALUE rnd);
|
33
|
+
mp_rnd_t r_mpfr_rnd_from_optional_argument(int min, int max, int argc, VALUE *argv);
|
34
|
+
mp_rnd_t r_mpfr_prec_from_optional_argument(int min, int max, int argc, VALUE *argv);
|
35
|
+
void r_mpfr_get_rnd_prec_from_optional_arguments(mp_rnd_t *rnd, mp_prec_t *prec, int min, int max, int argc, VALUE *argv);
|
36
|
+
|
37
|
+
#endif /* _RUBY_MPFR_H_ */
|
38
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
(yas/define-snippets
|
2
|
+
'c-mode
|
3
|
+
'(("fu" "static VALUE r_mpfi_$1 (VALUE self$2){\n $0\n}" "static VALUE r_mpfi_... (VALUE self ... )")
|
4
|
+
("fu.1" "static VALUE r_mpfi_$1 (int argc, VALUE *argv, VALUE self){\n $0\n}"
|
5
|
+
"static VALUE r_mpfi_... (int argc, VALUE *argv, VALUE self){")
|
6
|
+
("me" "rb_define_method(r_mpfi_class, \"$1\", r_mpfi_$1$0, ${2:0});" "rb_define_method")
|
7
|
+
("se" " R_MPFI *ptr_self;\n r_mpfi_get_struct(ptr_self, self);" "R_MPFI *ptr_self")
|
8
|
+
("se.2" " R_MPFI *ptr_self, *ptr_other;\n r_mpfi_get_struct(ptr_self, self);\n r_mpfi_get_struct(ptr_other, other);" "R_MPFI *ptr_self, *ptr_other")
|
9
|
+
("se.3" " R_MPFI *ptr_self, *ptr_ret;\n r_mpfi_get_struct(ptr_self, self);\n VALUE val_ret;\n r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(${1:max}, ${2:min}, argc, argv));\n$0 return val_ret;"
|
10
|
+
"R_MPFI *ptr_self, *ptr_ret; VALUE val_ret;")
|
11
|
+
("ar" " R_MPFI *ptr_a0, *ptr_ret;\n r_mpfi_get_convert_struct(ptr_a0, argv[0]);\n VALUE val_ret;\n r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(${1:max}, ${2:min}, argc, argv));\n$0 return val_ret;" "R_MPFI *ptr_a, *ptr_ret; VALUE val_ret;")
|
12
|
+
("co" "r_mpfi_get_convert_struct(ptr_a$1, argv[$1]);$0" "convert_struct argv[i]")
|
13
|
+
("re" " VALUE val_ret;\n R_MPFI *ptr_ret;\n r_mpfi_make_struct_init2(val_ret, ptr_ret, $0);" "VALUE val_ret")
|
14
|
+
("op" "r_mpfr_prec_from_optional_argument(${1:min}, ${2:max}, argc, argv)$0" "precision from optional arguments")
|
15
|
+
))
|
16
|
+
|
17
|
+
("fu.2" "static VALUE r_mpfi_$1 (VALUE self, VALUE *args){\n $0\n return ;\n}"
|
18
|
+
"static VALUE r_mpfi_... (VALUE self, VALUE *args){")
|
19
|
+
|
20
|
+
|
21
|
+
(yas/define-snippets
|
22
|
+
'c-mode
|
23
|
+
'(("func" "static VALUE r_mpfi_$1 (VALUE self){
|
24
|
+
R_MPFI *ptr_self;
|
25
|
+
r_mpfi_get_struct(ptr_self, self);
|
26
|
+
VALUE val_ret;
|
27
|
+
R_MPFR *ptr_ret;
|
28
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
29
|
+
r_mpfi_set_function_state(mpfi_$1(ptr_ret, ptr_self));
|
30
|
+
return val_ret;
|
31
|
+
}" "function with MPFR returned value and no argument")))
|
32
|
+
|
33
|
+
(yas/define-snippets
|
34
|
+
'c-mode
|
35
|
+
'(("func.2" "static VALUE r_mpfi_$1 (int argc, VALUE *argv, VALUE self){
|
36
|
+
R_MPFI *ptr_self;
|
37
|
+
r_mpfi_get_struct(ptr_self, self);
|
38
|
+
VALUE val_ret;
|
39
|
+
R_MPFR *ptr_ret;
|
40
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument($2, $3, argc, argv));
|
41
|
+
r_mpfi_set_function_state(mpfi_$1(ptr_ret, ptr_self));
|
42
|
+
return val_ret;
|
43
|
+
}" "function with MPFR returned value and some arguments")))
|
44
|
+
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#include "func_ruby_mpfi_complex.h"
|
2
|
+
|
3
|
+
void mpfi_complex_init(MPFIComplex *x){
|
4
|
+
x->re = ALLOC_N(MPFI, 1);
|
5
|
+
x->im = ALLOC_N(MPFI, 1);
|
6
|
+
mpfi_init(x->re);
|
7
|
+
mpfi_init(x->im);
|
8
|
+
}
|
9
|
+
|
10
|
+
void mpfi_complex_clear(MPFIComplex *x){
|
11
|
+
mpfi_clear(x->re);
|
12
|
+
mpfi_clear(x->im);
|
13
|
+
free(x->re);
|
14
|
+
free(x->im);
|
15
|
+
}
|
16
|
+
|
17
|
+
void mpfi_complex_set_zeros(MPFIComplex *x){
|
18
|
+
mpfi_set_si(x->re, 0);
|
19
|
+
mpfi_set_si(x->im, 0);
|
20
|
+
}
|
21
|
+
|
22
|
+
void mpfi_complex_set_real_part(MPFIComplex *x, MPFI *a){
|
23
|
+
mpfi_set(x->re, a);
|
24
|
+
}
|
25
|
+
|
26
|
+
void mpfi_complex_set_imaginary_part(MPFIComplex *x, MPFI *a){
|
27
|
+
mpfi_set(x->im, a);
|
28
|
+
}
|
29
|
+
|
30
|
+
void mpfi_complex_set(MPFIComplex *new, MPFIComplex *x){
|
31
|
+
mpfi_set(new->re, x->re);
|
32
|
+
mpfi_set(new->im, x->im);
|
33
|
+
}
|
34
|
+
|
35
|
+
void mpfi_complex_conjugate(MPFIComplex *new, MPFIComplex *x){
|
36
|
+
mpfi_set(new->re, x->re);
|
37
|
+
mpfi_neg(new->im, x->im);
|
38
|
+
}
|
39
|
+
|
40
|
+
void mpfi_complex_add(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
41
|
+
mpfi_add(new->re, x->re, y->re);
|
42
|
+
mpfi_add(new->im, x->im, y->im);
|
43
|
+
}
|
44
|
+
|
45
|
+
void mpfi_complex_sub(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
46
|
+
mpfi_sub(new->re, x->re, y->re);
|
47
|
+
mpfi_sub(new->im, x->im, y->im);
|
48
|
+
}
|
49
|
+
|
50
|
+
void mpfi_complex_mul(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
51
|
+
MPFI *t1, *t2, *t_re;
|
52
|
+
r_mpfi_temp_alloc_init2(t1, mpfi_complex_get_prec(new));
|
53
|
+
r_mpfi_temp_alloc_init2(t2, mpfi_complex_get_prec(new));
|
54
|
+
r_mpfi_temp_alloc_init2(t_re, mpfi_complex_get_prec(new));
|
55
|
+
|
56
|
+
mpfi_mul(t1, x->re, y->re);
|
57
|
+
mpfi_mul(t2, x->im, y->im);
|
58
|
+
mpfi_sub(t_re, t1, t2);
|
59
|
+
|
60
|
+
mpfi_mul(t1, x->re, y->im);
|
61
|
+
mpfi_mul(t2, x->im, y->re);
|
62
|
+
mpfi_add(new->im, t1, t2);
|
63
|
+
|
64
|
+
mpfi_set(new->re, t_re);
|
65
|
+
|
66
|
+
r_mpfi_temp_free(t1);
|
67
|
+
r_mpfi_temp_free(t2);
|
68
|
+
r_mpfi_temp_free(t_re);
|
69
|
+
}
|
70
|
+
|
71
|
+
void mpfi_complex_div(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
72
|
+
MPFI *t1, *t2, *t_re, *deno;
|
73
|
+
r_mpfi_temp_alloc_init2(t1, mpfi_complex_get_prec(new));
|
74
|
+
r_mpfi_temp_alloc_init2(t2, mpfi_complex_get_prec(new));
|
75
|
+
r_mpfi_temp_alloc_init2(t_re, mpfi_complex_get_prec(new));
|
76
|
+
r_mpfi_temp_alloc_init2(deno, mpfi_complex_get_prec(new));
|
77
|
+
|
78
|
+
mpfi_mul(t2, y->re, y->re);
|
79
|
+
mpfi_mul(t1, y->im, y->im);
|
80
|
+
mpfi_add(deno, t2, t1);
|
81
|
+
|
82
|
+
mpfi_mul(t2, x->re, y->re);
|
83
|
+
mpfi_mul(t1, x->im, y->im);
|
84
|
+
mpfi_add(t2, t2, t1);
|
85
|
+
mpfi_div(t_re, t2, deno);
|
86
|
+
|
87
|
+
mpfi_mul(t2, x->im, y->re);
|
88
|
+
mpfi_mul(t1, x->re, y->im);
|
89
|
+
mpfi_sub(t2, t2, t1);
|
90
|
+
mpfi_div(new->im, t2, deno);
|
91
|
+
|
92
|
+
mpfi_set(new->re, t_re);
|
93
|
+
|
94
|
+
r_mpfi_temp_free(t1);
|
95
|
+
r_mpfi_temp_free(t2);
|
96
|
+
r_mpfi_temp_free(t_re);
|
97
|
+
r_mpfi_temp_free(deno);
|
98
|
+
}
|
99
|
+
|
100
|
+
/* void mpfi_complex_mul_real(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
101
|
+
/* mpfi_mul(new->re, x->re, y); */
|
102
|
+
/* mpfi_mul(new->im, x->im, y); */
|
103
|
+
/* } */
|
104
|
+
|
105
|
+
/* void mpfi_complex_mul_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
106
|
+
/* mpfi_mul(new->re, x->im, y); */
|
107
|
+
/* mpfi_neg(new->re, new->re); */
|
108
|
+
/* mpfi_mul(new->im, x->re, y); */
|
109
|
+
/* } */
|
110
|
+
|
111
|
+
/* void mpfi_complex_div_real(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
112
|
+
/* mpfi_div(new->re, x->re, y); */
|
113
|
+
/* mpfi_div(new->im, x->im, y); */
|
114
|
+
/* } */
|
115
|
+
|
116
|
+
/* void mpfi_complex_div_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
117
|
+
/* mpfi_div(new->re, x->im, y); */
|
118
|
+
/* mpfi_div(new->im, x->re, y); */
|
119
|
+
/* mpfi_neg(new->im, new->im); */
|
120
|
+
/* } */
|
121
|
+
|
122
|
+
/* void mpfi_complex_abs(MPFI *new, MPFIComplex *x){ */
|
123
|
+
/* MPFI *tmp; */
|
124
|
+
/* r_mpfi_temp_alloc_init(tmp); */
|
125
|
+
/* mpfi_mul(tmp, x->re, x->re); */
|
126
|
+
/* mpfi_mul(new, x->im, x->im); */
|
127
|
+
/* mpfi_add(new, new, tmp); */
|
128
|
+
/* mpfi_sqrt(new, new); */
|
129
|
+
/* r_mpfi_temp_free(tmp); */
|
130
|
+
/* } */
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <ruby.h>
|
3
|
+
#include <mpfr.h>
|
4
|
+
#include <mpfi.h>
|
5
|
+
#include <mpfi_io.h>
|
6
|
+
#include "ruby_mpfi.h"
|
7
|
+
|
8
|
+
VALUE r_mpfi_complex;
|
9
|
+
|
10
|
+
typedef struct __MPFIComplex{
|
11
|
+
MPFI *re;
|
12
|
+
MPFI *im;
|
13
|
+
} MPFIComplex;
|
14
|
+
|
15
|
+
/* Although x->re and x->im can have different precision from each other for MPFIComplex x, */
|
16
|
+
/* we implement mpfi_complex_get_prec assuming that they have same presition. */
|
17
|
+
#define mpfi_complex_get_prec(x) mpfi_get_prec(x->re)
|
18
|
+
|
19
|
+
void mpfi_complex_init(MPFIComplex *x);
|
20
|
+
void mpfi_complex_clear(MPFIComplex *x);
|
21
|
+
void mpfi_complex_set_zeros(MPFIComplex *x);
|
22
|
+
void mpfi_complex_set_real_part(MPFIComplex *x, MPFI *a);
|
23
|
+
void mpfi_complex_set_imaginary_part(MPFIComplex *x, MPFI *a);
|
24
|
+
void mpfi_complex_set(MPFIComplex *new, MPFIComplex *x);
|
25
|
+
void mpfi_complex_conjugate(MPFIComplex *new, MPFIComplex *x);
|
26
|
+
void mpfi_complex_add(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
27
|
+
void mpfi_complex_sub(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
28
|
+
void mpfi_complex_mul(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
29
|
+
void mpfi_complex_div(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
30
|
+
|
31
|
+
/* void mpfi_complex_mul_real(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
32
|
+
/* void mpfi_complex_mul_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
33
|
+
/* void mpfi_complex_div_real(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
34
|
+
/* void mpfi_complex_div_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
35
|
+
/* void mpfi_complex_abs(MPFI *new, MPFIComplex *x); */
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#ifndef _RUBY_MPFI_H_
|
2
|
+
#define _RUBY_MPFI_H_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <ruby.h>
|
6
|
+
#include <mpfr.h>
|
7
|
+
#include <mpfi.h>
|
8
|
+
#include <mpfi_io.h>
|
9
|
+
#include "func_mpfi_extention.h"
|
10
|
+
#include "ruby_mpfr.h"
|
11
|
+
|
12
|
+
typedef __mpfi_struct MPFI;
|
13
|
+
|
14
|
+
VALUE r_mpfi_class, r_mpfi_math;;
|
15
|
+
|
16
|
+
#define r_mpfi_make_struct(ruby_var, c_var) { ruby_var = Data_Make_Struct(r_mpfi_class, MPFI, 0, r_mpfi_free, c_var); }
|
17
|
+
#define r_mpfi_make_struct_init(ruby_var, c_var) { r_mpfi_make_struct(ruby_var, c_var); mpfi_init(c_var); }
|
18
|
+
#define r_mpfi_make_struct_init2(ruby_var, c_var, prec) { r_mpfi_make_struct(ruby_var, c_var); mpfi_init2(c_var, prec); }
|
19
|
+
#define r_mpfi_get_struct(c_var, ruby_var) { Data_Get_Struct(ruby_var, MPFI, c_var); }
|
20
|
+
|
21
|
+
#define r_mpfi_temp_alloc(c_var) { c_var=ALLOC_N(MPFI, 1); }
|
22
|
+
#define r_mpfi_temp_alloc_init(c_var) { r_mpfi_temp_alloc(c_var); mpfi_init(c_var); }
|
23
|
+
#define r_mpfi_temp_alloc_init2(c_var, prec) { r_mpfi_temp_alloc(c_var); mpfi_init2(c_var, prec); }
|
24
|
+
#define r_mpfi_temp_free(c_var) { mpfi_clear(c_var); free(c_var); }
|
25
|
+
|
26
|
+
#define r_mpfi_left_ptr(c_var) (&((c_var)->left))
|
27
|
+
#define r_mpfi_right_ptr(c_var) (&((c_var)->right))
|
28
|
+
|
29
|
+
void r_mpfi_free(void *ptr);
|
30
|
+
VALUE r_mpfi_make_new_fi_obj(MPFI *ptr);
|
31
|
+
VALUE r_mpfi_new_fi_obj(VALUE obj);
|
32
|
+
void r_mpfi_set_robj(MPFI *ptr, VALUE obj);
|
33
|
+
|
34
|
+
int r_mpfi_subdivision2(int num, MPFI *ret, mpfi_t x);
|
35
|
+
|
36
|
+
void r_mpfi_set_function_state(int num);
|
37
|
+
VALUE r_mpfr_get_function_state(VALUE self);
|
38
|
+
|
39
|
+
#endif /* _RUBY_MPFI_H_ */
|
@@ -0,0 +1,217 @@
|
|
1
|
+
#include "ruby_mpfi_complex.h"
|
2
|
+
|
3
|
+
static ID object_id;
|
4
|
+
|
5
|
+
void r_mpfi_complex_free(void *ptr){
|
6
|
+
mpfi_complex_clear(ptr);
|
7
|
+
free(ptr);
|
8
|
+
}
|
9
|
+
|
10
|
+
/* Allocation function for MPF::Complex. */
|
11
|
+
static VALUE r_mpfi_complex_alloc (VALUE self){
|
12
|
+
MPFIComplex *ptr;
|
13
|
+
r_mpfi_make_complex_struct(self, ptr);
|
14
|
+
return self;
|
15
|
+
}
|
16
|
+
|
17
|
+
/* Initialization function for MPF::Complex. */
|
18
|
+
static VALUE r_mpfi_complex_initialize (int argc, VALUE *argv, VALUE self){
|
19
|
+
MPFIComplex *ptr;
|
20
|
+
r_mpfi_get_complex_struct(ptr, self);
|
21
|
+
mpfi_complex_init(ptr);
|
22
|
+
switch (argc) {
|
23
|
+
case 0:
|
24
|
+
mpfi_complex_set_zeros(ptr);
|
25
|
+
break;
|
26
|
+
case 1:
|
27
|
+
r_mpfi_set_robj(ptr->re, argv[0]);
|
28
|
+
mpfi_set_si(ptr->im, 0);
|
29
|
+
break;
|
30
|
+
case 2:
|
31
|
+
r_mpfi_set_robj(ptr->re, argv[0]);
|
32
|
+
r_mpfi_set_robj(ptr->im, argv[1]);
|
33
|
+
break;
|
34
|
+
default:
|
35
|
+
rb_raise(rb_eArgError, "Number of MPF::Complex.new arguments must be lesser than three.");
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
return Qtrue;
|
39
|
+
}
|
40
|
+
|
41
|
+
/* initialize_copy */
|
42
|
+
static VALUE r_mpfi_complex_initialize_copy (VALUE self, VALUE other){
|
43
|
+
MPFIComplex *ptr_self, *ptr_other;
|
44
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
45
|
+
r_mpfi_get_complex_struct(ptr_other, other);
|
46
|
+
mpfi_complex_init(ptr_self);
|
47
|
+
mpfi_complex_set(ptr_self, ptr_other);
|
48
|
+
return Qtrue;
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
static VALUE r_mpfi_complex_real (VALUE self){
|
53
|
+
MPFIComplex *ptr_self;
|
54
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
55
|
+
VALUE ret;
|
56
|
+
MPFI *ptr_ret;
|
57
|
+
r_mpfi_make_struct_init(ret, ptr_ret);
|
58
|
+
mpfi_set(ptr_ret, ptr_self->re);
|
59
|
+
return ret;
|
60
|
+
}
|
61
|
+
|
62
|
+
static VALUE r_mpfi_complex_imaginary (VALUE self){
|
63
|
+
MPFIComplex *ptr_self;
|
64
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
65
|
+
VALUE ret;
|
66
|
+
MPFI *ptr_ret;
|
67
|
+
r_mpfi_make_struct_init(ret, ptr_ret);
|
68
|
+
mpfi_set(ptr_ret, ptr_self->im);
|
69
|
+
return ret;
|
70
|
+
}
|
71
|
+
|
72
|
+
static VALUE r_mpfi_complex_element (VALUE self, VALUE arg){
|
73
|
+
MPFIComplex *ptr_self;
|
74
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
75
|
+
VALUE ret;
|
76
|
+
MPFI *ptr_ret;
|
77
|
+
r_mpfi_make_struct_init(ret, ptr_ret);
|
78
|
+
switch(NUM2INT(arg)){
|
79
|
+
case 0:
|
80
|
+
mpfi_set(ptr_ret, ptr_self->re);
|
81
|
+
break;
|
82
|
+
case 1:
|
83
|
+
mpfi_set(ptr_ret, ptr_self->im);
|
84
|
+
break;
|
85
|
+
default:
|
86
|
+
rb_raise(rb_eArgError, "Argument must be 0 or 1.");
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
return ret;
|
90
|
+
}
|
91
|
+
|
92
|
+
static VALUE r_mpfi_complex_conjugate (VALUE self){
|
93
|
+
MPFIComplex *ptr_self, *ptr_ret;
|
94
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
95
|
+
VALUE ret;
|
96
|
+
r_mpfi_make_complex_struct_init(ret, ptr_ret);
|
97
|
+
mpfi_complex_conjugate(ptr_ret, ptr_self);
|
98
|
+
return ret;
|
99
|
+
}
|
100
|
+
|
101
|
+
/* static VALUE r_mpfi_complex_abs (VALUE self){ */
|
102
|
+
/* MPFIComplex *ptr_self; */
|
103
|
+
/* r_mpfi_get_complex_struct(ptr_self, self); */
|
104
|
+
/* VALUE ret; */
|
105
|
+
/* MPFI *ptr_ret; */
|
106
|
+
/* r_mpfi_make_struct_init(ret, ptr_ret); */
|
107
|
+
/* mpfi_complex_abs(ptr_ret, ptr_self); */
|
108
|
+
/* return ret; */
|
109
|
+
/* } */
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
static VALUE r_mpfi_complex_inspect(VALUE self){
|
114
|
+
MPFIComplex *ptr_s;
|
115
|
+
r_mpfi_get_complex_struct(ptr_s, self);
|
116
|
+
char *ret_str;
|
117
|
+
mpfr_asprintf(&ret_str, "#<MPFI:%lx,['%.Re %.Re', '%.Re %.Re'], [%d, %d]>",
|
118
|
+
NUM2LONG(rb_funcall(self, object_id, 0)), r_mpfi_left_ptr(ptr_s->re), r_mpfi_right_ptr(ptr_s->re), r_mpfi_left_ptr(ptr_s->im), r_mpfi_right_ptr(ptr_s->im),
|
119
|
+
mpfi_get_prec(ptr_s->re), mpfi_get_prec(ptr_s->im));
|
120
|
+
VALUE ret_val = rb_str_new2(ret_str);
|
121
|
+
mpfr_free_str(ret_str);
|
122
|
+
return ret_val;
|
123
|
+
}
|
124
|
+
|
125
|
+
/* Return array which has strings converted elements to. */
|
126
|
+
static VALUE r_mpfi_complex_str_ary(VALUE self, VALUE format_str){
|
127
|
+
MPFIComplex *ptr_self;
|
128
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
129
|
+
char *format = StringValuePtr(format_str), *tmp_str;
|
130
|
+
VALUE ret_val[2];
|
131
|
+
gmp_asprintf(&tmp_str, format, ptr_self->re);
|
132
|
+
ret_val[0] = rb_str_new2(tmp_str);
|
133
|
+
free(tmp_str);
|
134
|
+
gmp_asprintf(&tmp_str, format, ptr_self->im);
|
135
|
+
ret_val[1] = rb_str_new2(tmp_str);
|
136
|
+
free(tmp_str);
|
137
|
+
return rb_ary_new4(2, ret_val);
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
static VALUE r_mpfi_complex_add (VALUE self, VALUE other){
|
143
|
+
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
144
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
145
|
+
r_mpfi_get_complex_struct(ptr_other, other);
|
146
|
+
VALUE ret;
|
147
|
+
r_mpfi_make_complex_struct_init(ret, ptr_ret);
|
148
|
+
mpfi_complex_add(ptr_ret, ptr_self, ptr_other);
|
149
|
+
return ret;
|
150
|
+
}
|
151
|
+
|
152
|
+
static VALUE r_mpfi_complex_sub (VALUE self, VALUE other){
|
153
|
+
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
154
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
155
|
+
r_mpfi_get_complex_struct(ptr_other, other);
|
156
|
+
VALUE ret;
|
157
|
+
r_mpfi_make_complex_struct_init(ret, ptr_ret);
|
158
|
+
mpfi_complex_sub(ptr_ret, ptr_self, ptr_other);
|
159
|
+
return ret;
|
160
|
+
}
|
161
|
+
|
162
|
+
static VALUE r_mpfi_complex_mul (VALUE self, VALUE other){
|
163
|
+
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
164
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
165
|
+
r_mpfi_get_complex_struct(ptr_other, other);
|
166
|
+
VALUE ret;
|
167
|
+
r_mpfi_make_complex_struct_init(ret, ptr_ret);
|
168
|
+
mpfi_complex_mul(ptr_ret, ptr_self, ptr_other);
|
169
|
+
return ret;
|
170
|
+
}
|
171
|
+
|
172
|
+
static VALUE r_mpfi_complex_div (VALUE self, VALUE other){
|
173
|
+
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
174
|
+
r_mpfi_get_complex_struct(ptr_self, self);
|
175
|
+
r_mpfi_get_complex_struct(ptr_other, other);
|
176
|
+
VALUE ret;
|
177
|
+
r_mpfi_make_complex_struct_init(ret, ptr_ret);
|
178
|
+
mpfi_complex_div(ptr_ret, ptr_self, ptr_other);
|
179
|
+
return ret;
|
180
|
+
}
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
void Init_complex(){
|
186
|
+
r_mpfi_complex = rb_define_class_under(rb_define_class("MPFI", rb_cNumeric), "Complex", rb_cObject);
|
187
|
+
|
188
|
+
rb_define_alloc_func(r_mpfi_complex, r_mpfi_complex_alloc);
|
189
|
+
rb_define_private_method(r_mpfi_complex, "initialize", r_mpfi_complex_initialize, -1);
|
190
|
+
rb_define_private_method(r_mpfi_complex, "initialize_copy", r_mpfi_complex_initialize_copy, 1);
|
191
|
+
|
192
|
+
|
193
|
+
rb_define_method(r_mpfi_complex, "real", r_mpfi_complex_real, 0);
|
194
|
+
rb_define_method(r_mpfi_complex, "imaginary", r_mpfi_complex_imaginary, 0);
|
195
|
+
rb_define_method(r_mpfi_complex, "element", r_mpfi_complex_element, 1);
|
196
|
+
rb_define_method(r_mpfi_complex, "conjugate", r_mpfi_complex_conjugate, 0);
|
197
|
+
rb_define_alias(r_mpfi_complex, "[]", "element");
|
198
|
+
|
199
|
+
|
200
|
+
rb_define_method(r_mpfi_complex, "inspect", r_mpfi_complex_inspect, 0);
|
201
|
+
rb_define_method(r_mpfi_complex, "str_ary", r_mpfi_complex_str_ary, 1);
|
202
|
+
|
203
|
+
|
204
|
+
rb_define_method(r_mpfi_complex, "add", r_mpfi_complex_add, 1);
|
205
|
+
rb_define_method(r_mpfi_complex, "sub", r_mpfi_complex_sub, 1);
|
206
|
+
rb_define_method(r_mpfi_complex, "mul", r_mpfi_complex_mul, 1);
|
207
|
+
rb_define_method(r_mpfi_complex, "div", r_mpfi_complex_div, 1);
|
208
|
+
|
209
|
+
rb_define_alias(r_mpfi_complex, "+", "add");
|
210
|
+
rb_define_alias(r_mpfi_complex, "-", "sub");
|
211
|
+
rb_define_alias(r_mpfi_complex, "*", "mul");
|
212
|
+
rb_define_alias(r_mpfi_complex, "/", "div");
|
213
|
+
|
214
|
+
object_id = rb_intern("object_id");
|
215
|
+
|
216
|
+
}
|
217
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#ifndef __RUBY_MPFI_COMPLEX__
|
2
|
+
#define __RUBY_MPFI_COMPLEX__
|
3
|
+
|
4
|
+
#include "func_ruby_mpfi_complex.h"
|
5
|
+
|
6
|
+
#define r_mpfi_make_complex_struct(ruby_var, mpfi_complex_var) { ruby_var = Data_Make_Struct(r_mpfi_complex, MPFIComplex, 0, r_mpfi_complex_free, mpfi_complex_var); }
|
7
|
+
#define r_mpfi_make_complex_struct_init(ruby_var, mpfi_complex_var) { ruby_var = Data_Make_Struct(r_mpfi_complex, MPFIComplex, 0, r_mpfi_complex_free, mpfi_complex_var); mpfi_complex_init(mpfi_complex_var);}
|
8
|
+
#define r_mpfi_get_complex_struct(mpfi_complex_var, ruby_var) { Data_Get_Struct(ruby_var, MPFIComplex, mpfi_complex_var); }
|
9
|
+
|
10
|
+
#define r_mpfi_complex_temp_alloc_init(mpfi_complex_var) { mpfi_complex_var = ALLOC_N(MPFIComplex, 1); mpfi_complex_init(mpfi_complex_var); }
|
11
|
+
#define r_mpfi_complex_temp_free(mpfi_complex_var) { mpfi_complex_clear(mpfi_complex_var); free(mpfi_complex_var); }
|
12
|
+
|
13
|
+
void r_mpfi_complex_free(void *ptr);
|
14
|
+
|
15
|
+
#endif
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#ifndef _RUBY_MPFR_H_
|
2
|
+
#define _RUBY_MPFR_H_
|
3
|
+
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <mpfr.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
|
8
|
+
typedef __mpfr_struct MPFR;
|
9
|
+
|
10
|
+
VALUE r_mpfr_class, r_mpfr_math;
|
11
|
+
|
12
|
+
#define r_mpfr_make_struct(ruby_var, c_var) { ruby_var = Data_Make_Struct(r_mpfr_class, MPFR, 0, r_mpfr_free, c_var); }
|
13
|
+
#define r_mpfr_make_struct_init(ruby_var, c_var) { r_mpfr_make_struct(ruby_var, c_var); mpfr_init(c_var); }
|
14
|
+
#define r_mpfr_make_struct_init2(ruby_var, c_var, prec) { r_mpfr_make_struct(ruby_var, c_var); mpfr_init2(c_var, prec); }
|
15
|
+
#define r_mpfr_get_struct(c_var, ruby_var) { Data_Get_Struct(ruby_var, MPFR, c_var); }
|
16
|
+
|
17
|
+
#define r_mpfr_temp_alloc(var) { var=ALLOC_N(MPFR, 1); }
|
18
|
+
#define r_mpfr_temp_alloc_init(var) { r_mpfr_temp_alloc(var); mpfr_init(var); }
|
19
|
+
#define r_mpfr_temp_alloc_init2(var, prec) { r_mpfr_temp_alloc(var); mpfr_init2(var, prec); }
|
20
|
+
#define r_mpfr_temp_free(var) { mpfr_clear(var); free(var); }
|
21
|
+
|
22
|
+
#define r_mpfr_check_number(c_val) { if(mpfr_number_p(c_val) == 0) rb_raise(rb_eArgError, "Not an ordinary number."); }
|
23
|
+
#define r_mpfr_check_positive_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) <= 0) rb_raise(rb_eArgError, "Not a positive number."); }
|
24
|
+
#define r_mpfr_check_non_negative_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) < 0) rb_raise(rb_eArgError, "Not a non negative number."); }
|
25
|
+
#define r_mpfr_check_negative_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) >= 0) rb_raise(rb_eArgError, "Not a negative number."); }
|
26
|
+
#define r_mpfr_check_non_positive_number(c_val) { if(mpfr_number_p(c_val) == 0 && mpfr_sgn(c_val) > 0) rb_raise(rb_eArgError, "Not a non positive number."); }
|
27
|
+
|
28
|
+
void r_mpfr_free(void *ptr);
|
29
|
+
VALUE r_mpfr_new_fr_obj(VALUE obj);
|
30
|
+
void r_mpfr_set_robj(MPFR *ptr, VALUE obj, mp_rnd_t rnd);
|
31
|
+
|
32
|
+
mp_rnd_t r_mpfr_rnd_from_value(VALUE rnd);
|
33
|
+
mp_rnd_t r_mpfr_rnd_from_optional_argument(int min, int max, int argc, VALUE *argv);
|
34
|
+
mp_rnd_t r_mpfr_prec_from_optional_argument(int min, int max, int argc, VALUE *argv);
|
35
|
+
void r_mpfr_get_rnd_prec_from_optional_arguments(mp_rnd_t *rnd, mp_prec_t *prec, int min, int max, int argc, VALUE *argv);
|
36
|
+
|
37
|
+
#endif /* _RUBY_MPFR_H_ */
|
38
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir_config('mpfr')
|
4
|
+
dir_config('mpfi')
|
5
|
+
dir_config('gmp')
|
6
|
+
|
7
|
+
if have_header('mpfr.h') && have_library('mpfr') && have_header('mpfi.h') && have_library('mpfi') && have_header('gmp.h') && have_library('gmp')
|
8
|
+
create_makefile("mpfi/matrix")
|
9
|
+
end
|