number 0.9.7 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,6 +40,14 @@
40
40
 
41
41
  #define REAL_CHECK(real) if (!REAL(real)) { return real_dup(real); }
42
42
 
43
+ #ifndef INFINITY
44
+ #define INFINITY (double)(1.0/0.0)
45
+ #endif
46
+
47
+ #ifndef NAN
48
+ #define NAN (double)(0.0/0.0)
49
+ #endif
50
+
43
51
  typedef struct
44
52
  {
45
53
  int flag;
@@ -91,4 +99,298 @@ extern VALUE rb_cReal;
91
99
  extern VALUE rb_cInterval;
92
100
  extern VALUE rb_cNumber;
93
101
 
102
+ VALUE rb_enc_str_new (const char*, long, void*);
103
+ void* rb_utf8_encoding (void);
104
+ void rb_remove_method_id (VALUE, ID);
105
+
106
+ void bounds_free (Bounds*);
107
+ void bounds_update_re (Bounds*, mpfr_t, int, int);
108
+ void bounds_update_im (Bounds*, mpfr_t, int, int);
109
+ void bounds_update (Bounds*, mpc_t, int, int, int);
110
+ Bounds* bounds_new ();
111
+
112
+ void init_complex_tmp_nums ();
113
+ void mpc_set_r_r (mpc_t, Real*, Real*);
114
+ void mpfr_set_r (mpfr_t, Real*);
115
+ void complex_free (Complex*);
116
+ long complex_strlen (Complex*);
117
+ void complex_print (char*, Complex*);
118
+ void complex_print_int (char*, Complex*);
119
+ void complex_print_decimal (char*, Complex*);
120
+ Complex* complex_new (Interval*, Interval*);
121
+ Complex* complex_from_real (Real*);
122
+ Complex* complex_from_int_str (char*);
123
+ Complex* complex_from_float_str (char*);
124
+ Complex* complex_nan ();
125
+ Complex* complex_pos_inf ();
126
+ Complex* complex_neg_inf ();
127
+ Complex* complex_zero ();
128
+ Complex* complex_one ();
129
+ Complex* complex_pi ();
130
+ Complex* complex_e ();
131
+ Complex* complex_i ();
132
+ Complex* complex_dup (Complex*);
133
+ Complex* complex_add (Complex*, Complex*);
134
+ Complex* complex_subtract (Complex*, Complex*);
135
+ Complex* complex_multiply (Complex*, Complex*);
136
+ Complex* complex_divide (Complex*, Complex*);
137
+ Complex* complex_modulo (Complex*, Complex*);
138
+ Complex* complex_abs (Complex*);
139
+ Complex* complex_area (Complex*);
140
+ Complex* complex_diagonal (Complex*);
141
+ Complex* complex_conjugate (Complex*);
142
+ Complex* complex_negate (Complex*);
143
+ Complex* complex_reflect (Complex*);
144
+ Complex* complex_sqrt (Complex*);
145
+
146
+ Complex* complex_im (Complex*);
147
+ Complex* complex_im_l (Complex*);
148
+ Complex* complex_im_n (Complex*);
149
+ Complex* complex_im_u (Complex*);
150
+ Complex* complex_im_magnitude (Complex*);
151
+ Complex* complex_im_mignitude (Complex*);
152
+ Complex* complex_im_width (Complex*);
153
+ Complex* complex_re (Complex*);
154
+ Complex* complex_re_l (Complex*);
155
+ Complex* complex_re_n (Complex*);
156
+ Complex* complex_re_u (Complex*);
157
+ Complex* complex_re_magnitude (Complex*);
158
+ Complex* complex_re_mignitude (Complex*);
159
+ Complex* complex_re_width (Complex*);
160
+ Complex* complex_ll (Complex*);
161
+ Complex* complex_lu (Complex*);
162
+ Complex* complex_n (Complex*);
163
+ Complex* complex_ul (Complex*);
164
+ Complex* complex_uu (Complex*);
165
+ Complex* complex_magnitude (Complex*);
166
+ Complex* complex_mignitude (Complex*);
167
+ Complex* complex_width (Complex*);
168
+
169
+ int complex_re_enclose_p (Complex*, Complex*);
170
+ int complex_re_contain_l_p (Complex*, Complex*);
171
+ int complex_re_contain_n_p (Complex*, Complex*);
172
+ int complex_re_contain_u_p (Complex*, Complex*);
173
+ int complex_re_contain_zero_p (Complex*);
174
+ int complex_re_intersect_p (Complex*, Complex*);
175
+ int complex_re_disjoint_p (Complex*, Complex*);
176
+ int complex_re_unbounded_p (Complex*);
177
+ int complex_re_left_unbounded_p (Complex*);
178
+ int complex_re_right_unbounded_p (Complex*);
179
+ int complex_re_nan_p (Complex*);
180
+ int complex_re_pos_inf_p (Complex*);
181
+ int complex_re_neg_inf_p (Complex*);
182
+ int complex_re_normal_p (Complex*);
183
+ int complex_re_zero_p (Complex*);
184
+ int complex_re_eq_p (Complex*, Complex*);
185
+ int complex_re_bounds_eq_p (Complex*, Complex*);
186
+ int complex_re_l_eq_l_p (Complex*, Complex*);
187
+ int complex_re_l_eq_n_p (Complex*, Complex*);
188
+ int complex_re_l_eq_u_p (Complex*, Complex*);
189
+ int complex_re_n_eq_l_p (Complex*, Complex*);
190
+ int complex_re_n_eq_n_p (Complex*, Complex*);
191
+ int complex_re_n_eq_u_p (Complex*, Complex*);
192
+ int complex_re_u_eq_l_p (Complex*, Complex*);
193
+ int complex_re_u_eq_n_p (Complex*, Complex*);
194
+ int complex_re_u_eq_u_p (Complex*, Complex*);
195
+ int complex_re_l_gt_l_p (Complex*, Complex*);
196
+ int complex_re_l_gt_n_p (Complex*, Complex*);
197
+ int complex_re_l_gt_u_p (Complex*, Complex*);
198
+ int complex_re_n_gt_l_p (Complex*, Complex*);
199
+ int complex_re_n_gt_n_p (Complex*, Complex*);
200
+ int complex_re_n_gt_u_p (Complex*, Complex*);
201
+ int complex_re_u_gt_l_p (Complex*, Complex*);
202
+ int complex_re_u_gt_n_p (Complex*, Complex*);
203
+ int complex_re_u_gt_u_p (Complex*, Complex*);
204
+ int complex_re_l_ge_l_p (Complex*, Complex*);
205
+ int complex_re_l_ge_n_p (Complex*, Complex*);
206
+ int complex_re_l_ge_u_p (Complex*, Complex*);
207
+ int complex_re_n_ge_l_p (Complex*, Complex*);
208
+ int complex_re_n_ge_n_p (Complex*, Complex*);
209
+ int complex_re_n_ge_u_p (Complex*, Complex*);
210
+ int complex_re_u_ge_l_p (Complex*, Complex*);
211
+ int complex_re_u_ge_n_p (Complex*, Complex*);
212
+ int complex_re_u_ge_u_p (Complex*, Complex*);
213
+ int complex_re_l_lt_l_p (Complex*, Complex*);
214
+ int complex_re_l_lt_n_p (Complex*, Complex*);
215
+ int complex_re_l_lt_u_p (Complex*, Complex*);
216
+ int complex_re_n_lt_l_p (Complex*, Complex*);
217
+ int complex_re_n_lt_n_p (Complex*, Complex*);
218
+ int complex_re_n_lt_u_p (Complex*, Complex*);
219
+ int complex_re_u_lt_l_p (Complex*, Complex*);
220
+ int complex_re_u_lt_n_p (Complex*, Complex*);
221
+ int complex_re_u_lt_u_p (Complex*, Complex*);
222
+ int complex_re_l_le_l_p (Complex*, Complex*);
223
+ int complex_re_l_le_n_p (Complex*, Complex*);
224
+ int complex_re_l_le_u_p (Complex*, Complex*);
225
+ int complex_re_n_le_l_p (Complex*, Complex*);
226
+ int complex_re_n_le_n_p (Complex*, Complex*);
227
+ int complex_re_n_le_u_p (Complex*, Complex*);
228
+ int complex_re_u_le_l_p (Complex*, Complex*);
229
+ int complex_re_u_le_n_p (Complex*, Complex*);
230
+ int complex_re_u_le_u_p (Complex*, Complex*);
231
+ int complex_im_unbounded_p (Complex*);
232
+ int complex_im_left_unbounded_p (Complex*);
233
+ int complex_im_right_unbounded_p (Complex*);
234
+ int complex_im_nan_p (Complex*);
235
+ int complex_im_pos_inf_p (Complex*);
236
+ int complex_im_neg_inf_p (Complex*);
237
+ int complex_im_normal_p (Complex*);
238
+ int complex_im_zero_p (Complex*);
239
+ int complex_im_contain_zero_p (Complex*);
240
+ int complex_im_enclose_p (Complex*, Complex*);
241
+ int complex_im_contain_l_p (Complex*, Complex*);
242
+ int complex_im_contain_n_p (Complex*, Complex*);
243
+ int complex_im_contain_u_p (Complex*, Complex*);
244
+ int complex_im_intersect_p (Complex*, Complex*);
245
+ int complex_im_disjoint_p (Complex*, Complex*);
246
+ int complex_im_eq_p (Complex*, Complex*);
247
+ int complex_im_bounds_eq_p (Complex*, Complex*);
248
+ int complex_im_l_eq_l_p (Complex*, Complex*);
249
+ int complex_im_l_eq_n_p (Complex*, Complex*);
250
+ int complex_im_l_eq_u_p (Complex*, Complex*);
251
+ int complex_im_n_eq_l_p (Complex*, Complex*);
252
+ int complex_im_n_eq_n_p (Complex*, Complex*);
253
+ int complex_im_n_eq_u_p (Complex*, Complex*);
254
+ int complex_im_u_eq_l_p (Complex*, Complex*);
255
+ int complex_im_u_eq_n_p (Complex*, Complex*);
256
+ int complex_im_u_eq_u_p (Complex*, Complex*);
257
+ int complex_im_l_gt_l_p (Complex*, Complex*);
258
+ int complex_im_l_gt_n_p (Complex*, Complex*);
259
+ int complex_im_l_gt_u_p (Complex*, Complex*);
260
+ int complex_im_n_gt_l_p (Complex*, Complex*);
261
+ int complex_im_n_gt_n_p (Complex*, Complex*);
262
+ int complex_im_n_gt_u_p (Complex*, Complex*);
263
+ int complex_im_u_gt_l_p (Complex*, Complex*);
264
+ int complex_im_u_gt_n_p (Complex*, Complex*);
265
+ int complex_im_u_gt_u_p (Complex*, Complex*);
266
+ int complex_im_l_ge_l_p (Complex*, Complex*);
267
+ int complex_im_l_ge_n_p (Complex*, Complex*);
268
+ int complex_im_l_ge_u_p (Complex*, Complex*);
269
+ int complex_im_n_ge_l_p (Complex*, Complex*);
270
+ int complex_im_n_ge_n_p (Complex*, Complex*);
271
+ int complex_im_n_ge_u_p (Complex*, Complex*);
272
+ int complex_im_u_ge_l_p (Complex*, Complex*);
273
+ int complex_im_u_ge_n_p (Complex*, Complex*);
274
+ int complex_im_u_ge_u_p (Complex*, Complex*);
275
+ int complex_im_l_lt_l_p (Complex*, Complex*);
276
+ int complex_im_l_lt_n_p (Complex*, Complex*);
277
+ int complex_im_l_lt_u_p (Complex*, Complex*);
278
+ int complex_im_n_lt_l_p (Complex*, Complex*);
279
+ int complex_im_n_lt_n_p (Complex*, Complex*);
280
+ int complex_im_n_lt_u_p (Complex*, Complex*);
281
+ int complex_im_u_lt_l_p (Complex*, Complex*);
282
+ int complex_im_u_lt_n_p (Complex*, Complex*);
283
+ int complex_im_u_lt_u_p (Complex*, Complex*);
284
+ int complex_im_l_le_l_p (Complex*, Complex*);
285
+ int complex_im_l_le_n_p (Complex*, Complex*);
286
+ int complex_im_l_le_u_p (Complex*, Complex*);
287
+ int complex_im_n_le_l_p (Complex*, Complex*);
288
+ int complex_im_n_le_n_p (Complex*, Complex*);
289
+ int complex_im_n_le_u_p (Complex*, Complex*);
290
+ int complex_im_u_le_l_p (Complex*, Complex*);
291
+ int complex_im_u_le_n_p (Complex*, Complex*);
292
+ int complex_im_u_le_u_p (Complex*, Complex*);
293
+ int complex_enclose_p (Complex*, Complex*);
294
+ int complex_contain_ll_p (Complex*, Complex*);
295
+ int complex_contain_lu_p (Complex*, Complex*);
296
+ int complex_contain_n_p (Complex*, Complex*);
297
+ int complex_contain_ul_p (Complex*, Complex*);
298
+ int complex_contain_uu_p (Complex*, Complex*);
299
+ int complex_contain_zero_p (Complex*);
300
+ int complex_intersect_p (Complex*, Complex*);
301
+ int complex_disjoint_p (Complex*, Complex*);
302
+ int complex_unbounded_p (Complex*);
303
+ int complex_nan_p (Complex*);
304
+ int complex_normal_p (Complex*);
305
+ int complex_zero_p (Complex*);
306
+ int complex_complex_p (Complex*);
307
+ int complex_real_p (Complex*);
308
+ int complex_eq_p (Complex*, Complex*);
309
+ int complex_bounds_eq_p (Complex*, Complex*);
310
+
311
+ Complex* complex_round (Complex*);
312
+ Complex* complex_round_c_c (Complex*);
313
+ Complex* complex_round_c_f (Complex*);
314
+ Complex* complex_round_f_c (Complex*);
315
+ Complex* complex_round_f_f (Complex*);
316
+ Complex* complex_round_i_i (Complex*);
317
+ Complex* complex_round_i_o (Complex*);
318
+ Complex* complex_round_o_i (Complex*);
319
+ Complex* complex_round_o_o (Complex*);
320
+
321
+ void interval_free (Interval*);
322
+ long interval_strlen (Interval*);
323
+ void interval_print(char*, Interval*);
324
+ int interval_span_p (Interval*, Real*);
325
+ int interval_span_zero_p (Interval*);
326
+ int interval_zero_p (Interval*);
327
+ int interval_degenerate_p (Interval*);
328
+ Interval* interval_new (Real*, int, Real*, int, Real*);
329
+ Interval* interval_from_real (Real*);
330
+ Interval* interval_nan ();
331
+ Interval* interval_pos_inf ();
332
+ Interval* interval_neg_inf ();
333
+ Interval* interval_zero ();
334
+ Interval* interval_one ();
335
+ Interval* interval_pi ();
336
+ Interval* interval_e ();
337
+ Interval* interval_dup (Interval*);
338
+ Interval* interval_add (Interval*, Interval*);
339
+ Interval* interval_subtract (Interval*, Interval*);
340
+ Interval* interval_multiply (Interval*, Interval*);
341
+ Interval* interval_divide (Interval*, Interval*);
342
+ Interval* interval_negate (Interval*);
343
+ Interval* interval_round (Interval*);
344
+ Interval* interval_round_ceiling (Interval*);
345
+ Interval* interval_round_floor (Interval*);
346
+ Interval* interval_round_infinity (Interval*);
347
+ Interval* interval_round_origin (Interval*);
348
+
349
+ void init_real_tmp_nums ();
350
+ void num_pad (mpz_t, int);
351
+ void num_round (mpz_t, int, int);
352
+ long num_len (mpz_t);
353
+ void real_free (Real*);
354
+ long real_strlen (Real*);
355
+ void real_print (char*, Real*);
356
+ void real_pad_tmps (Real*, Real*, long*, long*);
357
+ int real_zero_p (Real*);
358
+ int real_negative_p (Real*);
359
+ int real_positive_p (Real*);
360
+ int real_cmp (Real*, Real*);
361
+ int real_eq_p (Real*, Real*);
362
+ int real_gt_p (Real*, Real*);
363
+ int real_ge_p (Real*, Real*);
364
+ int real_lt_p (Real*, Real*);
365
+ int real_le_p (Real*, Real*);
366
+ Real* real_alloc ();
367
+ Real* real_new_flagged (int);
368
+ Real* real_new_exact (mpz_t, long);
369
+ Real* real_new_rounded (mpz_t, long, int);
370
+ Real* real_from_str (char*, long);
371
+ Real* real_from_mpfr (mpfr_t, int);
372
+ Real* real_nan ();
373
+ Real* real_pos_inf ();
374
+ Real* real_neg_inf ();
375
+ Real* real_zero ();
376
+ Real* real_one ();
377
+ Real* real_pi (int);
378
+ Real* real_e (int);
379
+ Real* real_dup (Real*);
380
+ Real* real_abs (Real*);
381
+ Real* real_negate (Real*);
382
+ Real* real_ceil (Real*);
383
+ Real* real_floor (Real*);
384
+ Real* real_round (Real*);
385
+ Real* real_round_infinity (Real*);
386
+ Real* real_round_origin (Real*);
387
+ Real* real_add (Real*, Real*);
388
+ Real* real_subtract (Real*, Real*);
389
+ Real* real_multiply (Real*, Real*);
390
+ Real* real_divide (Real*, Real*, int);
391
+
392
+ void real_bounds_free (RealBounds*);
393
+ void real_bounds_update (RealBounds*, Real*, int);
394
+ RealBounds* real_bounds_new ();
395
+
94
396
  #endif
@@ -301,7 +301,7 @@ int real_le_p (Real* a, Real* b)
301
301
  /*
302
302
  * Returns a pointer to a newly allocated Real.
303
303
  */
304
- static Real* real_alloc ()
304
+ Real* real_alloc ()
305
305
  {
306
306
  Real* real;
307
307
  real = malloc(sizeof(Real));
@@ -326,7 +326,7 @@ static Real* real_alloc ()
326
326
  Real* real_new_flagged (int flag)
327
327
  {
328
328
  Real* real;
329
- real = (Real*)real_alloc();
329
+ real = real_alloc();
330
330
 
331
331
  real->exp = 0;
332
332
  real->flag = flag;
@@ -345,7 +345,7 @@ Real* real_new_flagged (int flag)
345
345
  Real* real_new_exact (mpz_t num, long exp)
346
346
  {
347
347
  Real* real;
348
- real = (Real*)real_alloc();
348
+ real = real_alloc();
349
349
 
350
350
  real->exp = exp;
351
351
  real->flag = 0;
@@ -433,7 +433,7 @@ Real* real_from_mpfr (mpfr_t num, int round_mode)
433
433
 
434
434
  if (!mpfr_number_p(num))
435
435
  {
436
- return (Real*)real_new_flagged(mpfr_nan_p(num) ? NaN_FLAG : (mpfr_sgn(num) == 1) ? POS_INF_FLAG : NEG_INF_FLAG);
436
+ return real_new_flagged(mpfr_nan_p(num) ? NaN_FLAG : (mpfr_sgn(num) == 1) ? POS_INF_FLAG : NEG_INF_FLAG);
437
437
  }
438
438
 
439
439
  mpfr_get_str(buf, &exp, 10, digs + 5, num, MPFR_RNDN);
@@ -447,7 +447,7 @@ Real* real_from_mpfr (mpfr_t num, int round_mode)
447
447
  */
448
448
  Real* real_nan ()
449
449
  {
450
- return (Real*)real_new_flagged(NaN_FLAG);
450
+ return real_new_flagged(NaN_FLAG);
451
451
  }
452
452
 
453
453
  /*
@@ -455,7 +455,7 @@ Real* real_nan ()
455
455
  */
456
456
  Real* real_pos_inf ()
457
457
  {
458
- return (Real*)real_new_flagged(POS_INF_FLAG);
458
+ return real_new_flagged(POS_INF_FLAG);
459
459
  }
460
460
 
461
461
  /*
@@ -463,7 +463,7 @@ Real* real_pos_inf ()
463
463
  */
464
464
  Real* real_neg_inf ()
465
465
  {
466
- return (Real*)real_new_flagged(NEG_INF_FLAG);
466
+ return real_new_flagged(NEG_INF_FLAG);
467
467
  }
468
468
 
469
469
  /*
@@ -530,7 +530,7 @@ Real* real_e (int round_mode)
530
530
  */
531
531
  Real* real_dup (Real* real)
532
532
  {
533
- return REAL(real) ? (Real*)real_new_exact(real->num, real->exp) : (Real*)real_new_flagged(real->flag);
533
+ return REAL(real) ? real_new_exact(real->num, real->exp) : real_new_flagged(real->flag);
534
534
  }
535
535
 
536
536
  /*
@@ -811,7 +811,7 @@ Real* real_divide (Real* a, Real* b, int round_mode)
811
811
  mpfr_init2(num, PREC);
812
812
  mpfr_div(num, a_num, b_num, MPFR_RNDN);
813
813
 
814
- result = (Real*)real_from_mpfr(num, round_mode);
814
+ result = real_from_mpfr(num, round_mode);
815
815
 
816
816
  mpfr_clear(a_num);
817
817
  mpfr_clear(b_num);
@@ -28,7 +28,7 @@ void real_bounds_update (RealBounds* bounds, Real* real, int closed)
28
28
  {
29
29
  real_free(bounds->min);
30
30
 
31
- bounds->min = (Real*)real_dup(real);
31
+ bounds->min = real_dup(real);
32
32
  bounds->min_closed = (min_cmp) ? closed : bounds->min_closed || closed;
33
33
  }
34
34
 
@@ -36,7 +36,7 @@ void real_bounds_update (RealBounds* bounds, Real* real, int closed)
36
36
  {
37
37
  real_free(bounds->max);
38
38
 
39
- bounds->max = (Real*)real_dup(real);
39
+ bounds->max = real_dup(real);
40
40
  bounds->max_closed = (max_cmp) ? closed : bounds->max_closed || closed;
41
41
  }
42
42
 
@@ -0,0 +1,46 @@
1
+ #include "number.h"
2
+
3
+ Complex* complex_round (Complex* complex)
4
+ {
5
+ return complex_new(interval_round(complex->re), interval_round(complex->im));
6
+ }
7
+
8
+ Complex* complex_round_c_c (Complex* complex)
9
+ {
10
+ return complex_new(interval_round_ceiling(complex->re), interval_round_ceiling(complex->im));
11
+ }
12
+
13
+ Complex* complex_round_c_f (Complex* complex)
14
+ {
15
+ return complex_new(interval_round_floor(complex->re), interval_round_ceiling(complex->im));
16
+ }
17
+
18
+ Complex* complex_round_f_c (Complex* complex)
19
+ {
20
+ return complex_new(interval_round_ceiling(complex->re), interval_round_floor(complex->im));
21
+ }
22
+
23
+ Complex* complex_round_f_f (Complex* complex)
24
+ {
25
+ return complex_new(interval_round_floor(complex->re), interval_round_floor(complex->im));
26
+ }
27
+
28
+ Complex* complex_round_i_i (Complex* complex)
29
+ {
30
+ return complex_new(interval_round_infinity(complex->re), interval_round_infinity(complex->im));
31
+ }
32
+
33
+ Complex* complex_round_i_o (Complex* complex)
34
+ {
35
+ return complex_new(interval_round_infinity(complex->re), interval_round_origin(complex->im));
36
+ }
37
+
38
+ Complex* complex_round_o_i (Complex* complex)
39
+ {
40
+ return complex_new(interval_round_origin(complex->re), interval_round_infinity(complex->im));
41
+ }
42
+
43
+ Complex* complex_round_o_o (Complex* complex)
44
+ {
45
+ return complex_new(interval_round_origin(complex->re), interval_round_origin(complex->im));
46
+ }