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/bounds.c
CHANGED
@@ -31,11 +31,8 @@ void bounds_free (Bounds* bounds)
|
|
31
31
|
|
32
32
|
void bounds_update_re (Bounds* bounds, mpfr_t num, int re_closed, int exact)
|
33
33
|
{
|
34
|
-
int min_cmp;
|
35
|
-
int max_cmp;
|
36
|
-
|
37
|
-
min_cmp = mpfr_cmp(bounds->re_min, num);
|
38
|
-
max_cmp = mpfr_cmp(bounds->re_max, num);
|
34
|
+
int min_cmp = mpfr_cmp(bounds->re_min, num);
|
35
|
+
int max_cmp = mpfr_cmp(bounds->re_max, num);
|
39
36
|
|
40
37
|
if (min_cmp != -1)
|
41
38
|
{
|
@@ -53,11 +50,8 @@ void bounds_update_re (Bounds* bounds, mpfr_t num, int re_closed, int exact)
|
|
53
50
|
|
54
51
|
void bounds_update_im (Bounds* bounds, mpfr_t num, int im_closed, int exact)
|
55
52
|
{
|
56
|
-
int min_cmp;
|
57
|
-
int max_cmp;
|
58
|
-
|
59
|
-
min_cmp = mpfr_cmp(bounds->im_min, num);
|
60
|
-
max_cmp = mpfr_cmp(bounds->im_max, num);
|
53
|
+
int min_cmp = mpfr_cmp(bounds->im_min, num);
|
54
|
+
int max_cmp = mpfr_cmp(bounds->im_max, num);
|
61
55
|
|
62
56
|
if (min_cmp != -1)
|
63
57
|
{
|
@@ -93,8 +87,7 @@ void bounds_update (Bounds* bounds, mpc_t num, int re_closed, int im_closed, int
|
|
93
87
|
|
94
88
|
Bounds* bounds_new ()
|
95
89
|
{
|
96
|
-
Bounds* bounds;
|
97
|
-
bounds = malloc(sizeof(Bounds));
|
90
|
+
Bounds* bounds = malloc(sizeof(Bounds));
|
98
91
|
|
99
92
|
if (bounds == NULL)
|
100
93
|
{
|
data/ext/number/complex.c
CHANGED
@@ -187,8 +187,7 @@ void complex_print (char* buf, Complex* complex)
|
|
187
187
|
*/
|
188
188
|
void complex_print_int (char* buf, Complex* complex)
|
189
189
|
{
|
190
|
-
Real* rounded;
|
191
|
-
rounded = real_round_origin(complex->re->n);
|
190
|
+
Real* rounded = real_round_origin(complex->re->n);
|
192
191
|
|
193
192
|
if (!REAL(rounded))
|
194
193
|
{
|
@@ -236,8 +235,7 @@ void complex_print_decimal (char* buf, Complex* complex)
|
|
236
235
|
*/
|
237
236
|
Complex* complex_new (Interval* re, Interval* im)
|
238
237
|
{
|
239
|
-
Complex* complex;
|
240
|
-
complex = malloc(sizeof(Complex));
|
238
|
+
Complex* complex = malloc(sizeof(Complex));
|
241
239
|
|
242
240
|
if (complex == NULL)
|
243
241
|
{
|
@@ -253,16 +251,12 @@ Complex* complex_new (Interval* re, Interval* im)
|
|
253
251
|
|
254
252
|
/*
|
255
253
|
* Returns a pointer to a newly allocated Complex with the given real as its
|
256
|
-
* real part and 0 as its imaginary part.
|
257
|
-
* being stored, and therefore must be freed separately.
|
254
|
+
* real part and 0 as its imaginary part.
|
258
255
|
*/
|
259
256
|
Complex* complex_from_real (Real* real)
|
260
257
|
{
|
261
|
-
Interval* re;
|
262
|
-
Interval* im;
|
263
|
-
|
264
|
-
re = interval_from_real(real);
|
265
|
-
im = interval_zero();
|
258
|
+
Interval* re = interval_from_real(real);
|
259
|
+
Interval* im = interval_zero();
|
266
260
|
|
267
261
|
return complex_new(re, im);
|
268
262
|
}
|
@@ -273,15 +267,8 @@ Complex* complex_from_real (Real* real)
|
|
273
267
|
*/
|
274
268
|
Complex* complex_from_int_str (char* buf)
|
275
269
|
{
|
276
|
-
Real* real;
|
277
|
-
|
278
|
-
|
279
|
-
real = real_from_str(buf, strlen(buf) - (*buf == '-'));
|
280
|
-
result = complex_from_real(real);
|
281
|
-
|
282
|
-
real_free(real);
|
283
|
-
|
284
|
-
return result;
|
270
|
+
Real* real = real_from_str(buf, strlen(buf) - (*buf == '-'));
|
271
|
+
return complex_from_real(real);
|
285
272
|
}
|
286
273
|
|
287
274
|
/*
|
@@ -290,17 +277,10 @@ Complex* complex_from_int_str (char* buf)
|
|
290
277
|
*/
|
291
278
|
Complex* complex_from_float_str (char* buf)
|
292
279
|
{
|
293
|
-
Real* real;
|
294
|
-
Complex* result;
|
295
|
-
|
296
280
|
mpfr_set_str(tmp_complex_from_float_str, buf, 10, MPFR_RNDN);
|
281
|
+
Real* real = real_from_mpfr(tmp_complex_from_float_str, ROUND_NEAREST);
|
297
282
|
|
298
|
-
|
299
|
-
result = complex_from_real(real);
|
300
|
-
|
301
|
-
real_free(real);
|
302
|
-
|
303
|
-
return result;
|
283
|
+
return complex_from_real(real);
|
304
284
|
}
|
305
285
|
|
306
286
|
/*
|
@@ -308,7 +288,10 @@ Complex* complex_from_float_str (char* buf)
|
|
308
288
|
*/
|
309
289
|
Complex* complex_nan ()
|
310
290
|
{
|
311
|
-
|
291
|
+
Interval* re = interval_nan();
|
292
|
+
Interval* im = interval_zero();
|
293
|
+
|
294
|
+
return complex_new(re, im);
|
312
295
|
}
|
313
296
|
|
314
297
|
/*
|
@@ -316,7 +299,10 @@ Complex* complex_nan ()
|
|
316
299
|
*/
|
317
300
|
Complex* complex_pos_inf ()
|
318
301
|
{
|
319
|
-
|
302
|
+
Interval* re = interval_pos_inf();
|
303
|
+
Interval* im = interval_zero();
|
304
|
+
|
305
|
+
return complex_new(re, im);
|
320
306
|
}
|
321
307
|
|
322
308
|
/*
|
@@ -324,7 +310,10 @@ Complex* complex_pos_inf ()
|
|
324
310
|
*/
|
325
311
|
Complex* complex_neg_inf ()
|
326
312
|
{
|
327
|
-
|
313
|
+
Interval* re = interval_neg_inf();
|
314
|
+
Interval* im = interval_zero();
|
315
|
+
|
316
|
+
return complex_new(re, im);
|
328
317
|
}
|
329
318
|
|
330
319
|
/*
|
@@ -332,7 +321,10 @@ Complex* complex_neg_inf ()
|
|
332
321
|
*/
|
333
322
|
Complex* complex_zero ()
|
334
323
|
{
|
335
|
-
|
324
|
+
Interval* re = interval_zero();
|
325
|
+
Interval* im = interval_zero();
|
326
|
+
|
327
|
+
return complex_new(re, im);
|
336
328
|
}
|
337
329
|
|
338
330
|
/*
|
@@ -340,7 +332,10 @@ Complex* complex_zero ()
|
|
340
332
|
*/
|
341
333
|
Complex* complex_one ()
|
342
334
|
{
|
343
|
-
|
335
|
+
Interval* re = interval_one();
|
336
|
+
Interval* im = interval_zero();
|
337
|
+
|
338
|
+
return complex_new(re, im);
|
344
339
|
}
|
345
340
|
|
346
341
|
/*
|
@@ -349,7 +344,10 @@ Complex* complex_one ()
|
|
349
344
|
*/
|
350
345
|
Complex* complex_pi ()
|
351
346
|
{
|
352
|
-
|
347
|
+
Interval* re = interval_pi();
|
348
|
+
Interval* im = interval_zero();
|
349
|
+
|
350
|
+
return complex_new(re, im);
|
353
351
|
}
|
354
352
|
|
355
353
|
/*
|
@@ -358,7 +356,10 @@ Complex* complex_pi ()
|
|
358
356
|
*/
|
359
357
|
Complex* complex_e ()
|
360
358
|
{
|
361
|
-
|
359
|
+
Interval* re = interval_e();
|
360
|
+
Interval* im = interval_zero();
|
361
|
+
|
362
|
+
return complex_new(re, im);
|
362
363
|
}
|
363
364
|
|
364
365
|
/*
|
@@ -366,7 +367,10 @@ Complex* complex_e ()
|
|
366
367
|
*/
|
367
368
|
Complex* complex_i ()
|
368
369
|
{
|
369
|
-
|
370
|
+
Interval* re = interval_zero();
|
371
|
+
Interval* im = interval_one();
|
372
|
+
|
373
|
+
return complex_new(re, im);
|
370
374
|
}
|
371
375
|
|
372
376
|
/*
|
@@ -375,7 +379,10 @@ Complex* complex_i ()
|
|
375
379
|
*/
|
376
380
|
Complex* complex_dup (Complex* complex)
|
377
381
|
{
|
378
|
-
|
382
|
+
Interval* re = interval_dup(complex->re);
|
383
|
+
Interval* im = interval_dup(complex->im);
|
384
|
+
|
385
|
+
return complex_new(re, im);
|
379
386
|
}
|
380
387
|
|
381
388
|
/*
|
@@ -383,11 +390,8 @@ Complex* complex_dup (Complex* complex)
|
|
383
390
|
*/
|
384
391
|
Complex* complex_add (Complex* a, Complex* b)
|
385
392
|
{
|
386
|
-
Interval* re;
|
387
|
-
Interval* im;
|
388
|
-
|
389
|
-
re = interval_add(a->re, b->re);
|
390
|
-
im = interval_add(a->im, b->im);
|
393
|
+
Interval* re = interval_add(a->re, b->re);
|
394
|
+
Interval* im = interval_add(a->im, b->im);
|
391
395
|
|
392
396
|
return complex_new(re, im);
|
393
397
|
}
|
@@ -397,11 +401,8 @@ Complex* complex_add (Complex* a, Complex* b)
|
|
397
401
|
*/
|
398
402
|
Complex* complex_subtract (Complex* a, Complex* b)
|
399
403
|
{
|
400
|
-
Interval* re;
|
401
|
-
Interval* im;
|
402
|
-
|
403
|
-
re = interval_subtract(a->re, b->re);
|
404
|
-
im = interval_subtract(a->im, b->im);
|
404
|
+
Interval* re = interval_subtract(a->re, b->re);
|
405
|
+
Interval* im = interval_subtract(a->im, b->im);
|
405
406
|
|
406
407
|
return complex_new(re, im);
|
407
408
|
}
|
@@ -411,20 +412,13 @@ Complex* complex_subtract (Complex* a, Complex* b)
|
|
411
412
|
*/
|
412
413
|
Complex* complex_multiply (Complex* a, Complex* b)
|
413
414
|
{
|
414
|
-
Interval* re_re;
|
415
|
-
Interval* re_im;
|
416
|
-
Interval* im_re;
|
417
|
-
Interval* im_im;
|
418
|
-
Interval* re;
|
419
|
-
Interval* im;
|
420
|
-
|
421
|
-
re_re = interval_multiply(a->re, b->re);
|
422
|
-
re_im = interval_multiply(a->re, b->im);
|
423
|
-
im_re = interval_multiply(a->im, b->re);
|
424
|
-
im_im = interval_multiply(a->im, b->im);
|
415
|
+
Interval* re_re = interval_multiply(a->re, b->re);
|
416
|
+
Interval* re_im = interval_multiply(a->re, b->im);
|
417
|
+
Interval* im_re = interval_multiply(a->im, b->re);
|
418
|
+
Interval* im_im = interval_multiply(a->im, b->im);
|
425
419
|
|
426
|
-
re = interval_subtract(re_re, im_im);
|
427
|
-
im = interval_add(re_im, im_re);
|
420
|
+
Interval* re = interval_subtract(re_re, im_im);
|
421
|
+
Interval* im = interval_add(re_im, im_re);
|
428
422
|
|
429
423
|
interval_free(re_re);
|
430
424
|
interval_free(re_im);
|
@@ -439,21 +433,12 @@ Complex* complex_multiply (Complex* a, Complex* b)
|
|
439
433
|
*/
|
440
434
|
Complex* complex_divide (Complex* a, Complex* b)
|
441
435
|
{
|
442
|
-
Interval* denominator_re;
|
443
|
-
Interval* denominator_im;
|
444
|
-
Interval* denominator;
|
445
|
-
Interval* numerator_re;
|
446
|
-
Interval* numerator_im;
|
447
|
-
Interval* re_re;
|
448
|
-
Interval* re_im;
|
449
|
-
Interval* im_re;
|
450
|
-
Interval* im_im;
|
451
436
|
Interval* re;
|
452
437
|
Interval* im;
|
453
438
|
|
454
|
-
denominator_re = interval_multiply(b->re, b->re);
|
455
|
-
denominator_im = interval_multiply(b->im, b->im);
|
456
|
-
denominator = interval_add(denominator_re, denominator_im);
|
439
|
+
Interval* denominator_re = interval_multiply(b->re, b->re);
|
440
|
+
Interval* denominator_im = interval_multiply(b->im, b->im);
|
441
|
+
Interval* denominator = interval_add(denominator_re, denominator_im);
|
457
442
|
|
458
443
|
if (real_zero_p(denominator->l) || real_zero_p(denominator->u) || interval_span_zero_p(denominator))
|
459
444
|
{
|
@@ -476,13 +461,13 @@ Complex* complex_divide (Complex* a, Complex* b)
|
|
476
461
|
}
|
477
462
|
else
|
478
463
|
{
|
479
|
-
re_re = interval_multiply(a->re, b->re);
|
480
|
-
re_im = interval_multiply(a->re, b->im);
|
481
|
-
im_re = interval_multiply(a->im, b->re);
|
482
|
-
im_im = interval_multiply(a->im, b->im);
|
464
|
+
Interval* re_re = interval_multiply(a->re, b->re);
|
465
|
+
Interval* re_im = interval_multiply(a->re, b->im);
|
466
|
+
Interval* im_re = interval_multiply(a->im, b->re);
|
467
|
+
Interval* im_im = interval_multiply(a->im, b->im);
|
483
468
|
|
484
|
-
numerator_re = interval_add(re_re, im_im);
|
485
|
-
numerator_im = interval_subtract(im_re, re_im);
|
469
|
+
Interval* numerator_re = interval_add(re_re, im_im);
|
470
|
+
Interval* numerator_im = interval_subtract(im_re, re_im);
|
486
471
|
|
487
472
|
re = interval_divide(numerator_re, denominator);
|
488
473
|
im = interval_divide(numerator_im, denominator);
|
@@ -507,11 +492,8 @@ Complex* complex_divide (Complex* a, Complex* b)
|
|
507
492
|
*/
|
508
493
|
Complex* complex_modulo (Complex* a, Complex* b)
|
509
494
|
{
|
510
|
-
Interval* re;
|
511
|
-
Interval* im;
|
512
|
-
|
513
|
-
re = interval_zero();
|
514
|
-
im = interval_zero();
|
495
|
+
Interval* re = interval_zero();
|
496
|
+
Interval* im = interval_zero();
|
515
497
|
|
516
498
|
return complex_new(re, im);
|
517
499
|
}
|
@@ -522,14 +504,8 @@ Complex* complex_modulo (Complex* a, Complex* b)
|
|
522
504
|
*/
|
523
505
|
Complex* complex_abs (Complex* complex)
|
524
506
|
{
|
525
|
-
int ll_mpc_ternary;
|
526
|
-
int lu_mpc_ternary;
|
527
|
-
int ul_mpc_ternary;
|
528
|
-
int uu_mpc_ternary;
|
529
507
|
Real* l_abs;
|
530
508
|
Real* u_abs;
|
531
|
-
Bounds* bounds;
|
532
|
-
Interval* re;
|
533
509
|
|
534
510
|
mpfr_set_prec(tmp_abs_n_re, PREC);
|
535
511
|
mpfr_set_prec(tmp_abs_ll_re, PREC);
|
@@ -553,12 +529,12 @@ Complex* complex_abs (Complex* complex)
|
|
553
529
|
mpc_set_r_r(tmp_abs_ul, complex->re->u, complex->im->l);
|
554
530
|
mpc_set_r_r(tmp_abs_uu, complex->re->u, complex->im->u);
|
555
531
|
|
556
|
-
ll_mpc_ternary = mpc_abs(tmp_abs_ll_re, tmp_abs_ll, MPC_RNDDD);
|
557
|
-
lu_mpc_ternary = mpc_abs(tmp_abs_lu_re, tmp_abs_lu, MPC_RNDDU);
|
558
|
-
ul_mpc_ternary = mpc_abs(tmp_abs_ul_re, tmp_abs_ul, MPC_RNDUD);
|
559
|
-
uu_mpc_ternary = mpc_abs(tmp_abs_uu_re, tmp_abs_uu, MPC_RNDUU);
|
532
|
+
int ll_mpc_ternary = mpc_abs(tmp_abs_ll_re, tmp_abs_ll, MPC_RNDDD);
|
533
|
+
int lu_mpc_ternary = mpc_abs(tmp_abs_lu_re, tmp_abs_lu, MPC_RNDDU);
|
534
|
+
int ul_mpc_ternary = mpc_abs(tmp_abs_ul_re, tmp_abs_ul, MPC_RNDUD);
|
535
|
+
int uu_mpc_ternary = mpc_abs(tmp_abs_uu_re, tmp_abs_uu, MPC_RNDUU);
|
560
536
|
|
561
|
-
bounds = bounds_new();
|
537
|
+
Bounds* bounds = bounds_new();
|
562
538
|
bounds_update_re(bounds, tmp_abs_ll_re, complex->re->L, MPC_INEX_RE(ll_mpc_ternary) == 0);
|
563
539
|
bounds_update_re(bounds, tmp_abs_lu_re, complex->re->L, MPC_INEX_RE(lu_mpc_ternary) == 0);
|
564
540
|
bounds_update_re(bounds, tmp_abs_ul_re, complex->re->R, MPC_INEX_RE(ul_mpc_ternary) == 0);
|
@@ -594,11 +570,12 @@ Complex* complex_abs (Complex* complex)
|
|
594
570
|
bounds_update_re(bounds, tmp_abs_zero, true, true);
|
595
571
|
}
|
596
572
|
|
597
|
-
re = interval_new(real_from_mpfr(bounds->re_min, ROUND_DOWN), bounds->re_min_closed, real_from_mpfr(tmp_abs_n_re, ROUND_NEAREST), bounds->re_max_closed, real_from_mpfr(bounds->re_max, bounds->re_max_exact ? ROUND_UP : ROUND_UP1));
|
573
|
+
Interval* re = interval_new(real_from_mpfr(bounds->re_min, ROUND_DOWN), bounds->re_min_closed, real_from_mpfr(tmp_abs_n_re, ROUND_NEAREST), bounds->re_max_closed, real_from_mpfr(bounds->re_max, bounds->re_max_exact ? ROUND_UP : ROUND_UP1));
|
574
|
+
Interval* im = interval_zero();
|
598
575
|
|
599
576
|
bounds_free(bounds);
|
600
577
|
|
601
|
-
return complex_new(re,
|
578
|
+
return complex_new(re, im);
|
602
579
|
}
|
603
580
|
|
604
581
|
/*
|
@@ -607,21 +584,14 @@ Complex* complex_abs (Complex* complex)
|
|
607
584
|
*/
|
608
585
|
Complex* complex_area (Complex* complex)
|
609
586
|
{
|
610
|
-
Real* re_width;
|
611
|
-
Real* im_width;
|
612
|
-
Real* area;
|
613
|
-
Complex* result;
|
614
|
-
|
615
|
-
re_width = real_subtract(complex->re->u, complex->re->l);
|
616
|
-
im_width = real_subtract(complex->im->u, complex->im->l);
|
617
|
-
area = real_multiply(re_width, im_width);
|
618
|
-
result = complex_from_real(area);
|
587
|
+
Real* re_width = real_subtract(complex->re->u, complex->re->l);
|
588
|
+
Real* im_width = real_subtract(complex->im->u, complex->im->l);
|
589
|
+
Real* area = real_multiply(re_width, im_width);
|
619
590
|
|
620
591
|
real_free(re_width);
|
621
592
|
real_free(im_width);
|
622
|
-
real_free(area);
|
623
593
|
|
624
|
-
return
|
594
|
+
return complex_from_real(area);
|
625
595
|
}
|
626
596
|
|
627
597
|
/*
|
@@ -630,26 +600,18 @@ Complex* complex_area (Complex* complex)
|
|
630
600
|
*/
|
631
601
|
Complex* complex_diagonal (Complex* complex)
|
632
602
|
{
|
633
|
-
|
634
|
-
Real*
|
635
|
-
Real* im_width;
|
636
|
-
Real* re_width2;
|
637
|
-
Real* im_width2;
|
638
|
-
Real* diag2;
|
639
|
-
Interval* re;
|
640
|
-
|
641
|
-
re_width = real_subtract(complex->re->u, complex->re->l);
|
642
|
-
im_width = real_subtract(complex->im->u, complex->im->l);
|
603
|
+
Real* re_width = real_subtract(complex->re->u, complex->re->l);
|
604
|
+
Real* im_width = real_subtract(complex->im->u, complex->im->l);
|
643
605
|
|
644
|
-
re_width2 = real_multiply(re_width, re_width);
|
645
|
-
im_width2 = real_multiply(im_width, im_width);
|
606
|
+
Real* re_width2 = real_multiply(re_width, re_width);
|
607
|
+
Real* im_width2 = real_multiply(im_width, im_width);
|
646
608
|
|
647
|
-
diag2 = real_add(re_width2, im_width2);
|
609
|
+
Real* diag2 = real_add(re_width2, im_width2);
|
648
610
|
|
649
611
|
mpfr_set_r(tmp_diagonal, diag2);
|
650
|
-
mpfr_ternary = mpfr_sqrt(tmp_diagonal, tmp_diagonal, MPFR_RNDN);
|
612
|
+
int mpfr_ternary = mpfr_sqrt(tmp_diagonal, tmp_diagonal, MPFR_RNDN);
|
651
613
|
|
652
|
-
re = interval_new(real_from_mpfr(tmp_diagonal, ROUND_DOWN), true, real_from_mpfr(tmp_diagonal, ROUND_NEAREST), true, real_from_mpfr(tmp_diagonal, (mpfr_ternary == 0) ? ROUND_UP : ROUND_UP1));
|
614
|
+
Interval* re = interval_new(real_from_mpfr(tmp_diagonal, ROUND_DOWN), true, real_from_mpfr(tmp_diagonal, ROUND_NEAREST), true, real_from_mpfr(tmp_diagonal, (mpfr_ternary == 0) ? ROUND_UP : ROUND_UP1));
|
653
615
|
|
654
616
|
real_free(re_width);
|
655
617
|
real_free(im_width);
|
@@ -666,7 +628,10 @@ Complex* complex_diagonal (Complex* complex)
|
|
666
628
|
*/
|
667
629
|
Complex* complex_conjugate (Complex* complex)
|
668
630
|
{
|
669
|
-
|
631
|
+
Interval* re = interval_dup(complex->re);
|
632
|
+
Interval* im = interval_negate(complex->im);
|
633
|
+
|
634
|
+
return complex_new(re, im);
|
670
635
|
}
|
671
636
|
|
672
637
|
/*
|
@@ -674,7 +639,10 @@ Complex* complex_conjugate (Complex* complex)
|
|
674
639
|
*/
|
675
640
|
Complex* complex_negate (Complex* complex)
|
676
641
|
{
|
677
|
-
|
642
|
+
Interval* re = interval_negate(complex->re);
|
643
|
+
Interval* im = interval_negate(complex->im);
|
644
|
+
|
645
|
+
return complex_new(re, im);
|
678
646
|
}
|
679
647
|
|
680
648
|
/*
|
@@ -683,7 +651,10 @@ Complex* complex_negate (Complex* complex)
|
|
683
651
|
*/
|
684
652
|
Complex* complex_reflect (Complex* complex)
|
685
653
|
{
|
686
|
-
|
654
|
+
Interval* re = interval_dup(complex->im);
|
655
|
+
Interval* im = interval_dup(complex->re);
|
656
|
+
|
657
|
+
return complex_new(re, im);
|
687
658
|
}
|
688
659
|
|
689
660
|
/*
|
@@ -691,15 +662,6 @@ Complex* complex_reflect (Complex* complex)
|
|
691
662
|
*/
|
692
663
|
Complex* complex_sqrt (Complex* complex)
|
693
664
|
{
|
694
|
-
int ll_mpc_ternary;
|
695
|
-
int lu_mpc_ternary;
|
696
|
-
int ul_mpc_ternary;
|
697
|
-
int uu_mpc_ternary;
|
698
|
-
int re_sqrt_mpc_ternary;
|
699
|
-
Bounds* bounds;
|
700
|
-
Interval* re;
|
701
|
-
Interval* im;
|
702
|
-
|
703
665
|
mpfr_set_prec(tmp_sqrt_n_re, PREC);
|
704
666
|
mpfr_set_prec(tmp_sqrt_n_im, PREC);
|
705
667
|
mpc_set_prec(tmp_sqrt_n, PREC);
|
@@ -719,12 +681,12 @@ Complex* complex_sqrt (Complex* complex)
|
|
719
681
|
mpc_set_r_r(tmp_sqrt_ul, complex->re->u, complex->im->l);
|
720
682
|
mpc_set_r_r(tmp_sqrt_uu, complex->re->u, complex->im->u);
|
721
683
|
|
722
|
-
ll_mpc_ternary = mpc_sqrt(tmp_sqrt_ll, tmp_sqrt_ll, MPC_RNDDD);
|
723
|
-
lu_mpc_ternary = mpc_sqrt(tmp_sqrt_lu, tmp_sqrt_lu, MPC_RNDDU);
|
724
|
-
ul_mpc_ternary = mpc_sqrt(tmp_sqrt_ul, tmp_sqrt_ul, MPC_RNDUD);
|
725
|
-
uu_mpc_ternary = mpc_sqrt(tmp_sqrt_uu, tmp_sqrt_uu, MPC_RNDUU);
|
684
|
+
int ll_mpc_ternary = mpc_sqrt(tmp_sqrt_ll, tmp_sqrt_ll, MPC_RNDDD);
|
685
|
+
int lu_mpc_ternary = mpc_sqrt(tmp_sqrt_lu, tmp_sqrt_lu, MPC_RNDDU);
|
686
|
+
int ul_mpc_ternary = mpc_sqrt(tmp_sqrt_ul, tmp_sqrt_ul, MPC_RNDUD);
|
687
|
+
int uu_mpc_ternary = mpc_sqrt(tmp_sqrt_uu, tmp_sqrt_uu, MPC_RNDUU);
|
726
688
|
|
727
|
-
bounds = bounds_new();
|
689
|
+
Bounds* bounds = bounds_new();
|
728
690
|
bounds_update(bounds, tmp_sqrt_ll, complex->re->L, complex->im->L, ll_mpc_ternary);
|
729
691
|
bounds_update(bounds, tmp_sqrt_lu, complex->re->L, complex->im->R, lu_mpc_ternary);
|
730
692
|
bounds_update(bounds, tmp_sqrt_ul, complex->re->R, complex->im->L, ul_mpc_ternary);
|
@@ -733,13 +695,13 @@ Complex* complex_sqrt (Complex* complex)
|
|
733
695
|
if (interval_span_zero_p(complex->im))
|
734
696
|
{
|
735
697
|
mpc_set_r_r(tmp_sqrt_re_sqrt, complex->re->l, 0);
|
736
|
-
re_sqrt_mpc_ternary = mpc_sqrt(tmp_sqrt_re_sqrt, tmp_sqrt_re_sqrt, MPC_RNDDD);
|
698
|
+
int re_sqrt_mpc_ternary = mpc_sqrt(tmp_sqrt_re_sqrt, tmp_sqrt_re_sqrt, MPC_RNDDD);
|
737
699
|
|
738
700
|
bounds_update(bounds, tmp_sqrt_re_sqrt, complex->re->L, true, re_sqrt_mpc_ternary);
|
739
701
|
}
|
740
702
|
|
741
|
-
re = interval_new(real_from_mpfr(bounds->re_min, ROUND_DOWN), bounds->re_min_closed, real_from_mpfr(tmp_sqrt_n_re, ROUND_NEAREST), bounds->re_max_closed, real_from_mpfr(bounds->re_max, bounds->re_max_exact ? ROUND_UP : ROUND_UP1));
|
742
|
-
im = interval_new(real_from_mpfr(bounds->im_min, ROUND_DOWN), bounds->im_min_closed, real_from_mpfr(tmp_sqrt_n_im, ROUND_NEAREST), bounds->im_max_closed, real_from_mpfr(bounds->im_max, bounds->im_max_exact ? ROUND_UP : ROUND_UP1));
|
703
|
+
Interval* re = interval_new(real_from_mpfr(bounds->re_min, ROUND_DOWN), bounds->re_min_closed, real_from_mpfr(tmp_sqrt_n_re, ROUND_NEAREST), bounds->re_max_closed, real_from_mpfr(bounds->re_max, bounds->re_max_exact ? ROUND_UP : ROUND_UP1));
|
704
|
+
Interval* im = interval_new(real_from_mpfr(bounds->im_min, ROUND_DOWN), bounds->im_min_closed, real_from_mpfr(tmp_sqrt_n_im, ROUND_NEAREST), bounds->im_max_closed, real_from_mpfr(bounds->im_max, bounds->im_max_exact ? ROUND_UP : ROUND_UP1));
|
743
705
|
|
744
706
|
bounds_free(bounds);
|
745
707
|
|