number 0.9.9 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/number/bounds.c +5 -12
- data/ext/number/complex.c +105 -143
- data/ext/number/decompose.c +185 -122
- data/ext/number/interval.c +95 -89
- data/ext/number/real.c +31 -71
- data/ext/number/real_bounds.c +8 -4
- data/ext/number/round.c +36 -9
- metadata +3 -3
data/ext/number/real.c
CHANGED
@@ -170,22 +170,16 @@ void real_print (char* buf, Real* real)
|
|
170
170
|
*/
|
171
171
|
void real_pad_tmps (Real* a, Real* b, long* exp, long* len)
|
172
172
|
{
|
173
|
-
long a_len;
|
174
|
-
long b_len;
|
175
|
-
long a_last_place;
|
176
|
-
long b_last_place;
|
177
|
-
long pad;
|
178
|
-
|
179
173
|
mpz_set(a_tmp, a->num);
|
180
174
|
mpz_set(b_tmp, b->num);
|
181
175
|
|
182
|
-
a_len = num_len(a_tmp);
|
183
|
-
b_len = num_len(b_tmp);
|
176
|
+
long a_len = num_len(a_tmp);
|
177
|
+
long b_len = num_len(b_tmp);
|
184
178
|
|
185
|
-
a_last_place = 1 + a->exp - a_len;
|
186
|
-
b_last_place = 1 + b->exp - b_len;
|
179
|
+
long a_last_place = 1 + a->exp - a_len;
|
180
|
+
long b_last_place = 1 + b->exp - b_len;
|
187
181
|
|
188
|
-
pad = a_last_place - b_last_place;
|
182
|
+
long pad = a_last_place - b_last_place;
|
189
183
|
|
190
184
|
if (pad > 0)
|
191
185
|
{
|
@@ -231,8 +225,6 @@ int real_positive_p (Real* real)
|
|
231
225
|
*/
|
232
226
|
int real_cmp (Real* a, Real* b)
|
233
227
|
{
|
234
|
-
int a_sign;
|
235
|
-
int b_sign;
|
236
228
|
long exp;
|
237
229
|
long len;
|
238
230
|
|
@@ -241,8 +233,8 @@ int real_cmp (Real* a, Real* b)
|
|
241
233
|
return (NaN(a) || NaN(b)) ? 0 : POS_INF(a) ? (POS_INF(b) ? 0 : 1) : POS_INF(b) ? -1 : NEG_INF(a) ? (NEG_INF(b) ? 0 : -1) : 1;
|
242
234
|
}
|
243
235
|
|
244
|
-
a_sign = mpz_sgn(a->num);
|
245
|
-
b_sign = mpz_sgn(b->num);
|
236
|
+
int a_sign = mpz_sgn(a->num);
|
237
|
+
int b_sign = mpz_sgn(b->num);
|
246
238
|
|
247
239
|
if (a_sign != b_sign)
|
248
240
|
{
|
@@ -303,8 +295,7 @@ int real_le_p (Real* a, Real* b)
|
|
303
295
|
*/
|
304
296
|
Real* real_alloc ()
|
305
297
|
{
|
306
|
-
Real* real;
|
307
|
-
real = malloc(sizeof(Real));
|
298
|
+
Real* real = malloc(sizeof(Real));
|
308
299
|
|
309
300
|
if (real == NULL)
|
310
301
|
{
|
@@ -325,8 +316,7 @@ Real* real_alloc ()
|
|
325
316
|
*/
|
326
317
|
Real* real_new_flagged (int flag)
|
327
318
|
{
|
328
|
-
Real* real;
|
329
|
-
real = real_alloc();
|
319
|
+
Real* real = real_alloc();
|
330
320
|
|
331
321
|
real->exp = 0;
|
332
322
|
real->flag = flag;
|
@@ -344,8 +334,7 @@ Real* real_new_flagged (int flag)
|
|
344
334
|
*/
|
345
335
|
Real* real_new_exact (mpz_t num, long exp)
|
346
336
|
{
|
347
|
-
Real* real;
|
348
|
-
real = real_alloc();
|
337
|
+
Real* real = real_alloc();
|
349
338
|
|
350
339
|
real->exp = exp;
|
351
340
|
real->flag = 0;
|
@@ -360,22 +349,17 @@ Real* real_new_exact (mpz_t num, long exp)
|
|
360
349
|
|
361
350
|
mpz_set(real->num, num);
|
362
351
|
|
363
|
-
if (mpz_sgn(real->num))
|
352
|
+
if (mpz_sgn(real->num) == 0)
|
353
|
+
{
|
354
|
+
real->exp = 0;
|
355
|
+
}
|
356
|
+
else
|
364
357
|
{
|
365
|
-
while (mpz_divisible_ui_p(real->num, 10000))
|
366
|
-
{
|
367
|
-
mpz_divexact_ui(real->num, real->num, 10000);
|
368
|
-
}
|
369
|
-
|
370
358
|
while (mpz_divisible_ui_p(real->num, 10))
|
371
359
|
{
|
372
360
|
mpz_divexact_ui(real->num, real->num, 10);
|
373
361
|
}
|
374
362
|
}
|
375
|
-
else
|
376
|
-
{
|
377
|
-
real->exp = 0;
|
378
|
-
}
|
379
363
|
|
380
364
|
return real;
|
381
365
|
}
|
@@ -392,13 +376,10 @@ Real* real_new_exact (mpz_t num, long exp)
|
|
392
376
|
*/
|
393
377
|
Real* real_new_rounded (mpz_t num, long exp, int round_mode)
|
394
378
|
{
|
395
|
-
long len;
|
396
|
-
long overrun;
|
397
|
-
|
398
379
|
mpz_set(tmp_real_new_rounded, num);
|
399
380
|
|
400
|
-
len = num_len(num);
|
401
|
-
overrun = len - digs;
|
381
|
+
long len = num_len(num);
|
382
|
+
long overrun = len - digs;
|
402
383
|
|
403
384
|
if (overrun > 0)
|
404
385
|
{
|
@@ -578,15 +559,12 @@ Real* real_negate (Real* real)
|
|
578
559
|
*/
|
579
560
|
Real* real_ceil (Real* real)
|
580
561
|
{
|
581
|
-
long len;
|
582
|
-
long dec;
|
583
|
-
|
584
562
|
REAL_CHECK(real);
|
585
563
|
|
586
564
|
mpz_set(tmp_real_ceil, real->num);
|
587
565
|
|
588
|
-
len = num_len(tmp_real_ceil);
|
589
|
-
dec = len - real->exp;
|
566
|
+
long len = num_len(tmp_real_ceil);
|
567
|
+
long dec = len - real->exp;
|
590
568
|
|
591
569
|
if (dec > 0)
|
592
570
|
{
|
@@ -606,15 +584,12 @@ Real* real_ceil (Real* real)
|
|
606
584
|
*/
|
607
585
|
Real* real_floor (Real* real)
|
608
586
|
{
|
609
|
-
long len;
|
610
|
-
long dec;
|
611
|
-
|
612
587
|
REAL_CHECK(real);
|
613
588
|
|
614
589
|
mpz_set(tmp_real_floor, real->num);
|
615
590
|
|
616
|
-
len = num_len(tmp_real_floor);
|
617
|
-
dec = len - real->exp;
|
591
|
+
long len = num_len(tmp_real_floor);
|
592
|
+
long dec = len - real->exp;
|
618
593
|
|
619
594
|
if (dec > 0)
|
620
595
|
{
|
@@ -634,15 +609,12 @@ Real* real_floor (Real* real)
|
|
634
609
|
*/
|
635
610
|
Real* real_round (Real* real)
|
636
611
|
{
|
637
|
-
long len;
|
638
|
-
long dec;
|
639
|
-
|
640
612
|
REAL_CHECK(real);
|
641
613
|
|
642
614
|
mpz_set(tmp_real_round, real->num);
|
643
615
|
|
644
|
-
len = num_len(tmp_real_round);
|
645
|
-
dec = len - real->exp;
|
616
|
+
long len = num_len(tmp_real_round);
|
617
|
+
long dec = len - real->exp;
|
646
618
|
|
647
619
|
if (dec > 0)
|
648
620
|
{
|
@@ -662,15 +634,12 @@ Real* real_round (Real* real)
|
|
662
634
|
*/
|
663
635
|
Real* real_round_infinity (Real* real)
|
664
636
|
{
|
665
|
-
long len;
|
666
|
-
long dec;
|
667
|
-
|
668
637
|
REAL_CHECK(real);
|
669
638
|
|
670
639
|
mpz_set(tmp_real_round_infinity, real->num);
|
671
640
|
|
672
|
-
len = num_len(tmp_real_round_infinity);
|
673
|
-
dec = len - real->exp;
|
641
|
+
long len = num_len(tmp_real_round_infinity);
|
642
|
+
long dec = len - real->exp;
|
674
643
|
|
675
644
|
if (dec > 0)
|
676
645
|
{
|
@@ -690,15 +659,12 @@ Real* real_round_infinity (Real* real)
|
|
690
659
|
*/
|
691
660
|
Real* real_round_origin (Real* real)
|
692
661
|
{
|
693
|
-
long len;
|
694
|
-
long dec;
|
695
|
-
|
696
662
|
REAL_CHECK(real);
|
697
663
|
|
698
664
|
mpz_set(tmp_real_round_origin, real->num);
|
699
665
|
|
700
|
-
len = num_len(tmp_real_round_origin);
|
701
|
-
dec = len - real->exp;
|
666
|
+
long len = num_len(tmp_real_round_origin);
|
667
|
+
long dec = len - real->exp;
|
702
668
|
|
703
669
|
if (dec > 0)
|
704
670
|
{
|
@@ -764,21 +730,16 @@ Real* real_subtract (Real* a, Real* b)
|
|
764
730
|
*/
|
765
731
|
Real* real_multiply (Real* a, Real* b)
|
766
732
|
{
|
767
|
-
long a_len;
|
768
|
-
long b_len;
|
769
|
-
long exp;
|
770
|
-
long dec;
|
771
|
-
|
772
733
|
if (!REAL(a) || !REAL(b))
|
773
734
|
{
|
774
735
|
return (NaN(a) || NaN(b) || ZERO(a) || ZERO(b)) ? real_nan() : ((POS(a) && POS(b)) || (NEG(a) && NEG(b))) ? real_pos_inf() : real_neg_inf();
|
775
736
|
}
|
776
737
|
|
777
|
-
a_len = num_len(a->num);
|
778
|
-
b_len = num_len(b->num);
|
738
|
+
long a_len = num_len(a->num);
|
739
|
+
long b_len = num_len(b->num);
|
779
740
|
|
780
741
|
mpz_mul(tmp_real_multiply, a->num, b->num);
|
781
|
-
exp = num_len(tmp_real_multiply) - ((a_len - a->exp) + (b_len - b->exp));
|
742
|
+
long exp = num_len(tmp_real_multiply) - ((a_len - a->exp) + (b_len - b->exp));
|
782
743
|
|
783
744
|
return real_new_exact(tmp_real_multiply, exp);
|
784
745
|
}
|
@@ -796,7 +757,6 @@ Real* real_divide (Real* a, Real* b, int round_mode)
|
|
796
757
|
mpfr_t a_num;
|
797
758
|
mpfr_t b_num;
|
798
759
|
mpfr_t num;
|
799
|
-
Real* result;
|
800
760
|
|
801
761
|
if (!REAL(a) || !REAL(b))
|
802
762
|
{
|
@@ -811,7 +771,7 @@ Real* real_divide (Real* a, Real* b, int round_mode)
|
|
811
771
|
mpfr_init2(num, PREC);
|
812
772
|
mpfr_div(num, a_num, b_num, MPFR_RNDN);
|
813
773
|
|
814
|
-
result = real_from_mpfr(num, round_mode);
|
774
|
+
Real* result = real_from_mpfr(num, round_mode);
|
815
775
|
|
816
776
|
mpfr_clear(a_num);
|
817
777
|
mpfr_clear(b_num);
|
data/ext/number/real_bounds.c
CHANGED
@@ -24,7 +24,7 @@ void real_bounds_update (RealBounds* bounds, Real* real, int closed)
|
|
24
24
|
int min_cmp;
|
25
25
|
int max_cmp;
|
26
26
|
|
27
|
-
if (
|
27
|
+
if (min_cmp = real_cmp(bounds->min, real) != -1)
|
28
28
|
{
|
29
29
|
real_free(bounds->min);
|
30
30
|
|
@@ -32,7 +32,7 @@ void real_bounds_update (RealBounds* bounds, Real* real, int closed)
|
|
32
32
|
bounds->min_closed = (min_cmp) ? closed : bounds->min_closed || closed;
|
33
33
|
}
|
34
34
|
|
35
|
-
if (
|
35
|
+
if (max_cmp = real_cmp(bounds->max, real) != 1)
|
36
36
|
{
|
37
37
|
real_free(bounds->max);
|
38
38
|
|
@@ -45,8 +45,7 @@ void real_bounds_update (RealBounds* bounds, Real* real, int closed)
|
|
45
45
|
|
46
46
|
RealBounds* real_bounds_new ()
|
47
47
|
{
|
48
|
-
RealBounds* bounds;
|
49
|
-
bounds = malloc(sizeof(RealBounds));
|
48
|
+
RealBounds* bounds = malloc(sizeof(RealBounds));
|
50
49
|
|
51
50
|
if (bounds == NULL)
|
52
51
|
{
|
@@ -54,4 +53,9 @@ RealBounds* real_bounds_new ()
|
|
54
53
|
}
|
55
54
|
|
56
55
|
memset(bounds, 0, sizeof(RealBounds));
|
56
|
+
|
57
|
+
bounds->min = real_pos_inf();
|
58
|
+
bounds->max = real_neg_inf();
|
59
|
+
|
60
|
+
return bounds;
|
57
61
|
}
|
data/ext/number/round.c
CHANGED
@@ -2,45 +2,72 @@
|
|
2
2
|
|
3
3
|
Complex* complex_round (Complex* complex)
|
4
4
|
{
|
5
|
-
|
5
|
+
Interval* re = interval_round(complex->re);
|
6
|
+
Interval* im = interval_round(complex->im);
|
7
|
+
|
8
|
+
return complex_new(re, im);
|
6
9
|
}
|
7
10
|
|
8
11
|
Complex* complex_round_c_c (Complex* complex)
|
9
12
|
{
|
10
|
-
|
13
|
+
Interval* re = interval_round_ceiling(complex->re);
|
14
|
+
Interval* im = interval_round_ceiling(complex->im);
|
15
|
+
|
16
|
+
return complex_new(re, im);
|
11
17
|
}
|
12
18
|
|
13
19
|
Complex* complex_round_c_f (Complex* complex)
|
14
20
|
{
|
15
|
-
|
21
|
+
Interval* re = interval_round_ceiling(complex->re);
|
22
|
+
Interval* im = interval_round_floor(complex->im);
|
23
|
+
|
24
|
+
return complex_new(re, im);
|
16
25
|
}
|
17
26
|
|
18
27
|
Complex* complex_round_f_c (Complex* complex)
|
19
28
|
{
|
20
|
-
|
29
|
+
Interval* re = interval_round_floor(complex->re);
|
30
|
+
Interval* im = interval_round_ceiling(complex->im);
|
31
|
+
|
32
|
+
return complex_new(re, im);
|
21
33
|
}
|
22
34
|
|
23
35
|
Complex* complex_round_f_f (Complex* complex)
|
24
36
|
{
|
25
|
-
|
37
|
+
Interval* re = interval_round_floor(complex->re);
|
38
|
+
Interval* im = interval_round_floor(complex->im);
|
39
|
+
|
40
|
+
return complex_new(re, im);
|
26
41
|
}
|
27
42
|
|
28
43
|
Complex* complex_round_i_i (Complex* complex)
|
29
44
|
{
|
30
|
-
|
45
|
+
Interval* re = interval_round_infinity(complex->re);
|
46
|
+
Interval* im = interval_round_infinity(complex->im);
|
47
|
+
|
48
|
+
return complex_new(re, im);
|
31
49
|
}
|
32
50
|
|
33
51
|
Complex* complex_round_i_o (Complex* complex)
|
34
52
|
{
|
35
|
-
|
53
|
+
Interval* re = interval_round_infinity(complex->re);
|
54
|
+
Interval* im = interval_round_origin(complex->im);
|
55
|
+
|
56
|
+
return complex_new(re, im);
|
36
57
|
}
|
37
58
|
|
38
59
|
Complex* complex_round_o_i (Complex* complex)
|
39
60
|
{
|
40
|
-
|
61
|
+
Interval* re = interval_round_origin(complex->re);
|
62
|
+
Interval* im = interval_round_infinity(complex->im);
|
63
|
+
|
64
|
+
return complex_new(re, im);
|
41
65
|
}
|
42
66
|
|
43
67
|
Complex* complex_round_o_o (Complex* complex)
|
44
68
|
{
|
45
|
-
|
69
|
+
Interval* re = interval_round_origin(complex->re);
|
70
|
+
Interval* im = interval_round_origin(complex->im);
|
71
|
+
|
72
|
+
return complex_new(re, im);
|
46
73
|
}
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jesse Sielaff
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2011-
|
15
|
+
date: 2011-09-02 00:00:00 Z
|
16
16
|
dependencies: []
|
17
17
|
|
18
18
|
description: The Number gem is intended to be a drop-in replacement for Ruby's Numeric classes when arbitrary-precision complex interval calculations are warranted. The basis of the arbitrary-precision calculations is the GNU MP, MPFR, and MPC libraries.
|
@@ -60,7 +60,7 @@ requirements:
|
|
60
60
|
- MPFR
|
61
61
|
- MPC
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.8.
|
63
|
+
rubygems_version: 1.8.8
|
64
64
|
signing_key:
|
65
65
|
specification_version: 3
|
66
66
|
summary: An arbitrary-precision complex interval number library for Ruby.
|