number 0.9.6 → 0.9.7
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/interval.c +0 -4
- data/ext/number.c +51 -12
- data/ext/real.c +1 -1
- metadata +2 -2
data/ext/interval.c
CHANGED
@@ -319,10 +319,6 @@ Interval* interval_divide (Interval* a, Interval* b)
|
|
319
319
|
Interval* interval;
|
320
320
|
|
321
321
|
bounds = (RealBounds*)real_bounds_new();
|
322
|
-
real_bounds_update(bounds, (Real*)real_divide(a->l, b->l, ROUND_NEAREST), a->L && b->L);
|
323
|
-
real_bounds_update(bounds, (Real*)real_divide(a->l, b->u, ROUND_NEAREST), a->L && b->R);
|
324
|
-
real_bounds_update(bounds, (Real*)real_divide(a->u, b->l, ROUND_NEAREST), a->R && b->L);
|
325
|
-
real_bounds_update(bounds, (Real*)real_divide(a->u, b->u, ROUND_NEAREST), a->R && b->R);
|
326
322
|
real_bounds_update(bounds, (Real*)real_divide(a->l, b->l, ROUND_DOWN), a->L && b->L);
|
327
323
|
real_bounds_update(bounds, (Real*)real_divide(a->l, b->u, ROUND_DOWN), a->L && b->R);
|
328
324
|
real_bounds_update(bounds, (Real*)real_divide(a->u, b->l, ROUND_DOWN), a->R && b->L);
|
data/ext/number.c
CHANGED
@@ -3,6 +3,14 @@
|
|
3
3
|
long digs;
|
4
4
|
VALUE rb_cNumber;
|
5
5
|
|
6
|
+
VALUE rb_NilClass_to_number (VALUE nil)
|
7
|
+
{
|
8
|
+
VALUE result = rb_obj_alloc(rb_cNumber);
|
9
|
+
DATA_PTR(result) = (Complex*)complex_nan();
|
10
|
+
|
11
|
+
return result;
|
12
|
+
}
|
13
|
+
|
6
14
|
VALUE rb_String_to_number (VALUE str)
|
7
15
|
{
|
8
16
|
VALUE complex_regex = rb_enc_reg_new("^(.*[^\\s]+)\\s*\\+\\s*(.*)i$", strlen("^(.*[^\\s]+)\\s*\\+\\s*(.*)i$"), rb_utf8_encoding(), 0);
|
@@ -113,11 +121,14 @@ VALUE rb_Complex_to_number (VALUE complex)
|
|
113
121
|
|
114
122
|
VALUE rb_f_Number (int argc, VALUE* argv, VALUE obj)
|
115
123
|
{
|
116
|
-
int L;
|
117
|
-
int R;
|
118
124
|
Complex* tmp1;
|
119
125
|
Complex* tmp2;
|
120
126
|
Complex* tmp3;
|
127
|
+
Interval* i1;
|
128
|
+
Interval* i2;
|
129
|
+
VALUE tmp_A;
|
130
|
+
VALUE tmp_B;
|
131
|
+
VALUE tmp_C;
|
121
132
|
VALUE arg1;
|
122
133
|
VALUE arg2;
|
123
134
|
VALUE arg3;
|
@@ -128,25 +139,52 @@ VALUE rb_f_Number (int argc, VALUE* argv, VALUE obj)
|
|
128
139
|
switch (rb_scan_args(argc, argv, "14", &arg1, &arg2, &arg3, &arg4, &arg5))
|
129
140
|
{
|
130
141
|
case 1:
|
131
|
-
|
142
|
+
tmp_A = rb_convert_type(arg1, T_DATA, "Number", "to_number");
|
143
|
+
tmp1 = (Complex*)DATA_PTR(tmp_A);
|
144
|
+
|
145
|
+
DATA_PTR(result) = (Complex*)complex_dup(tmp1);
|
132
146
|
break;
|
133
147
|
|
134
148
|
case 2:
|
135
|
-
|
136
|
-
|
149
|
+
tmp_A = rb_convert_type(arg1, T_DATA, "Number", "to_number");
|
150
|
+
tmp_B = rb_convert_type(arg2, T_DATA, "Number", "to_number");
|
137
151
|
|
138
|
-
|
152
|
+
tmp1 = (Complex*)DATA_PTR(tmp_A);
|
153
|
+
tmp2 = (Complex*)DATA_PTR(tmp_B);
|
154
|
+
|
155
|
+
Interval* re1 = (Interval*)tmp1->re;
|
156
|
+
Interval* re2 = (Interval*)tmp2->re;
|
157
|
+
|
158
|
+
i1 = (Interval*)interval_dup(re1);
|
159
|
+
i2 = (Interval*)interval_dup(re2);
|
160
|
+
|
161
|
+
DATA_PTR(result) = (Complex*)complex_new(i1, i2);
|
139
162
|
break;
|
140
163
|
|
141
164
|
default:
|
142
|
-
|
143
|
-
|
165
|
+
tmp_A = rb_convert_type(arg1, T_DATA, "Number", "to_number");
|
166
|
+
tmp_B = rb_convert_type(arg2, T_DATA, "Number", "to_number");
|
167
|
+
tmp_C = rb_convert_type(arg3, T_DATA, "Number", "to_number");
|
168
|
+
|
169
|
+
tmp1 = (Complex*)DATA_PTR(tmp_A);
|
170
|
+
tmp2 = (Complex*)DATA_PTR(tmp_B);
|
171
|
+
tmp3 = (Complex*)DATA_PTR(tmp_C);
|
172
|
+
|
173
|
+
Real* n1 = (Real*)tmp1->re->n;
|
174
|
+
Real* n2 = (Real*)tmp2->re->n;
|
175
|
+
Real* n3 = (Real*)tmp3->re->n;
|
176
|
+
|
177
|
+
Real* r1 = (Real*)real_dup(n1);
|
178
|
+
Real* r2 = (Real*)real_dup(n2);
|
179
|
+
Real* r3 = (Real*)real_dup(n3);
|
180
|
+
|
181
|
+
int L = (argc == 3) ? true : RTEST(arg4);
|
182
|
+
int R = (argc == 5) ? RTEST(arg5) : L;
|
144
183
|
|
145
|
-
|
146
|
-
|
147
|
-
tmp3 = (Complex*)DATA_PTR(rb_convert_type(arg3, T_DATA, "Number", "to_number"));
|
184
|
+
i1 = (Interval*)interval_new(r1, L, r2, R, r3);
|
185
|
+
i2 = (Interval*)interval_zero();
|
148
186
|
|
149
|
-
DATA_PTR(result) = (Complex*)complex_new(
|
187
|
+
DATA_PTR(result) = (Complex*)complex_new(i1, i2);
|
150
188
|
break;
|
151
189
|
}
|
152
190
|
|
@@ -1387,6 +1425,7 @@ void Init_number ()
|
|
1387
1425
|
init_real_tmp_nums();
|
1388
1426
|
init_complex_tmp_nums();
|
1389
1427
|
|
1428
|
+
rb_define_method(rb_cNilClass, "to_number", rb_NilClass_to_number, 0);
|
1390
1429
|
rb_define_method(rb_cString, "to_number", rb_String_to_number, 0);
|
1391
1430
|
rb_define_method(rb_cInteger, "to_number", rb_Integer_to_number, 0);
|
1392
1431
|
rb_define_method(rb_cFloat, "to_number", rb_Float_to_number, 0);
|
data/ext/real.c
CHANGED
@@ -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_new_exact(real->num, real->exp) : real_new_flagged(real->flag);
|
533
|
+
return REAL(real) ? (Real*)real_new_exact(real->num, real->exp) : (Real*)real_new_flagged(real->flag);
|
534
534
|
}
|
535
535
|
|
536
536
|
/*
|
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.7
|
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-07-
|
15
|
+
date: 2011-07-27 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.
|