ruby-mpfi 0.0.2 → 0.0.3

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.
@@ -1,115 +0,0 @@
1
-
2
- def make_sepcial_functions(one_arguments, no_argument)
3
- one_arguments.each do |name|
4
- puts <<SRC
5
- static VALUE r_mpfi_math_#{name} (int argc, VALUE *argv, VALUE self){
6
- R_MPFI *ptr_a0, *ptr_ret;
7
- r_mpfi_get_convert_struct(argv[0], ptr_a0);
8
- VALUE val_ret;
9
- r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
10
- r_mpfi_set_function_state(mpfi_#{name}(ptr_ret, ptr_a0));
11
- return val_ret;
12
- }
13
-
14
- SRC
15
- end
16
-
17
- no_argument.each do |name|
18
- puts <<SRC
19
- static VALUE r_mpfi_math_#{name} (int argc, VALUE *argv, VALUE self){
20
- R_MPFI *ptr_ret;
21
- VALUE val_ret;
22
- r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
23
- r_mpfi_set_function_state(mpfi_#{name}(ptr_ret));
24
- return val_ret;
25
- }
26
-
27
- SRC
28
- end
29
-
30
- (one_arguments + no_argument).each do |name|
31
- puts %!rb_define_module_function(r_mpfi_math, "#{name}", r_mpfi_math_#{name}, -1);!
32
- end
33
-
34
- end
35
-
36
- def make_comparison(positive_returned_value, non_zero_returned_value)
37
- positive_returned_value.each do |name|
38
- puts <<SRC
39
- static VALUE r_mpfi_#{name} (VALUE self){
40
- R_MPFI *ptr_self;
41
- r_mpfi_get_struct(ptr_self, self);
42
- if (mpfi_#{name}(ptr_self) > 0) {
43
- return Qtrue;
44
- }else{
45
- return Qnil;
46
- }
47
- }
48
-
49
- SRC
50
- end
51
-
52
- non_zero_returned_value.each do |name|
53
- puts <<SRC
54
- static VALUE r_mpfi_#{name} (VALUE self){
55
- R_MPFI *ptr_self;
56
- r_mpfi_get_struct(ptr_self, self);
57
- if (mpfi_#{name}(ptr_self) != 0) {
58
- return Qtrue;
59
- }else{
60
- return Qnil;
61
- }
62
- }
63
-
64
- SRC
65
- end
66
-
67
- (positive_returned_value + non_zero_returned_value).each do |name|
68
- puts %!rb_define_module_function(r_mpfi_class, "#{name}", r_mpfi_#{name}, 0);!
69
- end
70
- end
71
-
72
- # Parse options.
73
- require 'optparse'
74
-
75
- help_message =<<HELP
76
- Make C source for extended library mpfr.
77
- HELP
78
-
79
- category = nil
80
-
81
- begin
82
- OptionParser.new(help_message) do |opt|
83
- # on(short [, klass [, pat [, desc]]]) {|v| ...}
84
- # on(long [, klass [, pat [, desc]]) {|v| ...}
85
- # on(short, long [, klass [, pat [, desc]]]) {|v| ...}
86
- opt.on('--special') { |v| category = :special }
87
- opt.on('--comparison') { |v| category = :comparison }
88
- opt.parse!(ARGV)
89
- end
90
- rescue OptionParser::InvalidOption
91
- $stderr.print <<MES
92
- error: Invalid Option
93
- #{help_message}
94
- MES
95
- exit(2)
96
- rescue OptionParser::InvalidArgument
97
- $stderr.print <<MES
98
- error: Invalid Argument
99
- #{help_message}
100
- MES
101
- exit(2)
102
- end
103
-
104
- case category
105
- when :special
106
- one_arguments = ['log', 'exp', 'exp2', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'cosh', 'sinh', 'tanh',
107
- 'acosh', 'asinh', 'atanh', 'log1p', 'expm1', 'log2', 'log10']
108
- no_argument = ['const_log2', 'const_pi', 'const_euler']
109
- make_sepcial_functions(one_arguments, no_argument)
110
- when :comparison
111
- positive_returned_value = ['is_pos', 'is_strictly_pos', 'is_nonneg', 'is_neg', 'is_strictly_neg', 'is_nonpos', 'is_zero']
112
- non_zero_returned_value = ['nan_p', 'inf_p', 'bounded_p']
113
- make_comparison(positive_returned_value, non_zero_returned_value)
114
- end
115
-
@@ -1,44 +0,0 @@
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
-
@@ -1,35 +0,0 @@
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); */
@@ -1,15 +0,0 @@
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