ruby-mpfi 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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,1452 @@
|
|
1
|
+
#include "ruby_mpfi.h"
|
2
|
+
|
3
|
+
#define CLASS_VAL_FUNCTION_STATE "@@function_state"
|
4
|
+
|
5
|
+
static ID eqq, to_s, new, class, method_defined, object_id;
|
6
|
+
static VALUE __mpfi_class__, __mpfr_class__, __sym_to_s__, __sym_to_str__;
|
7
|
+
|
8
|
+
|
9
|
+
/* ------------------------------ function state start ------------------------------ */
|
10
|
+
|
11
|
+
/* Save the value of last function state. */
|
12
|
+
void r_mpfi_set_function_state(int num){
|
13
|
+
rb_cv_set(r_mpfi_class, CLASS_VAL_FUNCTION_STATE, INT2NUM(num));
|
14
|
+
}
|
15
|
+
|
16
|
+
/* Return state of last function of MPFI. */
|
17
|
+
VALUE r_mpfr_get_function_state(VALUE self){
|
18
|
+
return rb_cv_get(r_mpfi_class, CLASS_VAL_FUNCTION_STATE);
|
19
|
+
}
|
20
|
+
|
21
|
+
/* ------------------------------ function state end ------------------------------ */
|
22
|
+
|
23
|
+
/* ------------------------------ allocation start ------------------------------ */
|
24
|
+
|
25
|
+
void r_mpfi_free(void *ptr){
|
26
|
+
mpfi_clear(ptr);
|
27
|
+
free(ptr);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE r_mpfi_make_new_fi_obj(MPFI *ptr){
|
31
|
+
VALUE ret;
|
32
|
+
MPFI *ptr_ret;
|
33
|
+
r_mpfi_make_struct_init(ret, ptr_ret);
|
34
|
+
mpfi_set(ptr_ret, ptr);
|
35
|
+
return ret;
|
36
|
+
}
|
37
|
+
|
38
|
+
/* VALUE obj must have method to_s or to_str. */
|
39
|
+
static void r_mpfi_set_from_object (MPFI *ptr, VALUE obj){
|
40
|
+
if(RTEST(rb_funcall(rb_funcall(obj, class, 0), method_defined, 1, __sym_to_str__))){
|
41
|
+
char *str = StringValuePtr(obj);
|
42
|
+
mpfi_set_str(ptr, str, 10);
|
43
|
+
}else if(RTEST(rb_funcall(rb_funcall(obj, class, 0), method_defined, 1, __sym_to_s__))){
|
44
|
+
VALUE tmp = rb_funcall(obj, to_s, 0);
|
45
|
+
char *str = StringValuePtr(tmp);
|
46
|
+
mpfi_set_str(ptr, str, 10);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
void r_mpfi_set_robj(MPFI *ptr, VALUE obj){
|
51
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, obj))){
|
52
|
+
MPFI *ptr_obj;
|
53
|
+
r_mpfi_get_struct(ptr_obj, obj);
|
54
|
+
mpfi_set(ptr, ptr_obj);
|
55
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, obj))){
|
56
|
+
MPFR *ptr_obj;
|
57
|
+
r_mpfr_get_struct(ptr_obj, obj);
|
58
|
+
mpfi_set_fr(ptr, ptr_obj);
|
59
|
+
}else{
|
60
|
+
switch(TYPE(obj)){
|
61
|
+
case T_FLOAT:
|
62
|
+
mpfi_set_d(ptr, NUM2DBL(obj));
|
63
|
+
break;
|
64
|
+
case T_FIXNUM:
|
65
|
+
mpfi_set_si(ptr, FIX2LONG(obj));
|
66
|
+
break;
|
67
|
+
default:
|
68
|
+
r_mpfi_set_from_object(ptr, obj);
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
VALUE r_mpfi_new_fi_obj(VALUE obj){
|
75
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, obj))){
|
76
|
+
return obj;
|
77
|
+
}else{
|
78
|
+
return rb_funcall(__mpfi_class__, new, 1, obj);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
/* Initializing and Assigning Intervals */
|
83
|
+
static VALUE r_mpfi_alloc(VALUE self){
|
84
|
+
MPFI *ptr;
|
85
|
+
r_mpfi_make_struct(self, ptr);
|
86
|
+
return self;
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE r_mpfi_initialize(int argc, VALUE *argv, VALUE self){
|
90
|
+
MPFI *ptr;
|
91
|
+
r_mpfi_get_struct(ptr, self);
|
92
|
+
switch(argc){
|
93
|
+
case 0:
|
94
|
+
mpfi_init(ptr);
|
95
|
+
break;
|
96
|
+
case 1:
|
97
|
+
mpfi_init(ptr);
|
98
|
+
r_mpfi_set_robj(ptr, argv[0]);
|
99
|
+
break;
|
100
|
+
case 2:
|
101
|
+
mpfi_init2(ptr, NUM2INT(argv[1]));
|
102
|
+
r_mpfi_set_robj(ptr, argv[0]);
|
103
|
+
break;
|
104
|
+
default:
|
105
|
+
rb_raise(rb_eArgError, "Invalid number of arguments.");
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
return Qtrue;
|
109
|
+
}
|
110
|
+
|
111
|
+
static VALUE r_mpfi_initialize_copy(VALUE self, VALUE other){
|
112
|
+
MPFI *ptr_self, *ptr_other;
|
113
|
+
r_mpfi_get_struct(ptr_self, self);
|
114
|
+
r_mpfi_get_struct(ptr_other, other);
|
115
|
+
mpfi_init2(ptr_self, mpfi_get_prec(ptr_other));
|
116
|
+
mpfi_set(ptr_self, ptr_other);
|
117
|
+
return Qtrue;
|
118
|
+
}
|
119
|
+
|
120
|
+
/* Return array which have MPFI instance converted to from p1 and self. */
|
121
|
+
static VALUE r_mpfi_coerce(VALUE self, VALUE other){
|
122
|
+
VALUE val_other;
|
123
|
+
MPFI *ptr_self, *ptr_other;
|
124
|
+
r_mpfi_get_struct(ptr_self, self);
|
125
|
+
r_mpfi_make_struct_init2(val_other, ptr_other, mpfi_get_prec(ptr_self));
|
126
|
+
r_mpfi_set_robj(ptr_other, other);
|
127
|
+
return rb_ary_new3(2, val_other, self);
|
128
|
+
}
|
129
|
+
|
130
|
+
static VALUE r_mpfi_set (VALUE self, VALUE arg){
|
131
|
+
MPFI *ptr_self;
|
132
|
+
r_mpfi_get_struct(ptr_self, self);
|
133
|
+
r_mpfi_set_robj(ptr_self, arg);
|
134
|
+
return self;
|
135
|
+
}
|
136
|
+
|
137
|
+
static VALUE r_mpfi_swap (VALUE self, VALUE other){
|
138
|
+
MPFI *ptr_self, *ptr_other;
|
139
|
+
r_mpfi_get_struct(ptr_self, self);
|
140
|
+
r_mpfi_get_struct(ptr_other, other);
|
141
|
+
mpfi_swap(ptr_self, ptr_other);
|
142
|
+
return self;
|
143
|
+
}
|
144
|
+
|
145
|
+
/* ------------------------------ allocation end ------------------------------ */
|
146
|
+
|
147
|
+
/* ------------------------------ Rounding Modes and Precision Handling start ------------------------------*/
|
148
|
+
|
149
|
+
/* Need to consider returned value later. */
|
150
|
+
/* mpfi_set_prec is different from reference manual. This is strange. */
|
151
|
+
static VALUE r_mpfi_set_prec (VALUE self, VALUE prec){
|
152
|
+
MPFI *ptr_self;
|
153
|
+
r_mpfi_get_struct(ptr_self, self);
|
154
|
+
/* if(mpfi_set_prec(ptr_self, NUM2INT(prec)) != 0){ */
|
155
|
+
/* rb_raise(rb_eRuntimeError, "Memory allocation failed for mpfi_set_prec."); */
|
156
|
+
/* } */
|
157
|
+
mpfi_set_prec(ptr_self, NUM2INT(prec));
|
158
|
+
return self;
|
159
|
+
}
|
160
|
+
|
161
|
+
/* Need to consider returned value later. */
|
162
|
+
static VALUE r_mpfi_get_prec (VALUE self){
|
163
|
+
MPFI *ptr_self;
|
164
|
+
r_mpfi_get_struct(ptr_self, self);
|
165
|
+
return INT2NUM((int)mpfi_get_prec(ptr_self));
|
166
|
+
}
|
167
|
+
|
168
|
+
/* Need to consider returned value later. */
|
169
|
+
static VALUE r_mpfi_round_prec (VALUE self, VALUE prec){
|
170
|
+
MPFI *ptr_self;
|
171
|
+
r_mpfi_get_struct(ptr_self, self);
|
172
|
+
r_mpfi_set_function_state(mpfi_round_prec(ptr_self, NUM2INT(prec)));
|
173
|
+
return self;
|
174
|
+
}
|
175
|
+
/* ------------------------------ Rounding Modes and Precision Handling end ------------------------------*/
|
176
|
+
|
177
|
+
/* ------------------------------ string start ------------------------------ */
|
178
|
+
|
179
|
+
static VALUE r_mpfi_inspect(VALUE self){
|
180
|
+
MPFI *ptr_s;
|
181
|
+
r_mpfi_get_struct(ptr_s, self);
|
182
|
+
char *ret_str;
|
183
|
+
mpfr_asprintf(&ret_str, "#<MPFI:%lx,['%.Re %.Re'],%d>",
|
184
|
+
NUM2LONG(rb_funcall(self, object_id, 0)), r_mpfi_left_ptr(ptr_s), r_mpfi_right_ptr(ptr_s), mpfi_get_prec(ptr_s));
|
185
|
+
VALUE ret_val = rb_str_new2(ret_str);
|
186
|
+
mpfr_free_str(ret_str);
|
187
|
+
return ret_val;
|
188
|
+
}
|
189
|
+
|
190
|
+
static VALUE r_mpfi_to_str_ary(VALUE self){
|
191
|
+
MPFI *ptr_self;
|
192
|
+
r_mpfi_get_struct(ptr_self, self);
|
193
|
+
char *ret_str1, *ret_str2;
|
194
|
+
mpfr_asprintf(&ret_str1, "%.Re", r_mpfi_left_ptr(ptr_self));
|
195
|
+
mpfr_asprintf(&ret_str2, "%.Re", r_mpfi_right_ptr(ptr_self));
|
196
|
+
VALUE str1 = rb_str_new2(ret_str1), str2 = rb_str_new2(ret_str2);
|
197
|
+
mpfr_free_str(ret_str1);
|
198
|
+
mpfr_free_str(ret_str2);
|
199
|
+
return rb_ary_new3(2, str1, str2);
|
200
|
+
}
|
201
|
+
|
202
|
+
/* Output self by sprintf. */
|
203
|
+
static VALUE r_mpfi_to_strf_ary(VALUE self, VALUE format_str){
|
204
|
+
MPFI *ptr_self;
|
205
|
+
r_mpfi_get_struct(ptr_self, self);
|
206
|
+
char *format = StringValuePtr(format_str);
|
207
|
+
char *ret_str1, *ret_str2;
|
208
|
+
mpfr_asprintf(&ret_str1, format, r_mpfi_left_ptr(ptr_self));
|
209
|
+
mpfr_asprintf(&ret_str2, format, r_mpfi_right_ptr(ptr_self));
|
210
|
+
VALUE str1 = rb_str_new2(ret_str1), str2 = rb_str_new2(ret_str2);
|
211
|
+
mpfr_free_str(ret_str1);
|
212
|
+
mpfr_free_str(ret_str2);
|
213
|
+
return rb_ary_new3(2, str1, str2);
|
214
|
+
}
|
215
|
+
|
216
|
+
/* ------------------------------ string end ------------------------------ */
|
217
|
+
|
218
|
+
/* ------------------------------ Basic Arithmetic Functions start ------------------------------ */
|
219
|
+
|
220
|
+
static VALUE r_mpfi_add (VALUE self, VALUE other){
|
221
|
+
VALUE val_ret;
|
222
|
+
MPFI *ptr_self, *ptr_ret;
|
223
|
+
r_mpfi_get_struct(ptr_self, self);
|
224
|
+
r_mpfi_make_struct_init(val_ret, ptr_ret);
|
225
|
+
|
226
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
|
227
|
+
MPFI *ptr_other;
|
228
|
+
r_mpfi_get_struct(ptr_other, other);
|
229
|
+
mpfi_add(ptr_ret, ptr_self, ptr_other);
|
230
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
|
231
|
+
MPFR *ptr_other;
|
232
|
+
r_mpfr_get_struct(ptr_other, other);
|
233
|
+
mpfi_add_fr(ptr_ret, ptr_self, ptr_other);
|
234
|
+
}else if(TYPE(other) == T_FIXNUM){
|
235
|
+
mpfi_add_si(ptr_ret, ptr_self, FIX2LONG(other));
|
236
|
+
}else if(TYPE(other) == T_FLOAT){
|
237
|
+
mpfi_add_d(ptr_ret, ptr_self, NUM2DBL(other));
|
238
|
+
}else{
|
239
|
+
MPFI *ptr_other;
|
240
|
+
volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
|
241
|
+
r_mpfi_get_struct(ptr_other, tmp_other);
|
242
|
+
mpfi_add(ptr_ret, ptr_self, ptr_other);
|
243
|
+
}
|
244
|
+
return val_ret;
|
245
|
+
}
|
246
|
+
|
247
|
+
static VALUE r_mpfi_sub (VALUE self, VALUE other){
|
248
|
+
VALUE val_ret;
|
249
|
+
MPFI *ptr_self, *ptr_ret;
|
250
|
+
r_mpfi_get_struct(ptr_self, self);
|
251
|
+
r_mpfi_make_struct_init(val_ret, ptr_ret);
|
252
|
+
|
253
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
|
254
|
+
MPFI *ptr_other;
|
255
|
+
r_mpfi_get_struct(ptr_other, other);
|
256
|
+
mpfi_sub(ptr_ret, ptr_self, ptr_other);
|
257
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
|
258
|
+
MPFR *ptr_other;
|
259
|
+
r_mpfr_get_struct(ptr_other, other);
|
260
|
+
mpfi_sub_fr(ptr_ret, ptr_self, ptr_other);
|
261
|
+
}else if(TYPE(other) == T_FIXNUM){
|
262
|
+
mpfi_sub_si(ptr_ret, ptr_self, FIX2LONG(other));
|
263
|
+
}else if(TYPE(other) == T_FLOAT){
|
264
|
+
mpfi_sub_d(ptr_ret, ptr_self, NUM2DBL(other));
|
265
|
+
}else{
|
266
|
+
MPFI *ptr_other;
|
267
|
+
volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
|
268
|
+
r_mpfi_get_struct(ptr_other, tmp_other);
|
269
|
+
mpfi_sub(ptr_ret, ptr_self, ptr_other);
|
270
|
+
}
|
271
|
+
return val_ret;
|
272
|
+
}
|
273
|
+
|
274
|
+
static VALUE r_mpfi_mul (VALUE self, VALUE other){
|
275
|
+
VALUE val_ret;
|
276
|
+
MPFI *ptr_self, *ptr_ret;
|
277
|
+
r_mpfi_get_struct(ptr_self, self);
|
278
|
+
r_mpfi_make_struct_init(val_ret, ptr_ret);
|
279
|
+
|
280
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
|
281
|
+
MPFI *ptr_other;
|
282
|
+
r_mpfi_get_struct(ptr_other, other);
|
283
|
+
mpfi_mul(ptr_ret, ptr_self, ptr_other);
|
284
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
|
285
|
+
MPFR *ptr_other;
|
286
|
+
r_mpfr_get_struct(ptr_other, other);
|
287
|
+
mpfi_mul_fr(ptr_ret, ptr_self, ptr_other);
|
288
|
+
}else if(TYPE(other) == T_FIXNUM){
|
289
|
+
mpfi_mul_si(ptr_ret, ptr_self, FIX2LONG(other));
|
290
|
+
}else if(TYPE(other) == T_FLOAT){
|
291
|
+
mpfi_mul_d(ptr_ret, ptr_self, NUM2DBL(other));
|
292
|
+
}else{
|
293
|
+
MPFI *ptr_other;
|
294
|
+
volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
|
295
|
+
r_mpfi_get_struct(ptr_other, tmp_other);
|
296
|
+
mpfi_mul(ptr_ret, ptr_self, ptr_other);
|
297
|
+
}
|
298
|
+
return val_ret;
|
299
|
+
}
|
300
|
+
|
301
|
+
static VALUE r_mpfi_div (VALUE self, VALUE other){
|
302
|
+
VALUE val_ret;
|
303
|
+
MPFI *ptr_self, *ptr_ret;
|
304
|
+
r_mpfi_get_struct(ptr_self, self);
|
305
|
+
r_mpfi_make_struct_init(val_ret, ptr_ret);
|
306
|
+
|
307
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
|
308
|
+
MPFI *ptr_other;
|
309
|
+
r_mpfi_get_struct(ptr_other, other);
|
310
|
+
mpfi_div(ptr_ret, ptr_self, ptr_other);
|
311
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
|
312
|
+
MPFR *ptr_other;
|
313
|
+
r_mpfr_get_struct(ptr_other, other);
|
314
|
+
mpfi_div_fr(ptr_ret, ptr_self, ptr_other);
|
315
|
+
}else if(TYPE(other) == T_FIXNUM){
|
316
|
+
mpfi_div_si(ptr_ret, ptr_self, FIX2LONG(other));
|
317
|
+
}else if(TYPE(other) == T_FLOAT){
|
318
|
+
mpfi_div_d(ptr_ret, ptr_self, NUM2DBL(other));
|
319
|
+
}else{
|
320
|
+
MPFI *ptr_other;
|
321
|
+
volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
|
322
|
+
r_mpfi_get_struct(ptr_other, tmp_other);
|
323
|
+
mpfi_div(ptr_ret, ptr_self, ptr_other);
|
324
|
+
}
|
325
|
+
return val_ret;
|
326
|
+
}
|
327
|
+
|
328
|
+
static VALUE r_mpfi_mul_2si (int argc, VALUE *argv, VALUE self){
|
329
|
+
MPFI *ptr_self, *ptr_ret;
|
330
|
+
r_mpfi_get_struct(ptr_self, self);
|
331
|
+
VALUE val_ret;
|
332
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
333
|
+
mpfi_mul_2si(ptr_ret, ptr_self, NUM2INT(argv[0]));
|
334
|
+
return val_ret;
|
335
|
+
}
|
336
|
+
|
337
|
+
static VALUE r_mpfi_div_2si (int argc, VALUE *argv, VALUE self){
|
338
|
+
MPFI *ptr_self, *ptr_ret;
|
339
|
+
r_mpfi_get_struct(ptr_self, self);
|
340
|
+
VALUE val_ret;
|
341
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
342
|
+
mpfi_div_2si(ptr_ret, ptr_self, NUM2INT(argv[0]));
|
343
|
+
return val_ret;
|
344
|
+
}
|
345
|
+
|
346
|
+
static VALUE r_mpfi_neg(int argc, VALUE *argv, VALUE self){
|
347
|
+
MPFI *ptr_self, *ptr_ret;
|
348
|
+
r_mpfi_get_struct(ptr_self, self);
|
349
|
+
VALUE val_ret;
|
350
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
351
|
+
mpfi_neg(ptr_ret, ptr_self);
|
352
|
+
return val_ret;
|
353
|
+
}
|
354
|
+
|
355
|
+
static VALUE r_mpfi_inv(int argc, VALUE *argv, VALUE self){
|
356
|
+
MPFI *ptr_self, *ptr_ret;
|
357
|
+
r_mpfi_get_struct(ptr_self, self);
|
358
|
+
VALUE val_ret;
|
359
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
360
|
+
mpfi_inv(ptr_ret, ptr_self);
|
361
|
+
return val_ret;
|
362
|
+
}
|
363
|
+
|
364
|
+
static VALUE r_mpfi_abs(int argc, VALUE *argv, VALUE self){
|
365
|
+
MPFI *ptr_self, *ptr_ret;
|
366
|
+
r_mpfi_get_struct(ptr_self, self);
|
367
|
+
VALUE val_ret;
|
368
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
369
|
+
mpfi_abs(ptr_ret, ptr_self);
|
370
|
+
return val_ret;
|
371
|
+
}
|
372
|
+
|
373
|
+
/* ------------------------------ Basic Arithmetic Functions end ------------------------------ */
|
374
|
+
|
375
|
+
/* ------------------------------ Comparison Functions start ------------------------------ */
|
376
|
+
|
377
|
+
static VALUE r_mpfi_cmp (VALUE self, VALUE other){
|
378
|
+
MPFI *ptr_self;
|
379
|
+
r_mpfi_get_struct(ptr_self, self);
|
380
|
+
int ret;
|
381
|
+
|
382
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
|
383
|
+
MPFI *ptr_other;
|
384
|
+
r_mpfi_get_struct(ptr_other, other);
|
385
|
+
ret = mpfi_cmp(ptr_self, ptr_other);
|
386
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
|
387
|
+
MPFR *ptr_other;
|
388
|
+
r_mpfr_get_struct(ptr_other, other);
|
389
|
+
ret = mpfi_cmp_fr(ptr_self, ptr_other);
|
390
|
+
}else if(TYPE(other) == T_FIXNUM){
|
391
|
+
ret = mpfi_cmp_si(ptr_self, FIX2LONG(other));
|
392
|
+
}else if(TYPE(other) == T_FLOAT){
|
393
|
+
ret = mpfi_cmp_d(ptr_self, NUM2DBL(other));
|
394
|
+
}else{
|
395
|
+
MPFI *ptr_other;
|
396
|
+
volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
|
397
|
+
r_mpfi_get_struct(ptr_other, tmp_other);
|
398
|
+
ret = mpfi_cmp(ptr_self, ptr_other);
|
399
|
+
}
|
400
|
+
return NUM2INT(ret);
|
401
|
+
}
|
402
|
+
|
403
|
+
static VALUE r_mpfi_is_pos (VALUE self){
|
404
|
+
MPFI *ptr_self;
|
405
|
+
r_mpfi_get_struct(ptr_self, self);
|
406
|
+
if (mpfi_is_pos(ptr_self) > 0) {
|
407
|
+
return Qtrue;
|
408
|
+
}else{
|
409
|
+
return Qnil;
|
410
|
+
}
|
411
|
+
}
|
412
|
+
|
413
|
+
static VALUE r_mpfi_is_strictly_pos (VALUE self){
|
414
|
+
MPFI *ptr_self;
|
415
|
+
r_mpfi_get_struct(ptr_self, self);
|
416
|
+
if (mpfi_is_strictly_pos(ptr_self) > 0) {
|
417
|
+
return Qtrue;
|
418
|
+
}else{
|
419
|
+
return Qnil;
|
420
|
+
}
|
421
|
+
}
|
422
|
+
|
423
|
+
static VALUE r_mpfi_is_nonneg (VALUE self){
|
424
|
+
MPFI *ptr_self;
|
425
|
+
r_mpfi_get_struct(ptr_self, self);
|
426
|
+
if (mpfi_is_nonneg(ptr_self) > 0) {
|
427
|
+
return Qtrue;
|
428
|
+
}else{
|
429
|
+
return Qnil;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
|
433
|
+
static VALUE r_mpfi_is_neg (VALUE self){
|
434
|
+
MPFI *ptr_self;
|
435
|
+
r_mpfi_get_struct(ptr_self, self);
|
436
|
+
if (mpfi_is_neg(ptr_self) > 0) {
|
437
|
+
return Qtrue;
|
438
|
+
}else{
|
439
|
+
return Qnil;
|
440
|
+
}
|
441
|
+
}
|
442
|
+
|
443
|
+
static VALUE r_mpfi_is_strictly_neg (VALUE self){
|
444
|
+
MPFI *ptr_self;
|
445
|
+
r_mpfi_get_struct(ptr_self, self);
|
446
|
+
if (mpfi_is_strictly_neg(ptr_self) > 0) {
|
447
|
+
return Qtrue;
|
448
|
+
}else{
|
449
|
+
return Qnil;
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
static VALUE r_mpfi_is_nonpos (VALUE self){
|
454
|
+
MPFI *ptr_self;
|
455
|
+
r_mpfi_get_struct(ptr_self, self);
|
456
|
+
if (mpfi_is_nonpos(ptr_self) > 0) {
|
457
|
+
return Qtrue;
|
458
|
+
}else{
|
459
|
+
return Qnil;
|
460
|
+
}
|
461
|
+
}
|
462
|
+
|
463
|
+
static VALUE r_mpfi_is_zero (VALUE self){
|
464
|
+
MPFI *ptr_self;
|
465
|
+
r_mpfi_get_struct(ptr_self, self);
|
466
|
+
if (mpfi_is_zero(ptr_self) > 0) {
|
467
|
+
return Qtrue;
|
468
|
+
}else{
|
469
|
+
return Qnil;
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
static VALUE r_mpfi_has_zero (VALUE self){
|
474
|
+
MPFI *ptr_self;
|
475
|
+
r_mpfi_get_struct(ptr_self, self);
|
476
|
+
if (mpfi_has_zero(ptr_self) > 0) {
|
477
|
+
return Qtrue;
|
478
|
+
}else{
|
479
|
+
return Qnil;
|
480
|
+
}
|
481
|
+
}
|
482
|
+
|
483
|
+
static VALUE r_mpfi_nan_p (VALUE self){
|
484
|
+
MPFI *ptr_self;
|
485
|
+
r_mpfi_get_struct(ptr_self, self);
|
486
|
+
if (mpfi_nan_p(ptr_self) != 0) {
|
487
|
+
return Qtrue;
|
488
|
+
}else{
|
489
|
+
return Qnil;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
static VALUE r_mpfi_inf_p (VALUE self){
|
494
|
+
MPFI *ptr_self;
|
495
|
+
r_mpfi_get_struct(ptr_self, self);
|
496
|
+
if (mpfi_inf_p(ptr_self) != 0) {
|
497
|
+
return Qtrue;
|
498
|
+
}else{
|
499
|
+
return Qnil;
|
500
|
+
}
|
501
|
+
}
|
502
|
+
|
503
|
+
static VALUE r_mpfi_bounded_p (VALUE self){
|
504
|
+
MPFI *ptr_self;
|
505
|
+
r_mpfi_get_struct(ptr_self, self);
|
506
|
+
if (mpfi_bounded_p(ptr_self) != 0) {
|
507
|
+
return Qtrue;
|
508
|
+
}else{
|
509
|
+
return Qnil;
|
510
|
+
}
|
511
|
+
}
|
512
|
+
|
513
|
+
/* Return true if self.right equals other.right and self.left equals other.right
|
514
|
+
by mpfr_equal_p. */
|
515
|
+
static VALUE r_mpfi_equal_p (VALUE self, VALUE other){
|
516
|
+
MPFI *ptr_self, *ptr_other;
|
517
|
+
r_mpfi_get_struct(ptr_self, self);
|
518
|
+
r_mpfi_get_struct(ptr_other, other);
|
519
|
+
if (mpfr_equal_p(r_mpfi_left_ptr(ptr_self), r_mpfi_left_ptr(ptr_other)) != 0 &&
|
520
|
+
mpfr_equal_p(r_mpfi_right_ptr(ptr_self), r_mpfi_right_ptr(ptr_other)) != 0) {
|
521
|
+
return Qtrue;
|
522
|
+
}else{
|
523
|
+
return Qnil;
|
524
|
+
}
|
525
|
+
}
|
526
|
+
|
527
|
+
/* ------------------------------ Comparison Functions end ------------------------------ */
|
528
|
+
|
529
|
+
/* ------------------------------ Interval Functions with Floating-point Results start ------------------------------ */
|
530
|
+
|
531
|
+
static VALUE r_mpfi_diam_abs (int argc, VALUE *argv, VALUE self){
|
532
|
+
MPFI *ptr_self;
|
533
|
+
r_mpfi_get_struct(ptr_self, self);
|
534
|
+
VALUE val_ret;
|
535
|
+
MPFR *ptr_ret;
|
536
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
537
|
+
r_mpfi_set_function_state(mpfi_diam_abs(ptr_ret, ptr_self));
|
538
|
+
return val_ret;
|
539
|
+
}
|
540
|
+
|
541
|
+
static VALUE r_mpfi_diam_rel (int argc, VALUE *argv, VALUE self){
|
542
|
+
MPFI *ptr_self;
|
543
|
+
r_mpfi_get_struct(ptr_self, self);
|
544
|
+
VALUE val_ret;
|
545
|
+
MPFR *ptr_ret;
|
546
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
547
|
+
r_mpfi_set_function_state(mpfi_diam_rel(ptr_ret, ptr_self));
|
548
|
+
return val_ret;
|
549
|
+
}
|
550
|
+
|
551
|
+
static VALUE r_mpfi_diam (int argc, VALUE *argv, VALUE self){
|
552
|
+
MPFI *ptr_self;
|
553
|
+
r_mpfi_get_struct(ptr_self, self);
|
554
|
+
VALUE val_ret;
|
555
|
+
MPFR *ptr_ret;
|
556
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
557
|
+
r_mpfi_set_function_state(mpfi_diam(ptr_ret, ptr_self));
|
558
|
+
return val_ret;
|
559
|
+
}
|
560
|
+
|
561
|
+
static VALUE r_mpfi_mag (int argc, VALUE *argv, VALUE self){
|
562
|
+
MPFI *ptr_self;
|
563
|
+
r_mpfi_get_struct(ptr_self, self);
|
564
|
+
VALUE val_ret;
|
565
|
+
MPFR *ptr_ret;
|
566
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
567
|
+
r_mpfi_set_function_state(mpfi_mag(ptr_ret, ptr_self));
|
568
|
+
return val_ret;
|
569
|
+
}
|
570
|
+
|
571
|
+
static VALUE r_mpfi_mig (int argc, VALUE *argv, VALUE self){
|
572
|
+
MPFI *ptr_self;
|
573
|
+
r_mpfi_get_struct(ptr_self, self);
|
574
|
+
VALUE val_ret;
|
575
|
+
MPFR *ptr_ret;
|
576
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
577
|
+
r_mpfi_set_function_state(mpfi_mig(ptr_ret, ptr_self));
|
578
|
+
return val_ret;
|
579
|
+
}
|
580
|
+
|
581
|
+
static VALUE r_mpfi_mid (int argc, VALUE *argv, VALUE self){
|
582
|
+
MPFI *ptr_self;
|
583
|
+
r_mpfi_get_struct(ptr_self, self);
|
584
|
+
VALUE val_ret;
|
585
|
+
MPFR *ptr_ret;
|
586
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
587
|
+
r_mpfi_set_function_state(mpfi_mid(ptr_ret, ptr_self));
|
588
|
+
return val_ret;
|
589
|
+
}
|
590
|
+
|
591
|
+
static VALUE r_mpfi_mid_interval (int argc, VALUE *argv, VALUE self){
|
592
|
+
MPFI *ptr_self, *ptr_ret;
|
593
|
+
r_mpfi_get_struct(ptr_self, self);
|
594
|
+
VALUE val_ret;
|
595
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
596
|
+
mpfi_mid_interval(ptr_ret, ptr_self);
|
597
|
+
return val_ret;
|
598
|
+
}
|
599
|
+
|
600
|
+
static VALUE r_mpfi_alea (int argc, VALUE *argv, VALUE self){
|
601
|
+
MPFI *ptr_self;
|
602
|
+
r_mpfi_get_struct(ptr_self, self);
|
603
|
+
VALUE val_ret;
|
604
|
+
MPFR *ptr_ret;
|
605
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
606
|
+
mpfi_alea(ptr_ret, ptr_self);
|
607
|
+
return val_ret;
|
608
|
+
}
|
609
|
+
|
610
|
+
/* ------------------------------ Interval Functions with Floating-point Results end ------------------------------ */
|
611
|
+
|
612
|
+
/* ------------------------------ Conversion Functions start ------------------------------ */
|
613
|
+
|
614
|
+
static VALUE r_mpfi_get_d(VALUE self){
|
615
|
+
MPFI *ptr_self;
|
616
|
+
r_mpfi_get_struct(ptr_self, self);
|
617
|
+
return rb_float_new(mpfi_get_d(ptr_self));
|
618
|
+
}
|
619
|
+
|
620
|
+
static VALUE r_mpfi_get_fr(VALUE self){
|
621
|
+
MPFI *ptr_self;
|
622
|
+
r_mpfi_get_struct(ptr_self, self);
|
623
|
+
VALUE val_ret;
|
624
|
+
MPFR *ptr_ret;
|
625
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, mpfi_get_prec(ptr_self));
|
626
|
+
mpfi_get_fr(ptr_ret, ptr_self);
|
627
|
+
return val_ret;
|
628
|
+
}
|
629
|
+
/* ------------------------------ Conversion Functions end ------------------------------ */
|
630
|
+
|
631
|
+
/* ------------------------------ Functions Operating on Endpoints start ------------------------------ */
|
632
|
+
|
633
|
+
static VALUE r_mpfi_get_left (VALUE self){
|
634
|
+
VALUE val_ret;
|
635
|
+
MPFI *ptr_self;
|
636
|
+
MPFR *ptr_ret;
|
637
|
+
r_mpfi_get_struct(ptr_self, self);
|
638
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, mpfi_get_prec(ptr_self));
|
639
|
+
mpfi_get_left(ptr_ret, ptr_self);
|
640
|
+
return val_ret;
|
641
|
+
}
|
642
|
+
|
643
|
+
static VALUE r_mpfi_get_right (VALUE self){
|
644
|
+
VALUE val_ret;
|
645
|
+
MPFI *ptr_self;
|
646
|
+
MPFR *ptr_ret;
|
647
|
+
r_mpfi_get_struct(ptr_self, self);
|
648
|
+
r_mpfr_make_struct_init2(val_ret, ptr_ret, mpfi_get_prec(ptr_self));
|
649
|
+
mpfi_get_right(ptr_ret, ptr_self);
|
650
|
+
return val_ret;
|
651
|
+
}
|
652
|
+
|
653
|
+
static VALUE r_mpfi_revert_if_needed (VALUE self){
|
654
|
+
MPFI *ptr_self;
|
655
|
+
r_mpfi_get_struct(ptr_self, self);
|
656
|
+
if(mpfi_revert_if_needed(ptr_self) != 0){
|
657
|
+
return Qtrue;
|
658
|
+
}else{
|
659
|
+
return Qnil;
|
660
|
+
};
|
661
|
+
}
|
662
|
+
|
663
|
+
static VALUE r_mpfi_put (VALUE self, VALUE other){
|
664
|
+
MPFI *ptr_self;
|
665
|
+
r_mpfi_get_struct(ptr_self, self);
|
666
|
+
|
667
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
|
668
|
+
MPFI *ptr_other;
|
669
|
+
r_mpfi_get_struct(ptr_other, other);
|
670
|
+
r_mpfi_set_function_state(mpfi_put(ptr_self, ptr_other));
|
671
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
|
672
|
+
MPFR *ptr_other;
|
673
|
+
r_mpfr_get_struct(ptr_other, other);
|
674
|
+
r_mpfi_set_function_state(mpfi_put_fr(ptr_self, ptr_other));
|
675
|
+
}else if(TYPE(other) == T_FIXNUM){
|
676
|
+
r_mpfi_set_function_state(mpfi_put_si(ptr_self, FIX2LONG(other)));
|
677
|
+
}else if(TYPE(other) == T_FLOAT){
|
678
|
+
r_mpfi_set_function_state(mpfi_put_d(ptr_self, NUM2DBL(other)));
|
679
|
+
}else{
|
680
|
+
MPFI *ptr_other;
|
681
|
+
volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
|
682
|
+
r_mpfi_get_struct(ptr_other, tmp_other);
|
683
|
+
r_mpfi_set_function_state(mpfi_put(ptr_self, ptr_other));
|
684
|
+
}
|
685
|
+
return self;
|
686
|
+
}
|
687
|
+
|
688
|
+
static VALUE r_mpfi_interv (VALUE self, VALUE a1, VALUE a2){
|
689
|
+
MPFI *ptr_self;
|
690
|
+
r_mpfi_get_struct(ptr_self, self);
|
691
|
+
|
692
|
+
if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, a1)) && RTEST(rb_funcall(__mpfr_class__, eqq, 1, a2))){
|
693
|
+
MPFR *ptr_a1, *ptr_a2;
|
694
|
+
r_mpfr_get_struct(ptr_a1, a1);
|
695
|
+
r_mpfr_get_struct(ptr_a2, a2);
|
696
|
+
r_mpfi_set_function_state(mpfi_interv_fr(ptr_self, ptr_a1, ptr_a2));
|
697
|
+
}else if((TYPE(a1) == T_FIXNUM) && (TYPE(a2) == T_FIXNUM)){
|
698
|
+
r_mpfi_set_function_state(mpfi_interv_si(ptr_self, FIX2LONG(a1), FIX2LONG(a2)));
|
699
|
+
}else if((TYPE(a1) == T_FLOAT) && (TYPE(a2) == T_FLOAT)){
|
700
|
+
r_mpfi_set_function_state(mpfi_interv_d(ptr_self, NUM2DBL(a1), NUM2DBL(a2)));
|
701
|
+
}else{
|
702
|
+
MPFR *ptr_a1, *ptr_a2;
|
703
|
+
volatile VALUE tmp_a1 = r_mpfr_new_fr_obj(a1);
|
704
|
+
r_mpfr_get_struct(ptr_a1, tmp_a1);
|
705
|
+
volatile VALUE tmp_a2 = r_mpfr_new_fr_obj(a2);
|
706
|
+
r_mpfr_get_struct(ptr_a2, tmp_a2);
|
707
|
+
r_mpfi_set_function_state(mpfi_interv_fr(ptr_self, ptr_a1, ptr_a2));
|
708
|
+
}
|
709
|
+
return self;
|
710
|
+
}
|
711
|
+
|
712
|
+
static VALUE r_mpfi_interval (int argc, VALUE *argv, VALUE self){
|
713
|
+
VALUE val_ret;
|
714
|
+
MPFI *ptr_ret;
|
715
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
|
716
|
+
|
717
|
+
if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[0])) && RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
|
718
|
+
MPFR *ptr_a0, *ptr_a1;
|
719
|
+
r_mpfr_get_struct(ptr_a0, argv[0]);
|
720
|
+
r_mpfr_get_struct(ptr_a1, argv[1]);
|
721
|
+
r_mpfi_set_function_state(mpfi_interv_fr(ptr_ret, ptr_a0, ptr_a1));
|
722
|
+
}else if((TYPE(argv[0]) == T_FIXNUM) && (TYPE(argv[1]) == T_FIXNUM)){
|
723
|
+
r_mpfi_set_function_state(mpfi_interv_si(ptr_ret, FIX2LONG(argv[0]), FIX2LONG(argv[1])));
|
724
|
+
}else if((TYPE(argv[0]) == T_FLOAT) && (TYPE(argv[1]) == T_FLOAT)){
|
725
|
+
r_mpfi_set_function_state(mpfi_interv_d(ptr_ret, NUM2DBL(argv[0]), NUM2DBL(argv[1])));
|
726
|
+
}else{
|
727
|
+
/* printf("r_mpfi_interval [start]\n"); */
|
728
|
+
MPFR *ptr_a0, *ptr_a1;
|
729
|
+
volatile VALUE tmp1 = r_mpfr_new_fr_obj(argv[0]), tmp2 = r_mpfr_new_fr_obj(argv[1]);
|
730
|
+
r_mpfr_get_struct(ptr_a0, tmp1);
|
731
|
+
r_mpfr_get_struct(ptr_a1, tmp2);
|
732
|
+
/* volatile VALUE tmp_argv0 = r_mpfr_new_fr_obj(argv[0]);
|
733
|
+
r_mpfr_get_struct(ptr_a0, tmp_argv0); */
|
734
|
+
/* volatile VALUE tmp_argv1 = r_mpfr_new_fr_obj(argv[1]);
|
735
|
+
r_mpfr_get_struct(ptr_a1, tmp_argv1); */
|
736
|
+
r_mpfi_set_function_state(mpfi_interv_fr(ptr_ret, ptr_a0, ptr_a1));
|
737
|
+
/* printf("r_mpfi_interval [end]\n"); */
|
738
|
+
}
|
739
|
+
return val_ret;
|
740
|
+
}
|
741
|
+
|
742
|
+
static VALUE r_mpfi_endpoints (VALUE self){
|
743
|
+
VALUE val_left, val_right;
|
744
|
+
MPFI *ptr_self;
|
745
|
+
MPFR *ptr_left, *ptr_right;
|
746
|
+
r_mpfi_get_struct(ptr_self, self);
|
747
|
+
r_mpfr_make_struct_init2(val_left, ptr_left, mpfi_get_prec(ptr_self));
|
748
|
+
r_mpfr_make_struct_init2(val_right, ptr_right, mpfi_get_prec(ptr_self));
|
749
|
+
mpfi_get_left(ptr_left, ptr_self);
|
750
|
+
mpfi_get_right(ptr_right, ptr_self);
|
751
|
+
return rb_ary_new3(2, val_left, val_right);
|
752
|
+
}
|
753
|
+
|
754
|
+
/* ------------------------------ Functions Operating on Endpoints end ------------------------------ */
|
755
|
+
|
756
|
+
/* ------------------------------ Set Functions on Intervals start ------------------------------ */
|
757
|
+
|
758
|
+
/* This method corresponds to mpfi_is_strictly_inside. */
|
759
|
+
static VALUE r_mpfi_strictly_include (VALUE self, VALUE other){
|
760
|
+
MPFI *ptr_self, *ptr_other;
|
761
|
+
r_mpfi_get_struct(ptr_self, self);
|
762
|
+
r_mpfi_get_struct(ptr_other, other);
|
763
|
+
if(mpfi_is_strictly_inside(ptr_other, ptr_self) > 0){
|
764
|
+
return Qtrue;
|
765
|
+
}else{
|
766
|
+
return Qnil;
|
767
|
+
}
|
768
|
+
}
|
769
|
+
|
770
|
+
/* This method corresponds to mpfi_is_inside. */
|
771
|
+
static VALUE r_mpfi_include (VALUE self, VALUE other){
|
772
|
+
MPFI *ptr_self;
|
773
|
+
r_mpfi_get_struct(ptr_self, self);
|
774
|
+
int result;
|
775
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
|
776
|
+
MPFI *ptr_other;
|
777
|
+
r_mpfi_get_struct(ptr_other, other);
|
778
|
+
result = mpfi_is_inside(ptr_other, ptr_self);
|
779
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
|
780
|
+
MPFR *ptr_other;
|
781
|
+
r_mpfr_get_struct(ptr_other, other);
|
782
|
+
result = mpfi_is_inside_fr(ptr_other, ptr_self);
|
783
|
+
}else if(TYPE(other) == T_FIXNUM){
|
784
|
+
result = mpfi_is_inside_si(FIX2LONG(other), ptr_self);
|
785
|
+
}else if(TYPE(other) == T_FLOAT){
|
786
|
+
result = mpfi_is_inside_d(NUM2DBL(other), ptr_self);
|
787
|
+
}else{
|
788
|
+
MPFI *ptr_other;
|
789
|
+
volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
|
790
|
+
r_mpfi_get_struct(ptr_other, tmp_other);
|
791
|
+
result = mpfi_is_inside(ptr_other, ptr_self);
|
792
|
+
}
|
793
|
+
if(result > 0){
|
794
|
+
return Qtrue;
|
795
|
+
}else{
|
796
|
+
return Qnil;
|
797
|
+
}
|
798
|
+
}
|
799
|
+
|
800
|
+
static VALUE r_mpfi_is_empty (VALUE self){
|
801
|
+
MPFI *ptr_self;
|
802
|
+
r_mpfi_get_struct(ptr_self, self);
|
803
|
+
if(mpfi_is_empty(ptr_self) > 0){
|
804
|
+
return Qtrue;
|
805
|
+
}else{
|
806
|
+
return Qnil;
|
807
|
+
}
|
808
|
+
}
|
809
|
+
|
810
|
+
/* If the intersection of two intervals is empty, this method returns nil.
|
811
|
+
Otherwise, it returns the intersection. */
|
812
|
+
static VALUE r_mpfi_intersect (int argc, VALUE *argv, VALUE self){
|
813
|
+
MPFI *ptr_self, *ptr_a0, *ptr_ret;
|
814
|
+
r_mpfi_get_struct(ptr_self, self);
|
815
|
+
r_mpfi_get_struct(ptr_a0, argv[0]);
|
816
|
+
VALUE val_ret;
|
817
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
818
|
+
r_mpfi_set_function_state(mpfi_intersect(ptr_ret, ptr_self, ptr_a0));
|
819
|
+
if(mpfi_is_empty(ptr_ret) > 0){
|
820
|
+
return Qnil;
|
821
|
+
}else{
|
822
|
+
return val_ret;
|
823
|
+
}
|
824
|
+
}
|
825
|
+
|
826
|
+
/* This method returns the intersection of two intervals.
|
827
|
+
The returned value may be empty interval. */
|
828
|
+
static VALUE r_mpfi_intersect2 (int argc, VALUE *argv, VALUE self){
|
829
|
+
MPFI *ptr_self, *ptr_a0, *ptr_ret;
|
830
|
+
r_mpfi_get_struct(ptr_self, self);
|
831
|
+
r_mpfi_get_struct(ptr_a0, argv[0]);
|
832
|
+
VALUE val_ret;
|
833
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
834
|
+
r_mpfi_set_function_state(mpfi_intersect(ptr_ret, ptr_self, ptr_a0));
|
835
|
+
return val_ret;
|
836
|
+
}
|
837
|
+
|
838
|
+
static VALUE r_mpfi_union (int argc, VALUE *argv, VALUE self){
|
839
|
+
MPFI *ptr_self, *ptr_a0, *ptr_ret;
|
840
|
+
r_mpfi_get_struct(ptr_self, self);
|
841
|
+
r_mpfi_get_struct(ptr_a0, argv[0]);
|
842
|
+
VALUE val_ret;
|
843
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
844
|
+
r_mpfi_set_function_state(mpfi_union(ptr_ret, ptr_self, ptr_a0));
|
845
|
+
return val_ret;
|
846
|
+
}
|
847
|
+
|
848
|
+
/* ------------------------------ Set Functions on Intervals end ------------------------------ */
|
849
|
+
|
850
|
+
/* ------------------------------ Miscellaneous Interval Functions start ------------------------------ */
|
851
|
+
|
852
|
+
static VALUE r_mpfi_increase (VALUE self, VALUE a0){
|
853
|
+
MPFI *ptr_self;
|
854
|
+
r_mpfi_get_struct(ptr_self, self);
|
855
|
+
MPFR *ptr_a0;
|
856
|
+
volatile VALUE tmp_a0 = r_mpfr_new_fr_obj(a0);
|
857
|
+
r_mpfr_get_struct(ptr_a0, tmp_a0);
|
858
|
+
r_mpfi_set_function_state(mpfi_increase(ptr_self, ptr_a0));
|
859
|
+
return self;
|
860
|
+
}
|
861
|
+
|
862
|
+
static VALUE r_mpfi_blow (int argc, VALUE *argv, VALUE self){
|
863
|
+
MPFI *ptr_self, *ptr_ret;
|
864
|
+
r_mpfi_get_struct(ptr_self, self);
|
865
|
+
VALUE val_ret;
|
866
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
867
|
+
r_mpfi_set_function_state(mpfi_blow(ptr_ret, ptr_self, NUM2DBL(argv[0])));
|
868
|
+
return val_ret;
|
869
|
+
}
|
870
|
+
|
871
|
+
static VALUE r_mpfi_bisect (int argc, VALUE *argv, VALUE self){
|
872
|
+
MPFI *ptr_self, *ptr_ret1, *ptr_ret2;
|
873
|
+
r_mpfi_get_struct(ptr_self, self);
|
874
|
+
int prec = r_mpfr_prec_from_optional_argument(0, 1, argc, argv);
|
875
|
+
VALUE val_ret1, val_ret2;
|
876
|
+
r_mpfi_make_struct_init2(val_ret1, ptr_ret1, prec);
|
877
|
+
r_mpfi_make_struct_init2(val_ret2, ptr_ret2, prec);
|
878
|
+
r_mpfi_set_function_state(mpfi_bisect(ptr_ret1, ptr_ret2, ptr_self));
|
879
|
+
return rb_ary_new3(2, val_ret1, val_ret2);
|
880
|
+
}
|
881
|
+
|
882
|
+
/* Retrun 0 if this function puts subdivision to *ret. */
|
883
|
+
/* Otherwise, return -1. */
|
884
|
+
void r_mpfi_subdivision_func(int num, MPFI *ret[], mpfi_t x){
|
885
|
+
int i;
|
886
|
+
mpfr_t l;
|
887
|
+
mpfr_init(l);
|
888
|
+
mpfr_sub(l, r_mpfi_right_ptr(x), r_mpfi_left_ptr(x), GMP_RNDD);
|
889
|
+
mpfr_div_si(l, l, num, GMP_RNDD);
|
890
|
+
mpfr_t x_diam;
|
891
|
+
mpfr_init(x_diam);
|
892
|
+
mpfi_diam_abs(x_diam, x);
|
893
|
+
if(mpfr_cmp(x_diam, l) > 0 && num > 1){
|
894
|
+
mpfr_set(r_mpfi_left_ptr(ret[0]), r_mpfi_left_ptr(x), GMP_RNDN);
|
895
|
+
mpfr_add(r_mpfi_right_ptr(ret[0]), r_mpfi_left_ptr(ret[0]), l, GMP_RNDU);
|
896
|
+
|
897
|
+
for(i = 1; i < num - 1; i ++){
|
898
|
+
mpfr_set(r_mpfi_left_ptr(ret[i]), r_mpfi_right_ptr(ret[i - 1]), GMP_RNDN);
|
899
|
+
mpfr_add(r_mpfi_right_ptr(ret[i]), r_mpfi_left_ptr(ret[i]), l, GMP_RNDU);
|
900
|
+
}
|
901
|
+
|
902
|
+
mpfr_set(r_mpfi_left_ptr(ret[i]), r_mpfi_right_ptr(ret[i - 1]), GMP_RNDN);
|
903
|
+
mpfr_set(r_mpfi_right_ptr(ret[i]), r_mpfi_right_ptr(x), GMP_RNDN);
|
904
|
+
}else{
|
905
|
+
mpfr_set(r_mpfi_left_ptr(ret[0]), r_mpfi_left_ptr(x), GMP_RNDN);
|
906
|
+
mpfr_set(r_mpfi_right_ptr(ret[0]), r_mpfi_right_ptr(x), GMP_RNDN);
|
907
|
+
}
|
908
|
+
mpfr_clear(x_diam);
|
909
|
+
mpfr_clear(l);
|
910
|
+
}
|
911
|
+
|
912
|
+
static VALUE r_mpfi_subdivision (int argc, VALUE *argv, VALUE self){
|
913
|
+
MPFI *ptr_self;
|
914
|
+
r_mpfi_get_struct(ptr_self, self);
|
915
|
+
int i, num = NUM2INT(argv[0]);
|
916
|
+
int prec = r_mpfr_prec_from_optional_argument(1, 2, argc, argv);
|
917
|
+
MPFI *f[num];
|
918
|
+
VALUE vf[num];
|
919
|
+
for(i = 0; i < num; i++){
|
920
|
+
r_mpfi_make_struct_init2(vf[i], f[i], prec);
|
921
|
+
}
|
922
|
+
r_mpfi_subdivision_func(num, f, ptr_self);
|
923
|
+
return rb_ary_new4(num, vf);
|
924
|
+
}
|
925
|
+
/* ------------------------------ Miscellaneous Interval Functions end ------------------------------ */
|
926
|
+
|
927
|
+
/* ------------------------------ Mathematical Basic Arithmetic Functions start ------------------------------ */
|
928
|
+
|
929
|
+
static VALUE r_mpfi_math_add (int argc, VALUE *argv, VALUE self){
|
930
|
+
VALUE val_ret;
|
931
|
+
MPFI *ptr_a0, *ptr_ret;
|
932
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
|
933
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
934
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
935
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
|
936
|
+
MPFI *ptr_other;
|
937
|
+
r_mpfi_get_struct(ptr_other, argv[1]);
|
938
|
+
r_mpfi_set_function_state(mpfi_add(ptr_ret, ptr_a0, ptr_other));
|
939
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
|
940
|
+
MPFR *ptr_other;
|
941
|
+
r_mpfr_get_struct(ptr_other, argv[1]);
|
942
|
+
r_mpfi_set_function_state(mpfi_add_fr(ptr_ret, ptr_a0, ptr_other));
|
943
|
+
}else if(TYPE(argv[1]) == T_FIXNUM){
|
944
|
+
r_mpfi_set_function_state(mpfi_add_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
|
945
|
+
}else if(TYPE(argv[1]) == T_FLOAT){
|
946
|
+
r_mpfi_set_function_state(mpfi_add_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
|
947
|
+
}else{
|
948
|
+
MPFI *ptr_a2;
|
949
|
+
volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
|
950
|
+
r_mpfi_get_struct(ptr_a2, tmp_argv1);
|
951
|
+
r_mpfi_set_function_state(mpfi_add(ptr_ret, ptr_a0, ptr_a2));
|
952
|
+
}
|
953
|
+
return val_ret;
|
954
|
+
}
|
955
|
+
|
956
|
+
static VALUE r_mpfi_math_sub (int argc, VALUE *argv, VALUE self){
|
957
|
+
VALUE val_ret;
|
958
|
+
MPFI *ptr_a0, *ptr_ret;
|
959
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
|
960
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
961
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
962
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
|
963
|
+
MPFI *ptr_other;
|
964
|
+
r_mpfi_get_struct(ptr_other, argv[1]);
|
965
|
+
r_mpfi_set_function_state(mpfi_sub(ptr_ret, ptr_a0, ptr_other));
|
966
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
|
967
|
+
MPFR *ptr_other;
|
968
|
+
r_mpfr_get_struct(ptr_other, argv[1]);
|
969
|
+
r_mpfi_set_function_state(mpfi_sub_fr(ptr_ret, ptr_a0, ptr_other));
|
970
|
+
}else if(TYPE(argv[1]) == T_FIXNUM){
|
971
|
+
r_mpfi_set_function_state(mpfi_sub_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
|
972
|
+
}else if(TYPE(argv[1]) == T_FLOAT){
|
973
|
+
r_mpfi_set_function_state(mpfi_sub_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
|
974
|
+
}else{
|
975
|
+
MPFI *ptr_a2;
|
976
|
+
volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
|
977
|
+
r_mpfi_get_struct(ptr_a2, tmp_argv1);
|
978
|
+
r_mpfi_set_function_state(mpfi_sub(ptr_ret, ptr_a0, ptr_a2));
|
979
|
+
}
|
980
|
+
return val_ret;
|
981
|
+
}
|
982
|
+
|
983
|
+
static VALUE r_mpfi_math_mul (int argc, VALUE *argv, VALUE self){
|
984
|
+
VALUE val_ret;
|
985
|
+
MPFI *ptr_a0, *ptr_ret;
|
986
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
|
987
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
988
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
989
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
|
990
|
+
MPFI *ptr_other;
|
991
|
+
r_mpfi_get_struct(ptr_other, argv[1]);
|
992
|
+
r_mpfi_set_function_state(mpfi_mul(ptr_ret, ptr_a0, ptr_other));
|
993
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
|
994
|
+
MPFR *ptr_other;
|
995
|
+
r_mpfr_get_struct(ptr_other, argv[1]);
|
996
|
+
r_mpfi_set_function_state(mpfi_mul_fr(ptr_ret, ptr_a0, ptr_other));
|
997
|
+
}else if(TYPE(argv[1]) == T_FIXNUM){
|
998
|
+
r_mpfi_set_function_state(mpfi_mul_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
|
999
|
+
}else if(TYPE(argv[1]) == T_FLOAT){
|
1000
|
+
r_mpfi_set_function_state(mpfi_mul_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
|
1001
|
+
}else{
|
1002
|
+
MPFI *ptr_a2;
|
1003
|
+
volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
|
1004
|
+
r_mpfi_get_struct(ptr_a2, tmp_argv1);
|
1005
|
+
r_mpfi_set_function_state(mpfi_mul(ptr_ret, ptr_a0, ptr_a2));
|
1006
|
+
}
|
1007
|
+
return val_ret;
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
static VALUE r_mpfi_math_div (int argc, VALUE *argv, VALUE self){
|
1011
|
+
VALUE val_ret;
|
1012
|
+
MPFI *ptr_a0, *ptr_ret;
|
1013
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
|
1014
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1015
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1016
|
+
if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
|
1017
|
+
MPFI *ptr_other;
|
1018
|
+
r_mpfi_get_struct(ptr_other, argv[1]);
|
1019
|
+
r_mpfi_set_function_state(mpfi_div(ptr_ret, ptr_a0, ptr_other));
|
1020
|
+
}else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
|
1021
|
+
MPFR *ptr_other;
|
1022
|
+
r_mpfr_get_struct(ptr_other, argv[1]);
|
1023
|
+
r_mpfi_set_function_state(mpfi_div_fr(ptr_ret, ptr_a0, ptr_other));
|
1024
|
+
}else if(TYPE(argv[1]) == T_FIXNUM){
|
1025
|
+
r_mpfi_set_function_state(mpfi_div_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
|
1026
|
+
}else if(TYPE(argv[1]) == T_FLOAT){
|
1027
|
+
r_mpfi_set_function_state(mpfi_div_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
|
1028
|
+
}else{
|
1029
|
+
MPFI *ptr_a2;
|
1030
|
+
volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
|
1031
|
+
r_mpfi_get_struct(ptr_a2, tmp_argv1);
|
1032
|
+
r_mpfi_set_function_state(mpfi_div(ptr_ret, ptr_a0, ptr_a2));
|
1033
|
+
}
|
1034
|
+
return val_ret;
|
1035
|
+
}
|
1036
|
+
|
1037
|
+
static VALUE r_mpfi_math_sqr (int argc, VALUE *argv, VALUE self){
|
1038
|
+
MPFI *ptr_a0, *ptr_ret;
|
1039
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1040
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1041
|
+
VALUE val_ret;
|
1042
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1043
|
+
r_mpfi_set_function_state(mpfi_sqr(ptr_ret, ptr_a0));
|
1044
|
+
return val_ret;
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
static VALUE r_mpfi_math_sqrt (int argc, VALUE *argv, VALUE self){
|
1048
|
+
MPFI *ptr_a0, *ptr_ret;
|
1049
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1050
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1051
|
+
VALUE val_ret;
|
1052
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1053
|
+
r_mpfi_set_function_state(mpfi_sqrt(ptr_ret, ptr_a0));
|
1054
|
+
return val_ret;
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
/* ------------------------------ Mathematical Basic Arithmetic Functions end ------------------------------ */
|
1058
|
+
|
1059
|
+
/* ------------------------------ Special Functions start ------------------------------ */
|
1060
|
+
|
1061
|
+
static VALUE r_mpfi_math_log (int argc, VALUE *argv, VALUE self){
|
1062
|
+
MPFI *ptr_a0, *ptr_ret;
|
1063
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1064
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1065
|
+
VALUE val_ret;
|
1066
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1067
|
+
r_mpfi_set_function_state(mpfi_log(ptr_ret, ptr_a0));
|
1068
|
+
return val_ret;
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
static VALUE r_mpfi_math_exp (int argc, VALUE *argv, VALUE self){
|
1072
|
+
MPFI *ptr_a0, *ptr_ret;
|
1073
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1074
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1075
|
+
VALUE val_ret;
|
1076
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1077
|
+
r_mpfi_set_function_state(mpfi_exp(ptr_ret, ptr_a0));
|
1078
|
+
return val_ret;
|
1079
|
+
}
|
1080
|
+
|
1081
|
+
static VALUE r_mpfi_math_exp2 (int argc, VALUE *argv, VALUE self){
|
1082
|
+
MPFI *ptr_a0, *ptr_ret;
|
1083
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1084
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1085
|
+
VALUE val_ret;
|
1086
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1087
|
+
r_mpfi_set_function_state(mpfi_exp2(ptr_ret, ptr_a0));
|
1088
|
+
return val_ret;
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
static VALUE r_mpfi_math_cos (int argc, VALUE *argv, VALUE self){
|
1092
|
+
MPFI *ptr_a0, *ptr_ret;
|
1093
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1094
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1095
|
+
VALUE val_ret;
|
1096
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1097
|
+
r_mpfi_set_function_state(mpfi_cos(ptr_ret, ptr_a0));
|
1098
|
+
return val_ret;
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
static VALUE r_mpfi_math_sin (int argc, VALUE *argv, VALUE self){
|
1102
|
+
MPFI *ptr_a0, *ptr_ret;
|
1103
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1104
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1105
|
+
VALUE val_ret;
|
1106
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1107
|
+
r_mpfi_set_function_state(mpfi_sin(ptr_ret, ptr_a0));
|
1108
|
+
return val_ret;
|
1109
|
+
}
|
1110
|
+
|
1111
|
+
static VALUE r_mpfi_math_tan (int argc, VALUE *argv, VALUE self){
|
1112
|
+
MPFI *ptr_a0, *ptr_ret;
|
1113
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1114
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1115
|
+
VALUE val_ret;
|
1116
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1117
|
+
r_mpfi_set_function_state(mpfi_tan(ptr_ret, ptr_a0));
|
1118
|
+
return val_ret;
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
static VALUE r_mpfi_math_acos (int argc, VALUE *argv, VALUE self){
|
1122
|
+
MPFI *ptr_a0, *ptr_ret;
|
1123
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1124
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1125
|
+
VALUE val_ret;
|
1126
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1127
|
+
r_mpfi_set_function_state(mpfi_acos(ptr_ret, ptr_a0));
|
1128
|
+
return val_ret;
|
1129
|
+
}
|
1130
|
+
|
1131
|
+
static VALUE r_mpfi_math_asin (int argc, VALUE *argv, VALUE self){
|
1132
|
+
MPFI *ptr_a0, *ptr_ret;
|
1133
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1134
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1135
|
+
VALUE val_ret;
|
1136
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1137
|
+
r_mpfi_set_function_state(mpfi_asin(ptr_ret, ptr_a0));
|
1138
|
+
return val_ret;
|
1139
|
+
}
|
1140
|
+
|
1141
|
+
static VALUE r_mpfi_math_atan (int argc, VALUE *argv, VALUE self){
|
1142
|
+
MPFI *ptr_a0, *ptr_ret;
|
1143
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1144
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1145
|
+
VALUE val_ret;
|
1146
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1147
|
+
r_mpfi_set_function_state(mpfi_atan(ptr_ret, ptr_a0));
|
1148
|
+
return val_ret;
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
static VALUE r_mpfi_math_cosh (int argc, VALUE *argv, VALUE self){
|
1152
|
+
MPFI *ptr_a0, *ptr_ret;
|
1153
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1154
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1155
|
+
VALUE val_ret;
|
1156
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1157
|
+
r_mpfi_set_function_state(mpfi_cosh(ptr_ret, ptr_a0));
|
1158
|
+
return val_ret;
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
static VALUE r_mpfi_math_sinh (int argc, VALUE *argv, VALUE self){
|
1162
|
+
MPFI *ptr_a0, *ptr_ret;
|
1163
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1164
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1165
|
+
VALUE val_ret;
|
1166
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1167
|
+
r_mpfi_set_function_state(mpfi_sinh(ptr_ret, ptr_a0));
|
1168
|
+
return val_ret;
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
static VALUE r_mpfi_math_tanh (int argc, VALUE *argv, VALUE self){
|
1172
|
+
MPFI *ptr_a0, *ptr_ret;
|
1173
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1174
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1175
|
+
VALUE val_ret;
|
1176
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1177
|
+
r_mpfi_set_function_state(mpfi_tanh(ptr_ret, ptr_a0));
|
1178
|
+
return val_ret;
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
static VALUE r_mpfi_math_acosh (int argc, VALUE *argv, VALUE self){
|
1182
|
+
MPFI *ptr_a0, *ptr_ret;
|
1183
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1184
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1185
|
+
VALUE val_ret;
|
1186
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1187
|
+
r_mpfi_set_function_state(mpfi_acosh(ptr_ret, ptr_a0));
|
1188
|
+
return val_ret;
|
1189
|
+
}
|
1190
|
+
|
1191
|
+
static VALUE r_mpfi_math_asinh (int argc, VALUE *argv, VALUE self){
|
1192
|
+
MPFI *ptr_a0, *ptr_ret;
|
1193
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1194
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1195
|
+
VALUE val_ret;
|
1196
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1197
|
+
r_mpfi_set_function_state(mpfi_asinh(ptr_ret, ptr_a0));
|
1198
|
+
return val_ret;
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
static VALUE r_mpfi_math_atanh (int argc, VALUE *argv, VALUE self){
|
1202
|
+
MPFI *ptr_a0, *ptr_ret;
|
1203
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1204
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1205
|
+
VALUE val_ret;
|
1206
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1207
|
+
r_mpfi_set_function_state(mpfi_atanh(ptr_ret, ptr_a0));
|
1208
|
+
return val_ret;
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
static VALUE r_mpfi_math_log1p (int argc, VALUE *argv, VALUE self){
|
1212
|
+
MPFI *ptr_a0, *ptr_ret;
|
1213
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1214
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1215
|
+
VALUE val_ret;
|
1216
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1217
|
+
r_mpfi_set_function_state(mpfi_log1p(ptr_ret, ptr_a0));
|
1218
|
+
return val_ret;
|
1219
|
+
}
|
1220
|
+
|
1221
|
+
static VALUE r_mpfi_math_expm1 (int argc, VALUE *argv, VALUE self){
|
1222
|
+
MPFI *ptr_a0, *ptr_ret;
|
1223
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1224
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1225
|
+
VALUE val_ret;
|
1226
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1227
|
+
r_mpfi_set_function_state(mpfi_expm1(ptr_ret, ptr_a0));
|
1228
|
+
return val_ret;
|
1229
|
+
}
|
1230
|
+
|
1231
|
+
static VALUE r_mpfi_math_log2 (int argc, VALUE *argv, VALUE self){
|
1232
|
+
MPFI *ptr_a0, *ptr_ret;
|
1233
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1234
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1235
|
+
VALUE val_ret;
|
1236
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1237
|
+
r_mpfi_set_function_state(mpfi_log2(ptr_ret, ptr_a0));
|
1238
|
+
return val_ret;
|
1239
|
+
}
|
1240
|
+
|
1241
|
+
static VALUE r_mpfi_math_log10 (int argc, VALUE *argv, VALUE self){
|
1242
|
+
MPFI *ptr_a0, *ptr_ret;
|
1243
|
+
volatile VALUE tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
|
1244
|
+
r_mpfi_get_struct(ptr_a0, tmp_argv0);
|
1245
|
+
VALUE val_ret;
|
1246
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
1247
|
+
r_mpfi_set_function_state(mpfi_log10(ptr_ret, ptr_a0));
|
1248
|
+
return val_ret;
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
static VALUE r_mpfi_math_const_log2 (int argc, VALUE *argv, VALUE self){
|
1252
|
+
MPFI *ptr_ret;
|
1253
|
+
VALUE val_ret;
|
1254
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
1255
|
+
r_mpfi_set_function_state(mpfi_const_log2(ptr_ret));
|
1256
|
+
return val_ret;
|
1257
|
+
}
|
1258
|
+
|
1259
|
+
static VALUE r_mpfi_math_const_pi (int argc, VALUE *argv, VALUE self){
|
1260
|
+
MPFI *ptr_ret;
|
1261
|
+
VALUE val_ret;
|
1262
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
1263
|
+
r_mpfi_set_function_state(mpfi_const_pi(ptr_ret));
|
1264
|
+
return val_ret;
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
static VALUE r_mpfi_math_const_euler (int argc, VALUE *argv, VALUE self){
|
1268
|
+
MPFI *ptr_ret;
|
1269
|
+
VALUE val_ret;
|
1270
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
1271
|
+
r_mpfi_set_function_state(mpfi_const_euler(ptr_ret));
|
1272
|
+
return val_ret;
|
1273
|
+
}
|
1274
|
+
|
1275
|
+
/* ------------------------------ Special Functions end ------------------------------ */
|
1276
|
+
|
1277
|
+
void Init_mpfi(){
|
1278
|
+
r_mpfi_class = rb_define_class("MPFI", rb_cNumeric);
|
1279
|
+
|
1280
|
+
/* ------------------------------ function state start ------------------------------ */
|
1281
|
+
rb_define_class_variable(r_mpfi_class, CLASS_VAL_FUNCTION_STATE, INT2FIX(0));
|
1282
|
+
rb_define_singleton_method(r_mpfi_class, "function_state", r_mpfr_get_function_state, 0);
|
1283
|
+
/* ------------------------------ function state end ------------------------------ */
|
1284
|
+
|
1285
|
+
/* ------------------------------ allocation start ------------------------------ */
|
1286
|
+
rb_define_alloc_func(r_mpfi_class, r_mpfi_alloc);
|
1287
|
+
rb_define_private_method(r_mpfi_class, "initialize", r_mpfi_initialize, -1);
|
1288
|
+
rb_define_private_method(r_mpfi_class, "initialize_copy", r_mpfi_initialize_copy, 1);
|
1289
|
+
|
1290
|
+
rb_define_method(r_mpfi_class, "coerce", r_mpfi_coerce, 1);
|
1291
|
+
rb_define_method(r_mpfi_class, "set", r_mpfi_set, 1);
|
1292
|
+
rb_define_method(r_mpfi_class, "swap", r_mpfi_swap, 1);
|
1293
|
+
/* ------------------------------ allocation end ------------------------------ */
|
1294
|
+
|
1295
|
+
/* ------------------------------ Rounding Modes and Precision Handling start ------------------------------*/
|
1296
|
+
rb_define_method(r_mpfi_class, "set_prec", r_mpfi_set_prec, 1);
|
1297
|
+
rb_define_method(r_mpfi_class, "get_prec", r_mpfi_get_prec, 0);
|
1298
|
+
rb_define_method(r_mpfi_class, "round_prec", r_mpfi_round_prec, 1);
|
1299
|
+
/* ------------------------------ Rounding Modes and Precision Handling end ------------------------------*/
|
1300
|
+
|
1301
|
+
/* ------------------------------ string start ------------------------------ */
|
1302
|
+
rb_define_method(r_mpfi_class, "inspect", r_mpfi_inspect, 0);
|
1303
|
+
|
1304
|
+
rb_define_method(r_mpfi_class, "to_str_ary", r_mpfi_to_str_ary, 0);
|
1305
|
+
rb_define_method(r_mpfi_class, "to_strf_ary", r_mpfi_to_strf_ary, 1);
|
1306
|
+
/* ------------------------------ string end ------------------------------ */
|
1307
|
+
|
1308
|
+
/* ------------------------------ Basic Arithmetic Functions start ------------------------------ */
|
1309
|
+
rb_define_method(r_mpfi_class, "+", r_mpfi_add, 1);
|
1310
|
+
rb_define_method(r_mpfi_class, "-", r_mpfi_sub, 1);
|
1311
|
+
rb_define_method(r_mpfi_class, "*", r_mpfi_mul, 1);
|
1312
|
+
rb_define_method(r_mpfi_class, "/", r_mpfi_div, 1);
|
1313
|
+
|
1314
|
+
rb_define_method(r_mpfi_class, "mul_2si", r_mpfi_mul_2si, -1);
|
1315
|
+
rb_define_method(r_mpfi_class, "div_2si", r_mpfi_div_2si, -1);
|
1316
|
+
|
1317
|
+
rb_define_method(r_mpfi_class, "neg", r_mpfi_neg, -1);
|
1318
|
+
rb_define_method(r_mpfi_class, "inv", r_mpfi_inv, -1);
|
1319
|
+
rb_define_method(r_mpfi_class, "abs", r_mpfi_abs, -1);
|
1320
|
+
/* ------------------------------ Basic Arithmetic Functions end ------------------------------ */
|
1321
|
+
|
1322
|
+
/* ------------------------------ Comparison Functions start ------------------------------ */
|
1323
|
+
rb_define_method(r_mpfi_class, "cmp", r_mpfi_cmp, 1);
|
1324
|
+
rb_define_method(r_mpfi_class, "is_pos", r_mpfi_is_pos, 0);
|
1325
|
+
rb_define_method(r_mpfi_class, "is_strictly_pos", r_mpfi_is_strictly_pos, 0);
|
1326
|
+
rb_define_method(r_mpfi_class, "is_nonneg", r_mpfi_is_nonneg, 0);
|
1327
|
+
rb_define_method(r_mpfi_class, "is_neg", r_mpfi_is_neg, 0);
|
1328
|
+
rb_define_method(r_mpfi_class, "is_strictly_neg", r_mpfi_is_strictly_neg, 0);
|
1329
|
+
rb_define_method(r_mpfi_class, "is_nonpos", r_mpfi_is_nonpos, 0);
|
1330
|
+
rb_define_method(r_mpfi_class, "is_zero", r_mpfi_is_zero, 0);
|
1331
|
+
rb_define_method(r_mpfi_class, "has_zero", r_mpfi_has_zero, 0);
|
1332
|
+
rb_define_method(r_mpfi_class, "nan_p", r_mpfi_nan_p, 0);
|
1333
|
+
rb_define_method(r_mpfi_class, "inf_p", r_mpfi_inf_p, 0);
|
1334
|
+
rb_define_method(r_mpfi_class, "bounded_p", r_mpfi_bounded_p, 0);
|
1335
|
+
rb_define_method(r_mpfi_class, "equal_p", r_mpfi_equal_p, 1);
|
1336
|
+
|
1337
|
+
rb_define_alias(r_mpfi_class, "cmp", "<=>");
|
1338
|
+
rb_define_alias(r_mpfi_class, "pos?", "is_pos");
|
1339
|
+
rb_define_alias(r_mpfi_class, "strictly_pos?", "is_strictly_pos");
|
1340
|
+
rb_define_alias(r_mpfi_class, "nonneg?", "is_nonneg");
|
1341
|
+
rb_define_alias(r_mpfi_class, "neg?", "is_neg");
|
1342
|
+
rb_define_alias(r_mpfi_class, "strictly_neg?", "is_strictly_neg");
|
1343
|
+
rb_define_alias(r_mpfi_class, "nonpos?", "is_nonpos");
|
1344
|
+
rb_define_alias(r_mpfi_class, "zero?", "is_zero");
|
1345
|
+
rb_define_alias(r_mpfi_class, "has_zero?", "has_zero");
|
1346
|
+
rb_define_alias(r_mpfi_class, "nan?", "nan_p");
|
1347
|
+
rb_define_alias(r_mpfi_class, "inf?", "inf_p");
|
1348
|
+
rb_define_alias(r_mpfi_class, "bounded?", "bounded_p");
|
1349
|
+
rb_define_method(r_mpfi_class, "==", r_mpfi_equal_p, 1);
|
1350
|
+
/* ------------------------------ Comparison Functions end ------------------------------ */
|
1351
|
+
|
1352
|
+
/* ------------------------------ Interval Functions with Floating-point Results start ------------------------------ */
|
1353
|
+
rb_define_method(r_mpfi_class, "diam_abs", r_mpfi_diam_abs, -1);
|
1354
|
+
rb_define_method(r_mpfi_class, "diam_rel", r_mpfi_diam_rel, -1);
|
1355
|
+
rb_define_method(r_mpfi_class, "diam", r_mpfi_diam, -1);
|
1356
|
+
rb_define_method(r_mpfi_class, "mag", r_mpfi_mag, -1);
|
1357
|
+
rb_define_method(r_mpfi_class, "mig", r_mpfi_mig, -1);
|
1358
|
+
rb_define_method(r_mpfi_class, "mid", r_mpfi_mid, -1);
|
1359
|
+
rb_define_method(r_mpfi_class, "mid_interval", r_mpfi_mid_interval, -1);
|
1360
|
+
rb_define_method(r_mpfi_class, "alea", r_mpfi_alea, -1);
|
1361
|
+
/* ------------------------------ Interval Functions with Floating-point Results end ------------------------------ */
|
1362
|
+
|
1363
|
+
/* ------------------------------ Conversion Functions start ------------------------------ */
|
1364
|
+
rb_define_method(r_mpfi_class, "get_d", r_mpfi_get_d, 0);
|
1365
|
+
rb_define_method(r_mpfi_class, "get_fr", r_mpfi_get_fr, 0);
|
1366
|
+
rb_define_alias(r_mpfi_class, "to_f", "get_d");
|
1367
|
+
rb_define_alias(r_mpfi_class, "to_fr", "get_fr");
|
1368
|
+
/* ------------------------------ Conversion Functions end ------------------------------ */
|
1369
|
+
|
1370
|
+
/* ------------------------------ Functions Operating on Endpoints start ------------------------------ */
|
1371
|
+
rb_define_method(r_mpfi_class, "get_left", r_mpfi_get_left, 0);
|
1372
|
+
rb_define_method(r_mpfi_class, "get_right", r_mpfi_get_right, 0);
|
1373
|
+
rb_define_method(r_mpfi_class, "revert_if_needed", r_mpfi_revert_if_needed, 0);
|
1374
|
+
rb_define_method(r_mpfi_class, "put", r_mpfi_put, 1);
|
1375
|
+
rb_define_method(r_mpfi_class, "interv", r_mpfi_interv, 2);
|
1376
|
+
|
1377
|
+
rb_define_alias(r_mpfi_class, "left", "get_left");
|
1378
|
+
rb_define_alias(r_mpfi_class, "right", "get_right");
|
1379
|
+
rb_define_method(r_mpfi_class, "endpoints", r_mpfi_endpoints, 0);
|
1380
|
+
|
1381
|
+
rb_define_singleton_method(r_mpfi_class, "interval", r_mpfi_interval, -1);
|
1382
|
+
/* ------------------------------ Functions Operating on Endpoints end ------------------------------ */
|
1383
|
+
|
1384
|
+
/* ------------------------------ Set Functions on Intervals start ------------------------------ */
|
1385
|
+
rb_define_method(r_mpfi_class, "strictly_include?", r_mpfi_strictly_include, 1);
|
1386
|
+
rb_define_method(r_mpfi_class, "include?", r_mpfi_include, 1);
|
1387
|
+
|
1388
|
+
rb_define_method(r_mpfi_class, "is_empty", r_mpfi_is_empty, 0);
|
1389
|
+
rb_define_method(r_mpfi_class, "intersect", r_mpfi_intersect, -1);
|
1390
|
+
rb_define_method(r_mpfi_class, "intersect2", r_mpfi_intersect2, -1);
|
1391
|
+
rb_define_method(r_mpfi_class, "union", r_mpfi_union, -1);
|
1392
|
+
|
1393
|
+
rb_define_alias(r_mpfi_class, "empty?", "is_empty");
|
1394
|
+
/* ------------------------------ Set Functions on Intervals end ------------------------------ */
|
1395
|
+
|
1396
|
+
/* ------------------------------ Miscellaneous Interval Functions start ------------------------------ */
|
1397
|
+
rb_define_method(r_mpfi_class, "increase", r_mpfi_increase, 1);
|
1398
|
+
rb_define_method(r_mpfi_class, "blow", r_mpfi_blow, -1);
|
1399
|
+
rb_define_method(r_mpfi_class, "bisect", r_mpfi_bisect, -1);
|
1400
|
+
rb_define_method(r_mpfi_class, "subdivision", r_mpfi_subdivision, -1);
|
1401
|
+
/* ------------------------------ Miscellaneous Interval Functions end ------------------------------ */
|
1402
|
+
|
1403
|
+
r_mpfi_math = rb_define_module_under(r_mpfi_class, "Math");
|
1404
|
+
|
1405
|
+
/* ------------------------------ Mathematical Basic Arithmetic Functions start ------------------------------ */
|
1406
|
+
rb_define_module_function(r_mpfi_math, "add", r_mpfi_math_add, -1);
|
1407
|
+
rb_define_module_function(r_mpfi_math, "sub", r_mpfi_math_sub, -1);
|
1408
|
+
rb_define_module_function(r_mpfi_math, "mul", r_mpfi_math_mul, -1);
|
1409
|
+
rb_define_module_function(r_mpfi_math, "div", r_mpfi_math_div, -1);
|
1410
|
+
|
1411
|
+
rb_define_module_function(r_mpfi_math, "sqr", r_mpfi_math_sqr, -1);
|
1412
|
+
rb_define_module_function(r_mpfi_math, "sqrt", r_mpfi_math_sqrt, -1);
|
1413
|
+
/* ------------------------------ Mathematical Basic Arithmetic Functions end ------------------------------ */
|
1414
|
+
|
1415
|
+
/* ------------------------------ Special Functions start ------------------------------ */
|
1416
|
+
rb_define_module_function(r_mpfi_math, "log", r_mpfi_math_log, -1);
|
1417
|
+
rb_define_module_function(r_mpfi_math, "exp", r_mpfi_math_exp, -1);
|
1418
|
+
rb_define_module_function(r_mpfi_math, "exp2", r_mpfi_math_exp2, -1);
|
1419
|
+
rb_define_module_function(r_mpfi_math, "cos", r_mpfi_math_cos, -1);
|
1420
|
+
rb_define_module_function(r_mpfi_math, "sin", r_mpfi_math_sin, -1);
|
1421
|
+
rb_define_module_function(r_mpfi_math, "tan", r_mpfi_math_tan, -1);
|
1422
|
+
rb_define_module_function(r_mpfi_math, "acos", r_mpfi_math_acos, -1);
|
1423
|
+
rb_define_module_function(r_mpfi_math, "asin", r_mpfi_math_asin, -1);
|
1424
|
+
rb_define_module_function(r_mpfi_math, "atan", r_mpfi_math_atan, -1);
|
1425
|
+
rb_define_module_function(r_mpfi_math, "cosh", r_mpfi_math_cosh, -1);
|
1426
|
+
rb_define_module_function(r_mpfi_math, "sinh", r_mpfi_math_sinh, -1);
|
1427
|
+
rb_define_module_function(r_mpfi_math, "tanh", r_mpfi_math_tanh, -1);
|
1428
|
+
rb_define_module_function(r_mpfi_math, "acosh", r_mpfi_math_acosh, -1);
|
1429
|
+
rb_define_module_function(r_mpfi_math, "asinh", r_mpfi_math_asinh, -1);
|
1430
|
+
rb_define_module_function(r_mpfi_math, "atanh", r_mpfi_math_atanh, -1);
|
1431
|
+
rb_define_module_function(r_mpfi_math, "log1p", r_mpfi_math_log1p, -1);
|
1432
|
+
rb_define_module_function(r_mpfi_math, "expm1", r_mpfi_math_expm1, -1);
|
1433
|
+
rb_define_module_function(r_mpfi_math, "log2", r_mpfi_math_log2, -1);
|
1434
|
+
rb_define_module_function(r_mpfi_math, "log10", r_mpfi_math_log10, -1);
|
1435
|
+
rb_define_module_function(r_mpfi_math, "const_log2", r_mpfi_math_const_log2, -1);
|
1436
|
+
rb_define_module_function(r_mpfi_math, "const_pi", r_mpfi_math_const_pi, -1);
|
1437
|
+
rb_define_module_function(r_mpfi_math, "const_euler", r_mpfi_math_const_euler, -1);
|
1438
|
+
/* ------------------------------ Special Functions end ------------------------------ */
|
1439
|
+
|
1440
|
+
eqq = rb_intern("===");
|
1441
|
+
to_s = rb_intern("to_s");
|
1442
|
+
new = rb_intern("new");
|
1443
|
+
class = rb_intern("class");
|
1444
|
+
object_id = rb_intern("object_id");
|
1445
|
+
method_defined = rb_intern("method_defined?");
|
1446
|
+
__mpfi_class__ = rb_eval_string("MPFI");
|
1447
|
+
__mpfr_class__ = rb_eval_string("MPFR");
|
1448
|
+
__sym_to_s__ = rb_eval_string(":to_s");
|
1449
|
+
__sym_to_str__ = rb_eval_string(":to_str");
|
1450
|
+
|
1451
|
+
}
|
1452
|
+
|