number 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- 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/decompose.c
CHANGED
@@ -2,230 +2,293 @@
|
|
2
2
|
|
3
3
|
Complex* complex_im (Complex* complex)
|
4
4
|
{
|
5
|
-
|
5
|
+
Interval* re = interval_dup(complex->im);
|
6
|
+
Interval* im = interval_zero();
|
7
|
+
|
8
|
+
return complex_new(re, im);
|
6
9
|
}
|
7
10
|
|
8
11
|
Complex* complex_im_l (Complex* complex)
|
9
12
|
{
|
10
|
-
|
13
|
+
Real* real = real_dup(complex->im->l);
|
14
|
+
return complex_from_real(real);
|
11
15
|
}
|
12
16
|
|
13
17
|
Complex* complex_im_n (Complex* complex)
|
14
18
|
{
|
15
|
-
|
19
|
+
Real* real = real_dup(complex->im->n);
|
20
|
+
return complex_from_real(real);
|
16
21
|
}
|
17
22
|
|
18
23
|
Complex* complex_im_u (Complex* complex)
|
19
24
|
{
|
20
|
-
|
25
|
+
Real* real = real_dup(complex->im->u);
|
26
|
+
return complex_from_real(real);
|
21
27
|
}
|
22
28
|
|
23
29
|
Complex* complex_im_magnitude (Complex* complex)
|
24
30
|
{
|
25
|
-
Real* l_abs;
|
26
|
-
Real* u_abs;
|
27
31
|
Complex* result;
|
28
32
|
|
29
|
-
l_abs = real_abs(complex->im->l);
|
30
|
-
u_abs = real_abs(complex->im->u);
|
31
|
-
|
32
|
-
result = complex_from_real(real_gt_p(l_abs, u_abs) ? l_abs : u_abs);
|
33
|
+
Real* l_abs = real_abs(complex->im->l);
|
34
|
+
Real* u_abs = real_abs(complex->im->u);
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
+
if (real_gt_p(l_abs, u_abs))
|
37
|
+
{
|
38
|
+
result = complex_from_real(l_abs);
|
39
|
+
real_free(u_abs);
|
40
|
+
}
|
41
|
+
else
|
42
|
+
{
|
43
|
+
result = complex_from_real(u_abs);
|
44
|
+
real_free(l_abs);
|
45
|
+
}
|
36
46
|
|
37
47
|
return result;
|
38
48
|
}
|
39
49
|
|
40
50
|
Complex* complex_im_mignitude (Complex* complex)
|
41
51
|
{
|
42
|
-
Real* l_abs;
|
43
|
-
Real* u_abs;
|
44
|
-
Real* zero;
|
45
52
|
Complex* result;
|
46
53
|
|
47
|
-
l_abs = real_abs(complex->im->l);
|
48
|
-
u_abs = real_abs(complex->im->u);
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
Real* l_abs = real_abs(complex->im->l);
|
55
|
+
Real* u_abs = real_abs(complex->im->u);
|
56
|
+
|
57
|
+
if (interval_span_zero_p(complex->im))
|
58
|
+
{
|
59
|
+
result = complex_zero();
|
60
|
+
real_free(l_abs);
|
61
|
+
real_free(u_abs);
|
62
|
+
}
|
63
|
+
else if (real_lt_p(l_abs, u_abs))
|
64
|
+
{
|
65
|
+
result = complex_from_real(l_abs);
|
66
|
+
real_free(u_abs);
|
67
|
+
}
|
68
|
+
else
|
69
|
+
{
|
70
|
+
result = complex_from_real(u_abs);
|
71
|
+
real_free(l_abs);
|
72
|
+
}
|
56
73
|
|
57
74
|
return result;
|
58
75
|
}
|
59
76
|
|
60
77
|
Complex* complex_im_width (Complex* complex)
|
61
78
|
{
|
62
|
-
Real*
|
63
|
-
|
64
|
-
|
65
|
-
width = real_subtract(complex->im->u, complex->im->l);
|
66
|
-
result = complex_from_real(width);
|
67
|
-
|
68
|
-
real_free(width);
|
69
|
-
|
70
|
-
return result;
|
79
|
+
Real* real = real_subtract(complex->im->u, complex->im->l);
|
80
|
+
return complex_from_real(real);
|
71
81
|
}
|
72
82
|
|
73
83
|
Complex* complex_re (Complex* complex)
|
74
84
|
{
|
75
|
-
|
85
|
+
Interval* re = interval_dup(complex->re);
|
86
|
+
Interval* im = interval_zero();
|
87
|
+
|
88
|
+
return complex_new(re, im);
|
76
89
|
}
|
77
90
|
|
78
91
|
Complex* complex_re_l (Complex* complex)
|
79
92
|
{
|
80
|
-
|
93
|
+
Real* real = real_dup(complex->re->l);
|
94
|
+
return complex_from_real(real);
|
81
95
|
}
|
82
96
|
|
83
97
|
Complex* complex_re_n (Complex* complex)
|
84
98
|
{
|
85
|
-
|
99
|
+
Real* real = real_dup(complex->re->n);
|
100
|
+
return complex_from_real(real);
|
86
101
|
}
|
87
102
|
|
88
103
|
Complex* complex_re_u (Complex* complex)
|
89
104
|
{
|
90
|
-
|
105
|
+
Real* real = real_dup(complex->re->u);
|
106
|
+
return complex_from_real(real);
|
91
107
|
}
|
92
108
|
|
93
109
|
Complex* complex_re_magnitude (Complex* complex)
|
94
110
|
{
|
95
|
-
Real* l_abs;
|
96
|
-
Real* u_abs;
|
97
111
|
Complex* result;
|
98
112
|
|
99
|
-
l_abs = real_abs(complex->re->l);
|
100
|
-
u_abs = real_abs(complex->re->u);
|
113
|
+
Real* l_abs = real_abs(complex->re->l);
|
114
|
+
Real* u_abs = real_abs(complex->re->u);
|
101
115
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
116
|
+
if (real_gt_p(l_abs, u_abs))
|
117
|
+
{
|
118
|
+
result = complex_from_real(l_abs);
|
119
|
+
real_free(u_abs);
|
120
|
+
}
|
121
|
+
else
|
122
|
+
{
|
123
|
+
result = complex_from_real(u_abs);
|
124
|
+
real_free(l_abs);
|
125
|
+
}
|
106
126
|
|
107
127
|
return result;
|
108
128
|
}
|
109
129
|
|
110
130
|
Complex* complex_re_mignitude (Complex* complex)
|
111
131
|
{
|
112
|
-
Real* l_abs;
|
113
|
-
Real* u_abs;
|
114
|
-
Real* zero;
|
115
132
|
Complex* result;
|
116
133
|
|
117
|
-
l_abs = real_abs(complex->re->l);
|
118
|
-
u_abs = real_abs(complex->re->u);
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
134
|
+
Real* l_abs = real_abs(complex->re->l);
|
135
|
+
Real* u_abs = real_abs(complex->re->u);
|
136
|
+
|
137
|
+
if (interval_span_zero_p(complex->re))
|
138
|
+
{
|
139
|
+
result = complex_zero();
|
140
|
+
real_free(l_abs);
|
141
|
+
real_free(u_abs);
|
142
|
+
}
|
143
|
+
else if (real_lt_p(l_abs, u_abs))
|
144
|
+
{
|
145
|
+
result = complex_from_real(l_abs);
|
146
|
+
real_free(u_abs);
|
147
|
+
}
|
148
|
+
else
|
149
|
+
{
|
150
|
+
result = complex_from_real(u_abs);
|
151
|
+
real_free(l_abs);
|
152
|
+
}
|
126
153
|
|
127
154
|
return result;
|
128
155
|
}
|
129
156
|
|
130
157
|
Complex* complex_re_width (Complex* complex)
|
131
158
|
{
|
132
|
-
Real*
|
133
|
-
|
134
|
-
|
135
|
-
width = real_subtract(complex->re->u, complex->re->l);
|
136
|
-
result = complex_from_real(width);
|
137
|
-
|
138
|
-
real_free(width);
|
139
|
-
|
140
|
-
return result;
|
159
|
+
Real* real = real_subtract(complex->re->u, complex->re->l);
|
160
|
+
return complex_from_real(real);
|
141
161
|
}
|
142
162
|
|
143
163
|
Complex* complex_ll (Complex* complex)
|
144
164
|
{
|
145
|
-
|
165
|
+
Interval* re = interval_from_real(complex->re->l);
|
166
|
+
Interval* im = interval_from_real(complex->im->l);
|
167
|
+
|
168
|
+
return complex_new(re, im);
|
146
169
|
}
|
147
170
|
|
148
171
|
Complex* complex_lu (Complex* complex)
|
149
172
|
{
|
150
|
-
|
173
|
+
Interval* re = interval_from_real(complex->re->l);
|
174
|
+
Interval* im = interval_from_real(complex->im->u);
|
175
|
+
|
176
|
+
return complex_new(re, im);
|
151
177
|
}
|
152
178
|
|
153
179
|
Complex* complex_n (Complex* complex)
|
154
180
|
{
|
155
|
-
|
181
|
+
Interval* re = interval_from_real(complex->re->n);
|
182
|
+
Interval* im = interval_from_real(complex->im->n);
|
183
|
+
|
184
|
+
return complex_new(re, im);
|
156
185
|
}
|
157
186
|
|
158
187
|
Complex* complex_ul (Complex* complex)
|
159
188
|
{
|
160
|
-
|
189
|
+
Interval* re = interval_from_real(complex->re->u);
|
190
|
+
Interval* im = interval_from_real(complex->im->l);
|
191
|
+
|
192
|
+
return complex_new(re, im);
|
161
193
|
}
|
162
194
|
|
163
195
|
Complex* complex_uu (Complex* complex)
|
164
196
|
{
|
165
|
-
|
197
|
+
Interval* re = interval_from_real(complex->re->u);
|
198
|
+
Interval* im = interval_from_real(complex->im->u);
|
199
|
+
|
200
|
+
return complex_new(re, im);
|
166
201
|
}
|
167
202
|
|
168
203
|
Complex* complex_magnitude (Complex* complex)
|
169
204
|
{
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
Real*
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
205
|
+
Interval* re;
|
206
|
+
Interval* im;
|
207
|
+
|
208
|
+
Real* re_l_abs = real_abs(complex->re->l);
|
209
|
+
Real* re_u_abs = real_abs(complex->re->u);
|
210
|
+
Real* im_l_abs = real_abs(complex->im->l);
|
211
|
+
Real* im_u_abs = real_abs(complex->im->u);
|
212
|
+
|
213
|
+
if (real_gt_p(re_l_abs, re_u_abs))
|
214
|
+
{
|
215
|
+
re = interval_from_real(re_l_abs);
|
216
|
+
real_free(re_u_abs);
|
217
|
+
}
|
218
|
+
else
|
219
|
+
{
|
220
|
+
re = interval_from_real(re_u_abs);
|
221
|
+
real_free(re_l_abs);
|
222
|
+
}
|
223
|
+
|
224
|
+
if (real_gt_p(im_l_abs, im_u_abs))
|
225
|
+
{
|
226
|
+
im = interval_from_real(im_l_abs);
|
227
|
+
real_free(im_u_abs);
|
228
|
+
}
|
229
|
+
else
|
230
|
+
{
|
231
|
+
im = interval_from_real(im_u_abs);
|
232
|
+
real_free(im_l_abs);
|
233
|
+
}
|
234
|
+
|
235
|
+
return complex_new(re, im);
|
189
236
|
}
|
190
237
|
|
191
238
|
Complex* complex_mignitude (Complex* complex)
|
192
239
|
{
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
Real*
|
197
|
-
Real*
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
240
|
+
Interval* re;
|
241
|
+
Interval* im;
|
242
|
+
|
243
|
+
Real* re_l_abs = real_abs(complex->re->l);
|
244
|
+
Real* re_u_abs = real_abs(complex->re->u);
|
245
|
+
Real* im_l_abs = real_abs(complex->im->l);
|
246
|
+
Real* im_u_abs = real_abs(complex->im->u);
|
247
|
+
|
248
|
+
if (interval_span_zero_p(complex->re))
|
249
|
+
{
|
250
|
+
re = interval_zero();
|
251
|
+
real_free(re_l_abs);
|
252
|
+
real_free(re_u_abs);
|
253
|
+
}
|
254
|
+
else if (real_lt_p(re_l_abs, re_u_abs))
|
255
|
+
{
|
256
|
+
re = interval_from_real(re_l_abs);
|
257
|
+
real_free(re_u_abs);
|
258
|
+
}
|
259
|
+
else
|
260
|
+
{
|
261
|
+
re = interval_from_real(re_u_abs);
|
262
|
+
real_free(re_l_abs);
|
263
|
+
}
|
264
|
+
|
265
|
+
if (interval_span_zero_p(complex->im))
|
266
|
+
{
|
267
|
+
im = interval_zero();
|
268
|
+
real_free(im_l_abs);
|
269
|
+
real_free(im_u_abs);
|
270
|
+
}
|
271
|
+
else if (real_lt_p(im_l_abs, im_u_abs))
|
272
|
+
{
|
273
|
+
im = interval_from_real(im_l_abs);
|
274
|
+
real_free(im_u_abs);
|
275
|
+
}
|
276
|
+
else
|
277
|
+
{
|
278
|
+
im = interval_from_real(im_u_abs);
|
279
|
+
real_free(im_l_abs);
|
280
|
+
}
|
281
|
+
|
282
|
+
return complex_new(re, im);
|
215
283
|
}
|
216
284
|
|
217
285
|
Complex* complex_width (Complex* complex)
|
218
286
|
{
|
219
|
-
Real* re_width;
|
220
|
-
Real* im_width;
|
221
|
-
Complex* result;
|
287
|
+
Real* re_width = real_subtract(complex->re->u, complex->re->l);
|
288
|
+
Real* im_width = real_subtract(complex->im->u, complex->im->l);
|
222
289
|
|
223
|
-
|
224
|
-
|
225
|
-
result = complex_new(interval_from_real(re_width), interval_from_real(im_width));
|
290
|
+
Interval* re = interval_from_real(re_width);
|
291
|
+
Interval* im = interval_from_real(im_width);
|
226
292
|
|
227
|
-
|
228
|
-
real_free(im_width);
|
229
|
-
|
230
|
-
return result;
|
293
|
+
return complex_new(re, im);
|
231
294
|
}
|
data/ext/number/interval.c
CHANGED
@@ -75,11 +75,8 @@ int interval_span_p (Interval* interval, Real* real)
|
|
75
75
|
*/
|
76
76
|
int interval_span_zero_p (Interval* interval)
|
77
77
|
{
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
zero = real_zero();
|
82
|
-
result = interval_span_p(interval, zero);
|
78
|
+
Real* zero = real_zero();
|
79
|
+
int result = interval_span_p(interval, zero);
|
83
80
|
|
84
81
|
real_free(zero);
|
85
82
|
|
@@ -91,15 +88,7 @@ int interval_span_zero_p (Interval* interval)
|
|
91
88
|
*/
|
92
89
|
int interval_zero_p (Interval* interval)
|
93
90
|
{
|
94
|
-
|
95
|
-
Real* zero;
|
96
|
-
|
97
|
-
zero = real_zero();
|
98
|
-
result = real_eq_p(interval->l, zero) && real_eq_p(interval->u, zero);
|
99
|
-
|
100
|
-
real_free(zero);
|
101
|
-
|
102
|
-
return result;
|
91
|
+
return ZERO(interval->l) && ZERO(interval->u);
|
103
92
|
}
|
104
93
|
|
105
94
|
/*
|
@@ -119,8 +108,7 @@ int interval_degenerate_p (Interval* interval)
|
|
119
108
|
*/
|
120
109
|
Interval* interval_new (Real* l, int L, Real* n, int R, Real* u)
|
121
110
|
{
|
122
|
-
Interval* interval;
|
123
|
-
interval = malloc(sizeof(Interval));
|
111
|
+
Interval* interval = malloc(sizeof(Interval));
|
124
112
|
|
125
113
|
if (interval == NULL)
|
126
114
|
{
|
@@ -131,25 +119,25 @@ Interval* interval_new (Real* l, int L, Real* n, int R, Real* u)
|
|
131
119
|
|
132
120
|
if (NaN(l) || NaN(n) || NaN(u))
|
133
121
|
{
|
134
|
-
interval->n = real_nan();
|
135
|
-
interval->l = real_neg_inf();
|
136
|
-
interval->u = real_pos_inf();
|
137
|
-
|
138
122
|
interval->L = true;
|
139
123
|
interval->R = true;
|
140
124
|
|
125
|
+
interval->l = real_neg_inf();
|
126
|
+
interval->n = real_nan();
|
127
|
+
interval->u = real_pos_inf();
|
128
|
+
|
141
129
|
real_free(n);
|
142
130
|
real_free(l);
|
143
131
|
real_free(u);
|
144
132
|
}
|
145
133
|
else
|
146
134
|
{
|
147
|
-
interval->n = n;
|
148
|
-
interval->l = l;
|
149
|
-
interval->u = u;
|
150
|
-
|
151
135
|
interval->L = (real_eq_p(l, u) || real_eq_p(n, l) || L);
|
152
136
|
interval->R = (real_eq_p(l, u) || real_eq_p(n, u) || R);
|
137
|
+
|
138
|
+
interval->l = l;
|
139
|
+
interval->n = n;
|
140
|
+
interval->u = u;
|
153
141
|
}
|
154
142
|
|
155
143
|
return interval;
|
@@ -157,12 +145,14 @@ Interval* interval_new (Real* l, int L, Real* n, int R, Real* u)
|
|
157
145
|
|
158
146
|
/*
|
159
147
|
* Returns a pointer to a newly allocated Interval containing only the given
|
160
|
-
* real.
|
161
|
-
* be freed separately.
|
148
|
+
* real.
|
162
149
|
*/
|
163
150
|
Interval* interval_from_real (Real* real)
|
164
151
|
{
|
165
|
-
|
152
|
+
Real* l = real_dup(real);
|
153
|
+
Real* u = real_dup(real);
|
154
|
+
|
155
|
+
return interval_new(l, true, real, true, u);
|
166
156
|
}
|
167
157
|
|
168
158
|
/*
|
@@ -170,7 +160,11 @@ Interval* interval_from_real (Real* real)
|
|
170
160
|
*/
|
171
161
|
Interval* interval_nan ()
|
172
162
|
{
|
173
|
-
|
163
|
+
Real* l = real_neg_inf();
|
164
|
+
Real* n = real_nan();
|
165
|
+
Real* u = real_pos_inf();
|
166
|
+
|
167
|
+
return interval_new(l, true, n, true, u);
|
174
168
|
}
|
175
169
|
|
176
170
|
/*
|
@@ -178,7 +172,7 @@ Interval* interval_nan ()
|
|
178
172
|
*/
|
179
173
|
Interval* interval_pos_inf ()
|
180
174
|
{
|
181
|
-
return
|
175
|
+
return interval_from_real(real_pos_inf());
|
182
176
|
}
|
183
177
|
|
184
178
|
/*
|
@@ -186,7 +180,7 @@ Interval* interval_pos_inf ()
|
|
186
180
|
*/
|
187
181
|
Interval* interval_neg_inf ()
|
188
182
|
{
|
189
|
-
return
|
183
|
+
return interval_from_real(real_neg_inf());
|
190
184
|
}
|
191
185
|
|
192
186
|
/*
|
@@ -194,7 +188,7 @@ Interval* interval_neg_inf ()
|
|
194
188
|
*/
|
195
189
|
Interval* interval_zero ()
|
196
190
|
{
|
197
|
-
return
|
191
|
+
return interval_from_real(real_zero());
|
198
192
|
}
|
199
193
|
|
200
194
|
/*
|
@@ -202,7 +196,7 @@ Interval* interval_zero ()
|
|
202
196
|
*/
|
203
197
|
Interval* interval_one ()
|
204
198
|
{
|
205
|
-
return
|
199
|
+
return interval_from_real(real_one());
|
206
200
|
}
|
207
201
|
|
208
202
|
/*
|
@@ -211,7 +205,11 @@ Interval* interval_one ()
|
|
211
205
|
*/
|
212
206
|
Interval* interval_pi ()
|
213
207
|
{
|
214
|
-
|
208
|
+
Real* l = real_pi(ROUND_DOWN);
|
209
|
+
Real* n = real_pi(ROUND_NEAREST);
|
210
|
+
Real* u = real_pi(ROUND_UP1);
|
211
|
+
|
212
|
+
return interval_new(l, false, n, false, u);
|
215
213
|
}
|
216
214
|
|
217
215
|
/*
|
@@ -220,7 +218,11 @@ Interval* interval_pi ()
|
|
220
218
|
*/
|
221
219
|
Interval* interval_e ()
|
222
220
|
{
|
223
|
-
|
221
|
+
Real* l = real_e(ROUND_DOWN);
|
222
|
+
Real* n = real_e(ROUND_NEAREST);
|
223
|
+
Real* u = real_e(ROUND_UP1);
|
224
|
+
|
225
|
+
return interval_new(l, false, n, false, u);
|
224
226
|
}
|
225
227
|
|
226
228
|
/*
|
@@ -229,7 +231,11 @@ Interval* interval_e ()
|
|
229
231
|
*/
|
230
232
|
Interval* interval_dup (Interval* interval)
|
231
233
|
{
|
232
|
-
|
234
|
+
Real* l = real_dup(interval->l);
|
235
|
+
Real* n = real_dup(interval->n);
|
236
|
+
Real* u = real_dup(interval->u);
|
237
|
+
|
238
|
+
return interval_new(l, interval->L, n, interval->R, u);
|
233
239
|
}
|
234
240
|
|
235
241
|
/*
|
@@ -237,18 +243,12 @@ Interval* interval_dup (Interval* interval)
|
|
237
243
|
*/
|
238
244
|
Interval* interval_add (Interval* a, Interval* b)
|
239
245
|
{
|
240
|
-
int L;
|
241
|
-
int R;
|
242
|
-
Real* n;
|
243
|
-
Real* l;
|
244
|
-
Real* u;
|
245
|
-
|
246
|
-
n = real_add(a->n, b->n);
|
247
|
-
l = real_add(a->l, b->l);
|
248
|
-
u = real_add(a->u, b->u);
|
246
|
+
int L = (a->L && b->L);
|
247
|
+
int R = (a->R && b->R);
|
249
248
|
|
250
|
-
|
251
|
-
|
249
|
+
Real* l = real_add(a->l, b->l);
|
250
|
+
Real* n = real_add(a->n, b->n);
|
251
|
+
Real* u = real_add(a->u, b->u);
|
252
252
|
|
253
253
|
return interval_new(l, L, n, R, u);
|
254
254
|
}
|
@@ -258,18 +258,12 @@ Interval* interval_add (Interval* a, Interval* b)
|
|
258
258
|
*/
|
259
259
|
Interval* interval_subtract (Interval* a, Interval* b)
|
260
260
|
{
|
261
|
-
int L;
|
262
|
-
int R;
|
263
|
-
Real* n;
|
264
|
-
Real* l;
|
265
|
-
Real* u;
|
261
|
+
int L = (a->L && b->R);
|
262
|
+
int R = (a->R && b->L);
|
266
263
|
|
267
|
-
|
268
|
-
|
269
|
-
u = real_subtract(a->u, b->l);
|
270
|
-
|
271
|
-
L = (a->L && b->R);
|
272
|
-
R = (a->R && b->L);
|
264
|
+
Real* l = real_subtract(a->l, b->u);
|
265
|
+
Real* n = real_subtract(a->n, b->n);
|
266
|
+
Real* u = real_subtract(a->u, b->l);
|
273
267
|
|
274
268
|
return interval_new(l, L, n, R, u);
|
275
269
|
}
|
@@ -279,25 +273,19 @@ Interval* interval_subtract (Interval* a, Interval* b)
|
|
279
273
|
*/
|
280
274
|
Interval* interval_multiply (Interval* a, Interval* b)
|
281
275
|
{
|
282
|
-
|
283
|
-
|
284
|
-
Real* n;
|
285
|
-
Real* l;
|
286
|
-
Real* u;
|
287
|
-
RealBounds* bounds;
|
288
|
-
|
289
|
-
bounds = real_bounds_new();
|
276
|
+
RealBounds* bounds = real_bounds_new();
|
277
|
+
|
290
278
|
real_bounds_update(bounds, real_multiply(a->l, b->l), (a->L && b->L));
|
291
279
|
real_bounds_update(bounds, real_multiply(a->l, b->u), (a->L && b->R));
|
292
280
|
real_bounds_update(bounds, real_multiply(a->u, b->l), (a->R && b->L));
|
293
281
|
real_bounds_update(bounds, real_multiply(a->u, b->u), (a->R && b->R));
|
294
282
|
|
295
|
-
L = (bounds->min_closed);
|
296
|
-
R = (bounds->max_closed);
|
283
|
+
int L = (bounds->min_closed);
|
284
|
+
int R = (bounds->max_closed);
|
297
285
|
|
298
|
-
|
299
|
-
|
300
|
-
u = real_dup(bounds->max);
|
286
|
+
Real* l = real_dup(bounds->min);
|
287
|
+
Real* n = real_multiply(a->n, b->n);
|
288
|
+
Real* u = real_dup(bounds->max);
|
301
289
|
|
302
290
|
real_bounds_free(bounds);
|
303
291
|
|
@@ -309,14 +297,8 @@ Interval* interval_multiply (Interval* a, Interval* b)
|
|
309
297
|
*/
|
310
298
|
Interval* interval_divide (Interval* a, Interval* b)
|
311
299
|
{
|
312
|
-
|
313
|
-
|
314
|
-
Real* n;
|
315
|
-
Real* l;
|
316
|
-
Real* u;
|
317
|
-
RealBounds* bounds;
|
318
|
-
|
319
|
-
bounds = real_bounds_new();
|
300
|
+
RealBounds* bounds = real_bounds_new();
|
301
|
+
|
320
302
|
real_bounds_update(bounds, real_divide(a->l, b->l, ROUND_DOWN), (a->L && b->L));
|
321
303
|
real_bounds_update(bounds, real_divide(a->l, b->u, ROUND_DOWN), (a->L && b->R));
|
322
304
|
real_bounds_update(bounds, real_divide(a->u, b->l, ROUND_DOWN), (a->R && b->L));
|
@@ -326,12 +308,12 @@ Interval* interval_divide (Interval* a, Interval* b)
|
|
326
308
|
real_bounds_update(bounds, real_divide(a->u, b->l, ROUND_UP), (a->R && b->L));
|
327
309
|
real_bounds_update(bounds, real_divide(a->u, b->u, ROUND_UP), (a->R && b->R));
|
328
310
|
|
329
|
-
L = (bounds->min_closed);
|
330
|
-
R = (bounds->max_closed);
|
311
|
+
int L = (bounds->min_closed);
|
312
|
+
int R = (bounds->max_closed);
|
331
313
|
|
332
|
-
|
333
|
-
|
334
|
-
u = real_dup(bounds->max);
|
314
|
+
Real* l = real_dup(bounds->min);
|
315
|
+
Real* n = real_divide(a->n, b->n, ROUND_NEAREST);
|
316
|
+
Real* u = real_dup(bounds->max);
|
335
317
|
|
336
318
|
real_bounds_free(bounds);
|
337
319
|
|
@@ -343,7 +325,11 @@ Interval* interval_divide (Interval* a, Interval* b)
|
|
343
325
|
*/
|
344
326
|
Interval* interval_negate (Interval* interval)
|
345
327
|
{
|
346
|
-
|
328
|
+
Real* l = real_negate(interval->u);
|
329
|
+
Real* n = real_negate(interval->n);
|
330
|
+
Real* u = real_negate(interval->l);
|
331
|
+
|
332
|
+
return interval_new(l, interval->R, n, interval->L, u);
|
347
333
|
}
|
348
334
|
|
349
335
|
/*
|
@@ -352,7 +338,11 @@ Interval* interval_negate (Interval* interval)
|
|
352
338
|
*/
|
353
339
|
Interval* interval_round (Interval* interval)
|
354
340
|
{
|
355
|
-
|
341
|
+
Real* l = real_round(interval->l);
|
342
|
+
Real* n = real_round(interval->n);
|
343
|
+
Real* u = real_round(interval->u);
|
344
|
+
|
345
|
+
return interval_new(l, true, n, true, u);
|
356
346
|
}
|
357
347
|
|
358
348
|
/*
|
@@ -362,7 +352,11 @@ Interval* interval_round (Interval* interval)
|
|
362
352
|
*/
|
363
353
|
Interval* interval_round_ceiling (Interval* interval)
|
364
354
|
{
|
365
|
-
|
355
|
+
Real* l = real_ceil(interval->l);
|
356
|
+
Real* n = real_ceil(interval->n);
|
357
|
+
Real* u = real_ceil(interval->u);
|
358
|
+
|
359
|
+
return interval_new(l, true, n, true, u);
|
366
360
|
}
|
367
361
|
|
368
362
|
/*
|
@@ -372,7 +366,11 @@ Interval* interval_round_ceiling (Interval* interval)
|
|
372
366
|
*/
|
373
367
|
Interval* interval_round_floor (Interval* interval)
|
374
368
|
{
|
375
|
-
|
369
|
+
Real* l = real_floor(interval->l);
|
370
|
+
Real* n = real_floor(interval->n);
|
371
|
+
Real* u = real_floor(interval->u);
|
372
|
+
|
373
|
+
return interval_new(l, true, n, true, u);
|
376
374
|
}
|
377
375
|
|
378
376
|
/*
|
@@ -382,7 +380,11 @@ Interval* interval_round_floor (Interval* interval)
|
|
382
380
|
*/
|
383
381
|
Interval* interval_round_infinity (Interval* interval)
|
384
382
|
{
|
385
|
-
|
383
|
+
Real* l = real_round_infinity(interval->l);
|
384
|
+
Real* n = real_round_infinity(interval->n);
|
385
|
+
Real* u = real_round_infinity(interval->u);
|
386
|
+
|
387
|
+
return interval_new(l, true, n, true, u);
|
386
388
|
}
|
387
389
|
|
388
390
|
/*
|
@@ -392,5 +394,9 @@ Interval* interval_round_infinity (Interval* interval)
|
|
392
394
|
*/
|
393
395
|
Interval* interval_round_origin (Interval* interval)
|
394
396
|
{
|
395
|
-
|
397
|
+
Real* l = real_round_origin(interval->l);
|
398
|
+
Real* n = real_round_origin(interval->n);
|
399
|
+
Real* u = real_round_origin(interval->u);
|
400
|
+
|
401
|
+
return interval_new(l, true, n, true, u);
|
396
402
|
}
|