ruby-mpfi 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a76096efc1a0b6908a38041051c9d1256e7fad23
4
- data.tar.gz: 38777b753c02e5e4ee0b5cec1981d2866ca61f26
3
+ metadata.gz: e01c430299b5a87c4b8f6d60666a628de85bd95d
4
+ data.tar.gz: 4cf943132b7fe3a93256396753ea8bbd88dbd93f
5
5
  SHA512:
6
- metadata.gz: b1040578a416fe7c44e29c902eb1e3e4c513ae94f72d6bb834290cd075b118eb139ff6c2418f9cadd1b8d7e5f24590e2f83f876b0ca44e15cbd966d400dd1b8b
7
- data.tar.gz: ff1a0f313d749f027d5f86edc99e69e8cff826f323d67cf850f9bffe3cb2e38dc6bd0be2b3f506dbd2bc986c4ce92e1ae3fb26e2a36d2191262635c0477d2bf2
6
+ metadata.gz: 36831fc758bc3d68e65719b44958b615dfb64a4eb157299af23976629a5fb13c93e92f5bf052169f7375eed9491627e2af2f45284af75029cd988a409cf2f77d
7
+ data.tar.gz: 09897dfa3ec6e2eadece450a3978595e32c772eee2471f9ae4fc7d77ebc13dfb0adffd6d9170b9a181582763e68e6a6a2caebbb144b8ca05121a7aeb29e266b1
@@ -4,7 +4,7 @@
4
4
  #include "ruby_mpfi.h"
5
5
  #include "func_mpfi_extention.h"
6
6
 
7
- void mpfi_mid_interval(mpfi_t ret, mpfi_t x){
7
+ void mpfi_mid_interval (mpfi_t ret, mpfi_t x) {
8
8
  mpfr_t left, right;
9
9
  mpfr_init2(left, mpfi_get_prec(x));
10
10
  mpfr_init2(right, mpfi_get_prec(x));
@@ -21,21 +21,20 @@ void mpfi_mid_interval(mpfi_t ret, mpfi_t x){
21
21
 
22
22
  /* Retrun 0 if this function puts subdivision to *ret. */
23
23
  /* Otherwise, return -1. */
24
- int mpfi_subdivision(int num, mpfi_t *ret, mpfi_t x){
24
+ int mpfi_subdivision (int num, mpfi_t *ret, mpfi_t x) {
25
25
  int i, ret_val = -1;
26
- mpfr_t l;
26
+ mpfr_t l, x_diam;
27
27
  mpfr_init(l);
28
28
  mpfr_sub(l, r_mpfi_right_ptr(x), r_mpfi_left_ptr(x), GMP_RNDD);
29
29
  mpfr_div_si(l, l, num, GMP_RNDD);
30
30
 
31
- mpfr_t x_diam;
32
31
  mpfr_init(x_diam);
33
32
  mpfi_diam_abs(x_diam, x);
34
- if(mpfr_cmp(x_diam, l) > 0){
33
+ if (mpfr_cmp(x_diam, l) > 0) {
35
34
  mpfr_set(r_mpfi_left_ptr(*ret), r_mpfi_left_ptr(x), GMP_RNDN);
36
35
  mpfr_add(r_mpfi_right_ptr(*ret), r_mpfi_left_ptr(*ret), l, GMP_RNDU);
37
36
 
38
- for(i = 1; i < num - 1; i ++){
37
+ for (i = 1; i < num - 1; i ++) {
39
38
  mpfr_set(r_mpfi_left_ptr(*ret + i), r_mpfi_right_ptr(*ret + i - 1), GMP_RNDN);
40
39
  mpfr_add(r_mpfi_right_ptr(*ret + i), r_mpfi_left_ptr(*ret + i), l, GMP_RNDU);
41
40
  }
@@ -49,4 +48,3 @@ int mpfi_subdivision(int num, mpfi_t *ret, mpfi_t x){
49
48
  mpfr_clear(l);
50
49
  return ret_val;
51
50
  }
52
-
@@ -1,2 +1,2 @@
1
- void mpfi_mid_interval(mpfi_t ret, mpfi_t x);
2
- int mpfi_subdivision(int num, mpfi_t *ret, mpfi_t x);
1
+ void mpfi_mid_interval (mpfi_t ret, mpfi_t x);
2
+ int mpfi_subdivision (int num, mpfi_t *ret, mpfi_t x);
@@ -9,13 +9,13 @@ static VALUE __mpfi_class__, __mpfr_class__, __sym_to_s__, __sym_to_str__;
9
9
  /* ------------------------------ function state start ------------------------------ */
10
10
 
11
11
  /* Save the value of last function state. */
12
- void r_mpfi_set_function_state(int num)
12
+ void r_mpfi_set_function_state (int num)
13
13
  {
14
14
  rb_cv_set(r_mpfi_class, CLASS_VAL_FUNCTION_STATE, INT2NUM(num));
15
15
  }
16
16
 
17
17
  /* Return state of last function of MPFI. */
18
- VALUE r_mpfi_get_function_state(VALUE self)
18
+ VALUE r_mpfi_get_function_state (VALUE self)
19
19
  {
20
20
  return rb_cv_get(r_mpfi_class, CLASS_VAL_FUNCTION_STATE);
21
21
  }
@@ -24,13 +24,13 @@ VALUE r_mpfi_get_function_state(VALUE self)
24
24
 
25
25
  /* ------------------------------ allocation start ------------------------------ */
26
26
 
27
- void r_mpfi_free(void *ptr)
27
+ void r_mpfi_free (void *ptr)
28
28
  {
29
29
  mpfi_clear(ptr);
30
30
  free(ptr);
31
31
  }
32
32
 
33
- VALUE r_mpfi_make_new_fi_obj(MPFI *ptr)
33
+ VALUE r_mpfi_make_new_fi_obj (MPFI *ptr)
34
34
  {
35
35
  VALUE ret;
36
36
  MPFI *ptr_ret;
@@ -41,16 +41,16 @@ VALUE r_mpfi_make_new_fi_obj(MPFI *ptr)
41
41
 
42
42
  static void r_mpfi_set_interv_from_robjs (MPFI *ptr, VALUE a1, VALUE a2)
43
43
  {
44
- if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, a1)) && RTEST(rb_funcall(__mpfr_class__, eqq, 1, a2))){
44
+ if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, a1)) && RTEST(rb_funcall(__mpfr_class__, eqq, 1, a2))) {
45
45
  MPFR *ptr_a1, *ptr_a2;
46
46
  r_mpfr_get_struct(ptr_a1, a1);
47
47
  r_mpfr_get_struct(ptr_a2, a2);
48
48
  r_mpfi_set_function_state(mpfi_interv_fr(ptr, ptr_a1, ptr_a2));
49
- }else if((TYPE(a1) == T_FIXNUM) && (TYPE(a2) == T_FIXNUM)){
49
+ } else if ((TYPE(a1) == T_FIXNUM) && (TYPE(a2) == T_FIXNUM)) {
50
50
  r_mpfi_set_function_state(mpfi_interv_si(ptr, FIX2LONG(a1), FIX2LONG(a2)));
51
- }else if((TYPE(a1) == T_FLOAT) && (TYPE(a2) == T_FLOAT)){
51
+ } else if ((TYPE(a1) == T_FLOAT) && (TYPE(a2) == T_FLOAT)) {
52
52
  r_mpfi_set_function_state(mpfi_interv_d(ptr, NUM2DBL(a1), NUM2DBL(a2)));
53
- }else{
53
+ } else {
54
54
  MPFR *ptr_a1, *ptr_a2;
55
55
  volatile VALUE tmp_a1 = r_mpfr_new_fr_obj(a1);
56
56
  volatile VALUE tmp_a2 = r_mpfr_new_fr_obj(a2);
@@ -76,29 +76,29 @@ static void r_mpfi_set_from_string (MPFI *ptr, VALUE obj)
76
76
  char *str;
77
77
  if (RTEST(rb_funcall(rb_funcall(obj, class, 0), method_defined, 1, __sym_to_str__))) {
78
78
  str = StringValuePtr(obj);
79
- } else if (RTEST(rb_funcall(rb_funcall(obj, class, 0), method_defined, 1, __sym_to_s__))){
79
+ } else if (RTEST(rb_funcall(rb_funcall(obj, class, 0), method_defined, 1, __sym_to_s__))) {
80
80
  VALUE tmp = rb_funcall(obj, to_s, 0);
81
81
  str = StringValuePtr(tmp);
82
82
  } else {
83
83
  rb_raise(rb_eArgError, "Can not convert to strings.");
84
84
  }
85
- if(mpfi_set_str(ptr, str, 10) != 0) {
85
+ if (mpfi_set_str(ptr, str, 10) != 0) {
86
86
  rb_raise(rb_eArgError, "Invalid string format of MPFI initialization: \"%s\"", str);
87
87
  }
88
88
  }
89
89
 
90
- void r_mpfi_set_robj(MPFI *ptr, VALUE obj)
90
+ void r_mpfi_set_robj (MPFI *ptr, VALUE obj)
91
91
  {
92
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, obj))){
92
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, obj))) {
93
93
  MPFI *ptr_obj;
94
94
  r_mpfi_get_struct(ptr_obj, obj);
95
95
  mpfi_set(ptr, ptr_obj);
96
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, obj))){
96
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, obj))) {
97
97
  MPFR *ptr_obj;
98
98
  r_mpfr_get_struct(ptr_obj, obj);
99
99
  mpfi_set_fr(ptr, ptr_obj);
100
- }else{
101
- switch(TYPE(obj)){
100
+ } else {
101
+ switch (TYPE(obj)) {
102
102
  case T_FLOAT:
103
103
  mpfi_set_d(ptr, NUM2DBL(obj));
104
104
  break;
@@ -115,11 +115,11 @@ void r_mpfi_set_robj(MPFI *ptr, VALUE obj)
115
115
  }
116
116
  }
117
117
 
118
- VALUE r_mpfi_new_fi_obj(VALUE obj)
118
+ VALUE r_mpfi_new_fi_obj (VALUE obj)
119
119
  {
120
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, obj))){
120
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, obj))) {
121
121
  return obj;
122
- }else{
122
+ } else {
123
123
  return rb_funcall(__mpfi_class__, new, 1, obj);
124
124
  }
125
125
  }
@@ -127,16 +127,16 @@ VALUE r_mpfi_new_fi_obj(VALUE obj)
127
127
  /* Initializing and Assigning Intervals */
128
128
 
129
129
  /* Allocation function. */
130
- static VALUE r_mpfi_alloc(VALUE self)
130
+ static VALUE r_mpfi_alloc (VALUE self)
131
131
  {
132
132
  MPFI *ptr;
133
133
  r_mpfi_make_struct(self, ptr);
134
134
  return self;
135
135
  }
136
136
 
137
- static void r_mpfi_set_initial_value(MPFI *ptr, int argc, VALUE *argv)
137
+ static void r_mpfi_set_initial_value (MPFI *ptr, int argc, VALUE *argv)
138
138
  {
139
- switch(argc){
139
+ switch (argc) {
140
140
  case 0:
141
141
  mpfi_init(ptr);
142
142
  break;
@@ -155,7 +155,7 @@ static void r_mpfi_set_initial_value(MPFI *ptr, int argc, VALUE *argv)
155
155
  }
156
156
 
157
157
  /* Return new MPFI instance. The same arguments as MPFI.new is acceptable. */
158
- static VALUE r_mpfi_global_new(int argc, VALUE *argv, VALUE self)
158
+ static VALUE r_mpfi_global_new (int argc, VALUE *argv, VALUE self)
159
159
  {
160
160
  MPFI *ptr;
161
161
  VALUE val;
@@ -169,7 +169,7 @@ static VALUE r_mpfi_global_new(int argc, VALUE *argv, VALUE self)
169
169
  which is MPFR, Float, Fixnum, String, and Array having two elements.
170
170
  The string must be "number" or "[number1, number2]" (refer MPFI documents).
171
171
  The second one is precision and its class is Fixnum. */
172
- static VALUE r_mpfi_initialize(int argc, VALUE *argv, VALUE self)
172
+ static VALUE r_mpfi_initialize (int argc, VALUE *argv, VALUE self)
173
173
  {
174
174
  MPFI *ptr;
175
175
  r_mpfi_get_struct(ptr, self);
@@ -178,7 +178,7 @@ static VALUE r_mpfi_initialize(int argc, VALUE *argv, VALUE self)
178
178
  }
179
179
 
180
180
  /* initialize_copy. */
181
- static VALUE r_mpfi_initialize_copy(VALUE self, VALUE other)
181
+ static VALUE r_mpfi_initialize_copy (VALUE self, VALUE other)
182
182
  {
183
183
  MPFI *ptr_self, *ptr_other;
184
184
  r_mpfi_get_struct(ptr_self, self);
@@ -189,7 +189,7 @@ static VALUE r_mpfi_initialize_copy(VALUE self, VALUE other)
189
189
  }
190
190
 
191
191
  /* Return array which have MPFI instance converted to from p1 and self. */
192
- static VALUE r_mpfi_coerce(VALUE self, VALUE other)
192
+ static VALUE r_mpfi_coerce (VALUE self, VALUE other)
193
193
  {
194
194
  VALUE val_other;
195
195
  MPFI *ptr_self, *ptr_other;
@@ -218,12 +218,12 @@ static VALUE r_mpfi_swap (VALUE self, VALUE other)
218
218
  return self;
219
219
  }
220
220
 
221
- char *r_mpfi_dump_to_string(MPFI *ptr_s)
221
+ char *r_mpfi_dump_to_string (MPFI *ptr_s)
222
222
  {
223
223
  char *ret_str, *str_right, *str_left;
224
224
  str_left = r_mpfr_dump_to_string(r_mpfi_left_ptr(ptr_s));
225
225
  str_right = r_mpfr_dump_to_string(r_mpfi_right_ptr(ptr_s));
226
- if(!mpfr_asprintf(&ret_str, "%s %s", str_left, str_right)) {
226
+ if (!mpfr_asprintf(&ret_str, "%s %s", str_left, str_right)) {
227
227
  rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
228
228
  }
229
229
  mpfr_free_str(str_left);
@@ -231,7 +231,7 @@ char *r_mpfi_dump_to_string(MPFI *ptr_s)
231
231
  return ret_str;
232
232
  }
233
233
 
234
- static VALUE r_mpfi_marshal_dump(VALUE self)
234
+ static VALUE r_mpfi_marshal_dump (VALUE self)
235
235
  {
236
236
  MPFI *ptr_s;
237
237
  char *ret_str;
@@ -243,7 +243,7 @@ static VALUE r_mpfi_marshal_dump(VALUE self)
243
243
  return ret_val;
244
244
  }
245
245
 
246
- void r_mpfi_load_string(MPFI *ptr_s, const char *dump)
246
+ void r_mpfi_load_string (MPFI *ptr_s, const char *dump)
247
247
  {
248
248
  int i;
249
249
  char *left;
@@ -260,7 +260,7 @@ void r_mpfi_load_string(MPFI *ptr_s, const char *dump)
260
260
  r_mpfr_load_string(r_mpfi_right_ptr(ptr_s), dump + i);
261
261
  }
262
262
 
263
- static VALUE r_mpfi_marshal_load(VALUE self, VALUE dump_string)
263
+ static VALUE r_mpfi_marshal_load (VALUE self, VALUE dump_string)
264
264
  {
265
265
  MPFI *ptr_s;
266
266
  char *dump;
@@ -284,7 +284,7 @@ static VALUE r_mpfi_set_prec (VALUE self, VALUE prec)
284
284
  {
285
285
  MPFI *ptr_self;
286
286
  r_mpfi_get_struct(ptr_self, self);
287
- /* if(mpfi_set_prec(ptr_self, NUM2INT(prec)) != 0){ */
287
+ /* if (mpfi_set_prec(ptr_self, NUM2INT(prec)) != 0) { */
288
288
  /* rb_raise(rb_eRuntimeError, "Memory allocation failed for mpfi_set_prec."); */
289
289
  /* } */
290
290
  mpfi_set_prec(ptr_self, NUM2INT(prec));
@@ -314,15 +314,15 @@ static VALUE r_mpfi_round_prec (VALUE self, VALUE prec)
314
314
  /* ------------------------------ string start ------------------------------ */
315
315
 
316
316
  /* String for inspect. */
317
- static VALUE r_mpfi_inspect(VALUE self)
317
+ static VALUE r_mpfi_inspect (VALUE self)
318
318
  {
319
319
  MPFI *ptr_s;
320
320
  char *ret_str;
321
321
  VALUE ret_val;
322
322
  r_mpfi_get_struct(ptr_s, self);
323
323
  if (!mpfr_asprintf(&ret_str, "#<MPFI:%lx,['%.Re %.Re'],%d>",
324
- NUM2LONG(rb_funcall(self, object_id, 0)), r_mpfi_left_ptr(ptr_s),
325
- r_mpfi_right_ptr(ptr_s), mpfi_get_prec(ptr_s))) {
324
+ NUM2LONG(rb_funcall(self, object_id, 0)), r_mpfi_left_ptr(ptr_s),
325
+ r_mpfi_right_ptr(ptr_s), mpfi_get_prec(ptr_s))) {
326
326
  rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
327
327
  }
328
328
  ret_val = rb_str_new2(ret_str);
@@ -331,7 +331,7 @@ static VALUE r_mpfi_inspect(VALUE self)
331
331
  }
332
332
 
333
333
  /* Return array having two strings to which endpoints is converted. */
334
- static VALUE r_mpfi_to_str_ary(VALUE self)
334
+ static VALUE r_mpfi_to_str_ary (VALUE self)
335
335
  {
336
336
  MPFI *ptr_self;
337
337
  char *ret_str1, *ret_str2;
@@ -351,7 +351,7 @@ static VALUE r_mpfi_to_str_ary(VALUE self)
351
351
  }
352
352
 
353
353
  /* Return array having two strings to which endpoints are converted by mpfr_asprintf with format_str. */
354
- static VALUE r_mpfi_to_strf_ary(VALUE self, VALUE format_str)
354
+ static VALUE r_mpfi_to_strf_ary (VALUE self, VALUE format_str)
355
355
  {
356
356
  MPFI *ptr_self;
357
357
  char *format, *ret_str1, *ret_str2;
@@ -383,19 +383,19 @@ static VALUE r_mpfi_add (VALUE self, VALUE other)
383
383
  r_mpfi_get_struct(ptr_self, self);
384
384
  r_mpfi_make_struct_init(val_ret, ptr_ret);
385
385
 
386
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
386
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))) {
387
387
  MPFI *ptr_other;
388
388
  r_mpfi_get_struct(ptr_other, other);
389
389
  mpfi_add(ptr_ret, ptr_self, ptr_other);
390
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
390
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))) {
391
391
  MPFR *ptr_other;
392
392
  r_mpfr_get_struct(ptr_other, other);
393
393
  mpfi_add_fr(ptr_ret, ptr_self, ptr_other);
394
- }else if(TYPE(other) == T_FIXNUM){
394
+ } else if (TYPE(other) == T_FIXNUM) {
395
395
  mpfi_add_si(ptr_ret, ptr_self, FIX2LONG(other));
396
- }else if(TYPE(other) == T_FLOAT){
396
+ } else if (TYPE(other) == T_FLOAT) {
397
397
  mpfi_add_d(ptr_ret, ptr_self, NUM2DBL(other));
398
- }else{
398
+ } else {
399
399
  MPFI *ptr_other;
400
400
  volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
401
401
  r_mpfi_get_struct(ptr_other, tmp_other);
@@ -412,19 +412,19 @@ static VALUE r_mpfi_sub (VALUE self, VALUE other)
412
412
  r_mpfi_get_struct(ptr_self, self);
413
413
  r_mpfi_make_struct_init(val_ret, ptr_ret);
414
414
 
415
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
415
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))) {
416
416
  MPFI *ptr_other;
417
417
  r_mpfi_get_struct(ptr_other, other);
418
418
  mpfi_sub(ptr_ret, ptr_self, ptr_other);
419
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
419
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))) {
420
420
  MPFR *ptr_other;
421
421
  r_mpfr_get_struct(ptr_other, other);
422
422
  mpfi_sub_fr(ptr_ret, ptr_self, ptr_other);
423
- }else if(TYPE(other) == T_FIXNUM){
423
+ } else if (TYPE(other) == T_FIXNUM) {
424
424
  mpfi_sub_si(ptr_ret, ptr_self, FIX2LONG(other));
425
- }else if(TYPE(other) == T_FLOAT){
425
+ } else if (TYPE(other) == T_FLOAT) {
426
426
  mpfi_sub_d(ptr_ret, ptr_self, NUM2DBL(other));
427
- }else{
427
+ } else {
428
428
  MPFI *ptr_other;
429
429
  volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
430
430
  r_mpfi_get_struct(ptr_other, tmp_other);
@@ -441,19 +441,19 @@ static VALUE r_mpfi_mul (VALUE self, VALUE other)
441
441
  r_mpfi_get_struct(ptr_self, self);
442
442
  r_mpfi_make_struct_init(val_ret, ptr_ret);
443
443
 
444
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
444
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))) {
445
445
  MPFI *ptr_other;
446
446
  r_mpfi_get_struct(ptr_other, other);
447
447
  mpfi_mul(ptr_ret, ptr_self, ptr_other);
448
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
448
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))) {
449
449
  MPFR *ptr_other;
450
450
  r_mpfr_get_struct(ptr_other, other);
451
451
  mpfi_mul_fr(ptr_ret, ptr_self, ptr_other);
452
- }else if(TYPE(other) == T_FIXNUM){
452
+ } else if (TYPE(other) == T_FIXNUM) {
453
453
  mpfi_mul_si(ptr_ret, ptr_self, FIX2LONG(other));
454
- }else if(TYPE(other) == T_FLOAT){
454
+ } else if (TYPE(other) == T_FLOAT) {
455
455
  mpfi_mul_d(ptr_ret, ptr_self, NUM2DBL(other));
456
- }else{
456
+ } else {
457
457
  MPFI *ptr_other;
458
458
  volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
459
459
  r_mpfi_get_struct(ptr_other, tmp_other);
@@ -470,19 +470,19 @@ static VALUE r_mpfi_div (VALUE self, VALUE other)
470
470
  r_mpfi_get_struct(ptr_self, self);
471
471
  r_mpfi_make_struct_init(val_ret, ptr_ret);
472
472
 
473
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
473
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))) {
474
474
  MPFI *ptr_other;
475
475
  r_mpfi_get_struct(ptr_other, other);
476
476
  mpfi_div(ptr_ret, ptr_self, ptr_other);
477
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
477
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))) {
478
478
  MPFR *ptr_other;
479
479
  r_mpfr_get_struct(ptr_other, other);
480
480
  mpfi_div_fr(ptr_ret, ptr_self, ptr_other);
481
- }else if(TYPE(other) == T_FIXNUM){
481
+ } else if (TYPE(other) == T_FIXNUM) {
482
482
  mpfi_div_si(ptr_ret, ptr_self, FIX2LONG(other));
483
- }else if(TYPE(other) == T_FLOAT){
483
+ } else if (TYPE(other) == T_FLOAT) {
484
484
  mpfi_div_d(ptr_ret, ptr_self, NUM2DBL(other));
485
- }else{
485
+ } else {
486
486
  MPFI *ptr_other;
487
487
  volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
488
488
  r_mpfi_get_struct(ptr_other, tmp_other);
@@ -514,7 +514,7 @@ static VALUE r_mpfi_div_2si (int argc, VALUE *argv, VALUE self)
514
514
  }
515
515
 
516
516
  /* mpfi_neg(ret, self) */
517
- static VALUE r_mpfi_neg(int argc, VALUE *argv, VALUE self)
517
+ static VALUE r_mpfi_neg (int argc, VALUE *argv, VALUE self)
518
518
  {
519
519
  MPFI *ptr_self, *ptr_ret;
520
520
  VALUE val_ret;
@@ -525,7 +525,7 @@ static VALUE r_mpfi_neg(int argc, VALUE *argv, VALUE self)
525
525
  }
526
526
 
527
527
  /* mpfi_inv(ret, self) */
528
- static VALUE r_mpfi_inv(int argc, VALUE *argv, VALUE self)
528
+ static VALUE r_mpfi_inv (int argc, VALUE *argv, VALUE self)
529
529
  {
530
530
  MPFI *ptr_self, *ptr_ret;
531
531
  VALUE val_ret;
@@ -536,7 +536,7 @@ static VALUE r_mpfi_inv(int argc, VALUE *argv, VALUE self)
536
536
  }
537
537
 
538
538
  /* mpfi_abs(ret, self) */
539
- static VALUE r_mpfi_abs(int argc, VALUE *argv, VALUE self)
539
+ static VALUE r_mpfi_abs (int argc, VALUE *argv, VALUE self)
540
540
  {
541
541
  MPFI *ptr_self, *ptr_ret;
542
542
  VALUE val_ret;
@@ -557,19 +557,19 @@ static VALUE r_mpfi_cmp (VALUE self, VALUE other)
557
557
  int ret;
558
558
  r_mpfi_get_struct(ptr_self, self);
559
559
 
560
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
560
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))) {
561
561
  MPFI *ptr_other;
562
562
  r_mpfi_get_struct(ptr_other, other);
563
563
  ret = mpfi_cmp(ptr_self, ptr_other);
564
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
564
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))) {
565
565
  MPFR *ptr_other;
566
566
  r_mpfr_get_struct(ptr_other, other);
567
567
  ret = mpfi_cmp_fr(ptr_self, ptr_other);
568
- }else if(TYPE(other) == T_FIXNUM){
568
+ } else if (TYPE(other) == T_FIXNUM) {
569
569
  ret = mpfi_cmp_si(ptr_self, FIX2LONG(other));
570
- }else if(TYPE(other) == T_FLOAT){
570
+ } else if (TYPE(other) == T_FLOAT) {
571
571
  ret = mpfi_cmp_d(ptr_self, NUM2DBL(other));
572
- }else{
572
+ } else {
573
573
  MPFI *ptr_other;
574
574
  volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
575
575
  r_mpfi_get_struct(ptr_other, tmp_other);
@@ -585,7 +585,7 @@ static VALUE r_mpfi_is_pos (VALUE self)
585
585
  r_mpfi_get_struct(ptr_self, self);
586
586
  if (mpfi_is_pos(ptr_self) > 0) {
587
587
  return Qtrue;
588
- }else{
588
+ } else {
589
589
  return Qnil;
590
590
  }
591
591
  }
@@ -597,7 +597,7 @@ static VALUE r_mpfi_is_strictly_pos (VALUE self)
597
597
  r_mpfi_get_struct(ptr_self, self);
598
598
  if (mpfi_is_strictly_pos(ptr_self) > 0) {
599
599
  return Qtrue;
600
- }else{
600
+ } else {
601
601
  return Qnil;
602
602
  }
603
603
  }
@@ -609,7 +609,7 @@ static VALUE r_mpfi_is_nonneg (VALUE self)
609
609
  r_mpfi_get_struct(ptr_self, self);
610
610
  if (mpfi_is_nonneg(ptr_self) > 0) {
611
611
  return Qtrue;
612
- }else{
612
+ } else {
613
613
  return Qnil;
614
614
  }
615
615
  }
@@ -621,7 +621,7 @@ static VALUE r_mpfi_is_neg (VALUE self)
621
621
  r_mpfi_get_struct(ptr_self, self);
622
622
  if (mpfi_is_neg(ptr_self) > 0) {
623
623
  return Qtrue;
624
- }else{
624
+ } else {
625
625
  return Qnil;
626
626
  }
627
627
  }
@@ -633,7 +633,7 @@ static VALUE r_mpfi_is_strictly_neg (VALUE self)
633
633
  r_mpfi_get_struct(ptr_self, self);
634
634
  if (mpfi_is_strictly_neg(ptr_self) > 0) {
635
635
  return Qtrue;
636
- }else{
636
+ } else {
637
637
  return Qnil;
638
638
  }
639
639
  }
@@ -645,7 +645,7 @@ static VALUE r_mpfi_is_nonpos (VALUE self)
645
645
  r_mpfi_get_struct(ptr_self, self);
646
646
  if (mpfi_is_nonpos(ptr_self) > 0) {
647
647
  return Qtrue;
648
- }else{
648
+ } else {
649
649
  return Qnil;
650
650
  }
651
651
  }
@@ -657,7 +657,7 @@ static VALUE r_mpfi_is_zero (VALUE self)
657
657
  r_mpfi_get_struct(ptr_self, self);
658
658
  if (mpfi_is_zero(ptr_self) > 0) {
659
659
  return Qtrue;
660
- }else{
660
+ } else {
661
661
  return Qnil;
662
662
  }
663
663
  }
@@ -669,7 +669,7 @@ static VALUE r_mpfi_has_zero (VALUE self)
669
669
  r_mpfi_get_struct(ptr_self, self);
670
670
  if (mpfi_has_zero(ptr_self) > 0) {
671
671
  return Qtrue;
672
- }else{
672
+ } else {
673
673
  return Qnil;
674
674
  }
675
675
  }
@@ -681,7 +681,7 @@ static VALUE r_mpfi_nan_p (VALUE self)
681
681
  r_mpfi_get_struct(ptr_self, self);
682
682
  if (mpfi_nan_p(ptr_self) != 0) {
683
683
  return Qtrue;
684
- }else{
684
+ } else {
685
685
  return Qnil;
686
686
  }
687
687
  }
@@ -693,7 +693,7 @@ static VALUE r_mpfi_inf_p (VALUE self)
693
693
  r_mpfi_get_struct(ptr_self, self);
694
694
  if (mpfi_inf_p(ptr_self) != 0) {
695
695
  return Qtrue;
696
- }else{
696
+ } else {
697
697
  return Qnil;
698
698
  }
699
699
  }
@@ -705,7 +705,7 @@ static VALUE r_mpfi_bounded_p (VALUE self)
705
705
  r_mpfi_get_struct(ptr_self, self);
706
706
  if (mpfi_bounded_p(ptr_self) != 0) {
707
707
  return Qtrue;
708
- }else{
708
+ } else {
709
709
  return Qnil;
710
710
  }
711
711
  }
@@ -722,7 +722,7 @@ static VALUE r_mpfi_equal_p (VALUE self, VALUE other)
722
722
  if (mpfr_equal_p(r_mpfi_left_ptr(ptr_self), r_mpfi_left_ptr(ptr_other)) != 0 &&
723
723
  mpfr_equal_p(r_mpfi_right_ptr(ptr_self), r_mpfi_right_ptr(ptr_other)) != 0) {
724
724
  return Qtrue;
725
- }else{
725
+ } else {
726
726
  return Qnil;
727
727
  }
728
728
  }
@@ -831,7 +831,7 @@ static VALUE r_mpfi_alea (int argc, VALUE *argv, VALUE self)
831
831
  /* ------------------------------ Conversion Functions start ------------------------------ */
832
832
 
833
833
  /* Return float by mpfi_get_d(self). */
834
- static VALUE r_mpfi_get_d(VALUE self)
834
+ static VALUE r_mpfi_get_d (VALUE self)
835
835
  {
836
836
  MPFI *ptr_self;
837
837
  r_mpfi_get_struct(ptr_self, self);
@@ -839,7 +839,7 @@ static VALUE r_mpfi_get_d(VALUE self)
839
839
  }
840
840
 
841
841
  /* Return MPFR by mpfi_get_fr(ret, self). */
842
- static VALUE r_mpfi_get_fr(VALUE self)
842
+ static VALUE r_mpfi_get_fr (VALUE self)
843
843
  {
844
844
  MPFI *ptr_self;
845
845
  VALUE val_ret;
@@ -882,9 +882,9 @@ static VALUE r_mpfi_revert_if_needed (VALUE self)
882
882
  {
883
883
  MPFI *ptr_self;
884
884
  r_mpfi_get_struct(ptr_self, self);
885
- if(mpfi_revert_if_needed(ptr_self) != 0){
885
+ if (mpfi_revert_if_needed(ptr_self) != 0) {
886
886
  return Qtrue;
887
- }else{
887
+ } else {
888
888
  return Qnil;
889
889
  };
890
890
  }
@@ -895,19 +895,19 @@ static VALUE r_mpfi_put (VALUE self, VALUE other)
895
895
  MPFI *ptr_self;
896
896
  r_mpfi_get_struct(ptr_self, self);
897
897
 
898
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
898
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))) {
899
899
  MPFI *ptr_other;
900
900
  r_mpfi_get_struct(ptr_other, other);
901
901
  r_mpfi_set_function_state(mpfi_put(ptr_self, ptr_other));
902
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
902
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))) {
903
903
  MPFR *ptr_other;
904
904
  r_mpfr_get_struct(ptr_other, other);
905
905
  r_mpfi_set_function_state(mpfi_put_fr(ptr_self, ptr_other));
906
- }else if(TYPE(other) == T_FIXNUM){
906
+ } else if (TYPE(other) == T_FIXNUM) {
907
907
  r_mpfi_set_function_state(mpfi_put_si(ptr_self, FIX2LONG(other)));
908
- }else if(TYPE(other) == T_FLOAT){
908
+ } else if (TYPE(other) == T_FLOAT) {
909
909
  r_mpfi_set_function_state(mpfi_put_d(ptr_self, NUM2DBL(other)));
910
- }else{
910
+ } else {
911
911
  MPFI *ptr_other;
912
912
  volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
913
913
  r_mpfi_get_struct(ptr_other, tmp_other);
@@ -959,9 +959,9 @@ static VALUE r_mpfi_strictly_include (VALUE self, VALUE other)
959
959
  MPFI *ptr_self, *ptr_other;
960
960
  r_mpfi_get_struct(ptr_self, self);
961
961
  r_mpfi_get_struct(ptr_other, other);
962
- if(mpfi_is_strictly_inside(ptr_other, ptr_self) > 0){
962
+ if (mpfi_is_strictly_inside(ptr_other, ptr_self) > 0) {
963
963
  return Qtrue;
964
- }else{
964
+ } else {
965
965
  return Qnil;
966
966
  }
967
967
  }
@@ -972,27 +972,27 @@ static VALUE r_mpfi_include (VALUE self, VALUE other)
972
972
  MPFI *ptr_self;
973
973
  int result;
974
974
  r_mpfi_get_struct(ptr_self, self);
975
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))){
975
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, other))) {
976
976
  MPFI *ptr_other;
977
977
  r_mpfi_get_struct(ptr_other, other);
978
978
  result = mpfi_is_inside(ptr_other, ptr_self);
979
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))){
979
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, other))) {
980
980
  MPFR *ptr_other;
981
981
  r_mpfr_get_struct(ptr_other, other);
982
982
  result = mpfi_is_inside_fr(ptr_other, ptr_self);
983
- }else if(TYPE(other) == T_FIXNUM){
983
+ } else if (TYPE(other) == T_FIXNUM) {
984
984
  result = mpfi_is_inside_si(FIX2LONG(other), ptr_self);
985
- }else if(TYPE(other) == T_FLOAT){
985
+ } else if (TYPE(other) == T_FLOAT) {
986
986
  result = mpfi_is_inside_d(NUM2DBL(other), ptr_self);
987
- }else{
987
+ } else {
988
988
  MPFI *ptr_other;
989
989
  volatile VALUE tmp_other = r_mpfi_new_fi_obj(other);
990
990
  r_mpfi_get_struct(ptr_other, tmp_other);
991
991
  result = mpfi_is_inside(ptr_other, ptr_self);
992
992
  }
993
- if(result > 0){
993
+ if (result > 0) {
994
994
  return Qtrue;
995
- }else{
995
+ } else {
996
996
  return Qnil;
997
997
  }
998
998
  }
@@ -1002,9 +1002,9 @@ static VALUE r_mpfi_is_empty (VALUE self)
1002
1002
  {
1003
1003
  MPFI *ptr_self;
1004
1004
  r_mpfi_get_struct(ptr_self, self);
1005
- if(mpfi_is_empty(ptr_self) > 0){
1005
+ if (mpfi_is_empty(ptr_self) > 0) {
1006
1006
  return Qtrue;
1007
- }else{
1007
+ } else {
1008
1008
  return Qnil;
1009
1009
  }
1010
1010
  }
@@ -1021,9 +1021,9 @@ static VALUE r_mpfi_intersect (int argc, VALUE *argv, VALUE self)
1021
1021
  r_mpfi_get_struct(ptr_a0, argv[0]);
1022
1022
  r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
1023
1023
  r_mpfi_set_function_state(mpfi_intersect(ptr_ret, ptr_self, ptr_a0));
1024
- if(mpfi_is_empty(ptr_ret) > 0){
1024
+ if (mpfi_is_empty(ptr_ret) > 0) {
1025
1025
  return Qnil;
1026
- }else{
1026
+ } else {
1027
1027
  return val_ret;
1028
1028
  }
1029
1029
  }
@@ -1097,55 +1097,72 @@ static VALUE r_mpfi_bisect (int argc, VALUE *argv, VALUE self)
1097
1097
  return rb_ary_new3(2, val_ret1, val_ret2);
1098
1098
  }
1099
1099
 
1100
- /* Retrun 0 if this function puts subdivision to *ret. */
1101
- /* Otherwise, return -1. */
1102
- void r_mpfi_subdivision_func(int num, MPFI *ret[], mpfi_t x)
1103
- {
1104
- int i;
1105
- mpfr_t l;
1106
- mpfr_t x_diam;
1107
- mpfr_init(l);
1108
- mpfr_sub(l, r_mpfi_right_ptr(x), r_mpfi_left_ptr(x), GMP_RNDD);
1109
- mpfr_div_si(l, l, num, GMP_RNDD);
1110
- mpfr_init(x_diam);
1111
- mpfi_diam_abs(x_diam, x);
1112
- if(mpfr_cmp(x_diam, l) > 0 && num > 1){
1113
- mpfr_set(r_mpfi_left_ptr(ret[0]), r_mpfi_left_ptr(x), GMP_RNDN);
1114
- mpfr_add(r_mpfi_right_ptr(ret[0]), r_mpfi_left_ptr(ret[0]), l, GMP_RNDU);
1115
-
1116
- for(i = 1; i < num - 1; i ++){
1117
- mpfr_set(r_mpfi_left_ptr(ret[i]), r_mpfi_right_ptr(ret[i - 1]), GMP_RNDN);
1118
- mpfr_add(r_mpfi_right_ptr(ret[i]), r_mpfi_left_ptr(ret[i]), l, GMP_RNDU);
1119
- }
1120
-
1121
- mpfr_set(r_mpfi_left_ptr(ret[i]), r_mpfi_right_ptr(ret[i - 1]), GMP_RNDN);
1122
- mpfr_set(r_mpfi_right_ptr(ret[i]), r_mpfi_right_ptr(x), GMP_RNDN);
1123
- }else{
1124
- mpfr_set(r_mpfi_left_ptr(ret[0]), r_mpfi_left_ptr(x), GMP_RNDN);
1125
- mpfr_set(r_mpfi_right_ptr(ret[0]), r_mpfi_right_ptr(x), GMP_RNDN);
1126
- }
1127
- mpfr_clear(x_diam);
1128
- mpfr_clear(l);
1129
- }
1130
-
1131
- /* Return array having MPFI instances by subdividing. */
1132
- static VALUE r_mpfi_subdivision (int argc, VALUE *argv, VALUE self)
1100
+ /* Yield MPFI instances obtained by subdividing. */
1101
+ static VALUE r_mpfi_each_subdivision (int argc, VALUE *argv, VALUE self)
1133
1102
  {
1134
- MPFI *ptr_self, **f;
1135
- int i, num, prec;
1136
- VALUE *vf, ret;
1137
- r_mpfi_get_struct(ptr_self, self);
1103
+ MPFI *ptr_self;
1104
+ int i, num, prec, state = 0;
1105
+ mpfr_t ptr_self_diam, step, endpoint;
1106
+ VALUE ret;
1107
+ RETURN_ENUMERATOR(self, argc, argv);
1138
1108
  num = NUM2INT(argv[0]);
1109
+ if (num <= 0) {
1110
+ rb_raise(rb_eArgError, "Split number must be positive.");
1111
+ }
1139
1112
  prec = r_mpfr_prec_from_optional_argument(1, 2, argc, argv);
1140
- vf = ALLOC_N(VALUE, num);
1141
- f = ALLOC_N(MPFI*, num);
1142
- for(i = 0; i < num; i++){
1143
- r_mpfi_make_struct_init2(vf[i], f[i], prec);
1113
+ r_mpfi_get_struct(ptr_self, self);
1114
+ mpfr_init2(ptr_self_diam, prec);
1115
+ mpfr_init2(step, prec);
1116
+ mpfr_init2(endpoint, prec);
1117
+ mpfr_sub(step, r_mpfi_right_ptr(ptr_self), r_mpfi_left_ptr(ptr_self), GMP_RNDD);
1118
+ mpfr_div_si(step, step, num, GMP_RNDD);
1119
+ mpfi_diam_abs(ptr_self_diam, ptr_self);
1120
+ if (mpfr_cmp(ptr_self_diam, step) > 0 && num > 1) {
1121
+ {
1122
+ volatile VALUE obj;
1123
+ MPFI *ptr_obj;
1124
+ r_mpfi_make_struct_init2(obj, ptr_obj, prec);
1125
+ mpfr_set(r_mpfi_left_ptr(ptr_obj), r_mpfi_left_ptr(ptr_self), GMP_RNDD);
1126
+ mpfr_add(endpoint, r_mpfi_left_ptr(ptr_self), step, GMP_RNDU);
1127
+ mpfr_set(r_mpfi_right_ptr(ptr_obj), endpoint, GMP_RNDU);
1128
+ ret = rb_protect(rb_yield, obj, &state);
1129
+ }
1130
+ if (state == 0) {
1131
+ for (i = 1; i < num - 1; i++) {
1132
+ volatile VALUE obj;
1133
+ MPFI *ptr_obj;
1134
+ r_mpfi_make_struct_init2(obj, ptr_obj, prec);
1135
+ mpfr_set(r_mpfi_left_ptr(ptr_obj), endpoint, GMP_RNDD);
1136
+ mpfr_add(endpoint, endpoint, step, GMP_RNDU);
1137
+ mpfr_set(r_mpfi_right_ptr(ptr_obj), endpoint, GMP_RNDU);
1138
+ ret = rb_protect(rb_yield, obj, &state);
1139
+ if (state != 0) {
1140
+ break;
1141
+ }
1142
+ }
1143
+ if (state == 0) {
1144
+ volatile VALUE obj;
1145
+ MPFI *ptr_obj;
1146
+ r_mpfi_make_struct_init2(obj, ptr_obj, prec);
1147
+ mpfr_set(r_mpfi_left_ptr(ptr_obj), endpoint, GMP_RNDD);
1148
+ mpfr_set(r_mpfi_right_ptr(ptr_obj), r_mpfi_right_ptr(ptr_self), GMP_RNDU);
1149
+ ret = rb_protect(rb_yield, obj, &state);
1150
+ }
1151
+ }
1152
+ } else {
1153
+ volatile VALUE obj;
1154
+ MPFI *ptr_obj;
1155
+ r_mpfi_make_struct_init2(obj, ptr_obj, prec);
1156
+ mpfr_set(r_mpfi_left_ptr(ptr_obj), r_mpfi_left_ptr(ptr_self), GMP_RNDD);
1157
+ mpfr_set(r_mpfi_right_ptr(ptr_obj), r_mpfi_right_ptr(ptr_self), GMP_RNDU);
1158
+ ret = rb_protect(rb_yield, obj, &state);
1159
+ }
1160
+ mpfr_clear(ptr_self_diam);
1161
+ mpfr_clear(endpoint);
1162
+ mpfr_clear(step);
1163
+ if (state != 0) {
1164
+ rb_jump_tag(state);
1144
1165
  }
1145
- r_mpfi_subdivision_func(num, f, ptr_self);
1146
- ret = rb_ary_new4(num, vf);
1147
- free(vf);
1148
- free(f);
1149
1166
  return ret;
1150
1167
  }
1151
1168
  /* ------------------------------ Miscellaneous Interval Functions end ------------------------------ */
@@ -1161,19 +1178,19 @@ static VALUE r_mpfi_math_add (int argc, VALUE *argv, VALUE self)
1161
1178
  r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
1162
1179
  tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
1163
1180
  r_mpfi_get_struct(ptr_a0, tmp_argv0);
1164
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
1181
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))) {
1165
1182
  MPFI *ptr_other;
1166
1183
  r_mpfi_get_struct(ptr_other, argv[1]);
1167
1184
  r_mpfi_set_function_state(mpfi_add(ptr_ret, ptr_a0, ptr_other));
1168
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
1185
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))) {
1169
1186
  MPFR *ptr_other;
1170
1187
  r_mpfr_get_struct(ptr_other, argv[1]);
1171
1188
  r_mpfi_set_function_state(mpfi_add_fr(ptr_ret, ptr_a0, ptr_other));
1172
- }else if(TYPE(argv[1]) == T_FIXNUM){
1189
+ } else if (TYPE(argv[1]) == T_FIXNUM) {
1173
1190
  r_mpfi_set_function_state(mpfi_add_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
1174
- }else if(TYPE(argv[1]) == T_FLOAT){
1191
+ } else if (TYPE(argv[1]) == T_FLOAT) {
1175
1192
  r_mpfi_set_function_state(mpfi_add_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
1176
- }else{
1193
+ } else {
1177
1194
  MPFI *ptr_a2;
1178
1195
  volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
1179
1196
  r_mpfi_get_struct(ptr_a2, tmp_argv1);
@@ -1191,19 +1208,19 @@ static VALUE r_mpfi_math_sub (int argc, VALUE *argv, VALUE self)
1191
1208
  r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
1192
1209
  tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
1193
1210
  r_mpfi_get_struct(ptr_a0, tmp_argv0);
1194
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
1211
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))) {
1195
1212
  MPFI *ptr_other;
1196
1213
  r_mpfi_get_struct(ptr_other, argv[1]);
1197
1214
  r_mpfi_set_function_state(mpfi_sub(ptr_ret, ptr_a0, ptr_other));
1198
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
1215
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))) {
1199
1216
  MPFR *ptr_other;
1200
1217
  r_mpfr_get_struct(ptr_other, argv[1]);
1201
1218
  r_mpfi_set_function_state(mpfi_sub_fr(ptr_ret, ptr_a0, ptr_other));
1202
- }else if(TYPE(argv[1]) == T_FIXNUM){
1219
+ } else if (TYPE(argv[1]) == T_FIXNUM) {
1203
1220
  r_mpfi_set_function_state(mpfi_sub_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
1204
- }else if(TYPE(argv[1]) == T_FLOAT){
1221
+ } else if (TYPE(argv[1]) == T_FLOAT) {
1205
1222
  r_mpfi_set_function_state(mpfi_sub_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
1206
- }else{
1223
+ } else {
1207
1224
  MPFI *ptr_a2;
1208
1225
  volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
1209
1226
  r_mpfi_get_struct(ptr_a2, tmp_argv1);
@@ -1221,19 +1238,19 @@ static VALUE r_mpfi_math_mul (int argc, VALUE *argv, VALUE self)
1221
1238
  r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
1222
1239
  tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
1223
1240
  r_mpfi_get_struct(ptr_a0, tmp_argv0);
1224
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
1241
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))) {
1225
1242
  MPFI *ptr_other;
1226
1243
  r_mpfi_get_struct(ptr_other, argv[1]);
1227
1244
  r_mpfi_set_function_state(mpfi_mul(ptr_ret, ptr_a0, ptr_other));
1228
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
1245
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))) {
1229
1246
  MPFR *ptr_other;
1230
1247
  r_mpfr_get_struct(ptr_other, argv[1]);
1231
1248
  r_mpfi_set_function_state(mpfi_mul_fr(ptr_ret, ptr_a0, ptr_other));
1232
- }else if(TYPE(argv[1]) == T_FIXNUM){
1249
+ } else if (TYPE(argv[1]) == T_FIXNUM) {
1233
1250
  r_mpfi_set_function_state(mpfi_mul_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
1234
- }else if(TYPE(argv[1]) == T_FLOAT){
1251
+ } else if (TYPE(argv[1]) == T_FLOAT) {
1235
1252
  r_mpfi_set_function_state(mpfi_mul_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
1236
- }else{
1253
+ } else {
1237
1254
  MPFI *ptr_a2;
1238
1255
  volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
1239
1256
  r_mpfi_get_struct(ptr_a2, tmp_argv1);
@@ -1251,19 +1268,19 @@ static VALUE r_mpfi_math_div (int argc, VALUE *argv, VALUE self)
1251
1268
  r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(2, 3, argc, argv));
1252
1269
  tmp_argv0 = r_mpfi_new_fi_obj(argv[0]);
1253
1270
  r_mpfi_get_struct(ptr_a0, tmp_argv0);
1254
- if(RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))){
1271
+ if (RTEST(rb_funcall(__mpfi_class__, eqq, 1, argv[1]))) {
1255
1272
  MPFI *ptr_other;
1256
1273
  r_mpfi_get_struct(ptr_other, argv[1]);
1257
1274
  r_mpfi_set_function_state(mpfi_div(ptr_ret, ptr_a0, ptr_other));
1258
- }else if(RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))){
1275
+ } else if (RTEST(rb_funcall(__mpfr_class__, eqq, 1, argv[1]))) {
1259
1276
  MPFR *ptr_other;
1260
1277
  r_mpfr_get_struct(ptr_other, argv[1]);
1261
1278
  r_mpfi_set_function_state(mpfi_div_fr(ptr_ret, ptr_a0, ptr_other));
1262
- }else if(TYPE(argv[1]) == T_FIXNUM){
1279
+ } else if (TYPE(argv[1]) == T_FIXNUM) {
1263
1280
  r_mpfi_set_function_state(mpfi_div_si(ptr_ret, ptr_a0, FIX2LONG(argv[1])));
1264
- }else if(TYPE(argv[1]) == T_FLOAT){
1281
+ } else if (TYPE(argv[1]) == T_FLOAT) {
1265
1282
  r_mpfi_set_function_state(mpfi_div_d(ptr_ret, ptr_a0, NUM2DBL(argv[1])));
1266
- }else{
1283
+ } else {
1267
1284
  MPFI *ptr_a2;
1268
1285
  volatile VALUE tmp_argv1 = r_mpfi_new_fi_obj(argv[1]);
1269
1286
  r_mpfi_get_struct(ptr_a2, tmp_argv1);
@@ -1688,7 +1705,7 @@ void Init_mpfi()
1688
1705
  rb_define_method(r_mpfi_class, "increase", r_mpfi_increase, 1);
1689
1706
  rb_define_method(r_mpfi_class, "blow", r_mpfi_blow, -1);
1690
1707
  rb_define_method(r_mpfi_class, "bisect", r_mpfi_bisect, -1);
1691
- rb_define_method(r_mpfi_class, "subdivision", r_mpfi_subdivision, -1);
1708
+ rb_define_method(r_mpfi_class, "each_subdivision", r_mpfi_each_subdivision, -1);
1692
1709
  /* ------------------------------ Miscellaneous Interval Functions end ------------------------------ */
1693
1710
 
1694
1711
  r_mpfi_math = rb_define_module_under(r_mpfi_class, "Math");
@@ -1740,4 +1757,3 @@ void Init_mpfi()
1740
1757
  __sym_to_str__ = rb_eval_string(":to_str");
1741
1758
 
1742
1759
  }
1743
-