Skip to content

Commit a9f8822

Browse files
committed
Optimization: LAGOM is finite. Add test.
1 parent 89b489e commit a9f8822

File tree

5 files changed

+365
-82
lines changed

5 files changed

+365
-82
lines changed

arb/addmul.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ arb_addmul_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
2424
if (inexact)
2525
arf_mag_add_ulp(arb_radref(z), arb_radref(z), arb_midref(z), prec);
2626
}
27-
else if (arf_is_inf(y) && arb_is_nonzero(x))
28-
{
29-
if (arf_sgn(arb_midref(x)) > 0)
30-
arb_add_arf(z, z, y, prec);
31-
else
32-
arb_sub_arf(z, z, y, prec);
33-
}
3427
else if (ARB_IS_LAGOM(x) && ARF_IS_LAGOM(y) && ARB_IS_LAGOM(z))
3528
{
3629
mag_fast_init_set_arf(ym, y);
@@ -40,6 +33,13 @@ arb_addmul_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
4033
if (inexact)
4134
arf_mag_fast_add_ulp(arb_radref(z), arb_radref(z), arb_midref(z), prec);
4235
}
36+
else if (arf_is_inf(y) && arb_is_nonzero(x))
37+
{
38+
if (arf_sgn(arb_midref(x)) > 0)
39+
arb_add_arf(z, z, y, prec);
40+
else
41+
arb_sub_arf(z, z, y, prec);
42+
}
4343
else
4444
{
4545
mag_init_set_arf(ym, y);
@@ -67,20 +67,6 @@ arb_addmul(arb_t z, const arb_t x, const arb_t y, slong prec)
6767
{
6868
arb_addmul_arf(z, y, arb_midref(x), prec);
6969
}
70-
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y))
71-
{
72-
if (arf_sgn(arb_midref(y)) > 0)
73-
arb_add_arf(z, z, arb_midref(x), prec);
74-
else
75-
arb_sub_arf(z, z, arb_midref(x), prec);
76-
}
77-
else if (arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
78-
{
79-
if (arf_sgn(arb_midref(x)) > 0)
80-
arb_add_arf(z, z, arb_midref(y), prec);
81-
else
82-
arb_sub_arf(z, z, arb_midref(y), prec);
83-
}
8470
else if (ARB_IS_LAGOM(x) && ARB_IS_LAGOM(y) && ARB_IS_LAGOM(z))
8571
{
8672
mag_fast_init_set_arf(xm, arb_midref(x));
@@ -99,6 +85,20 @@ arb_addmul(arb_t z, const arb_t x, const arb_t y, slong prec)
9985

10086
*arb_radref(z) = *zr;
10187
}
88+
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y))
89+
{
90+
if (arf_sgn(arb_midref(y)) > 0)
91+
arb_add_arf(z, z, arb_midref(x), prec);
92+
else
93+
arb_sub_arf(z, z, arb_midref(x), prec);
94+
}
95+
else if (arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
96+
{
97+
if (arf_sgn(arb_midref(x)) > 0)
98+
arb_add_arf(z, z, arb_midref(y), prec);
99+
else
100+
arb_sub_arf(z, z, arb_midref(y), prec);
101+
}
102102
else
103103
{
104104
mag_init_set_arf(xm, arb_midref(x));

arb/fma.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ arb_fma_arf(arb_t res, const arb_t x, const arf_t y, const arb_t z, slong prec)
2626
else
2727
mag_set(arb_radref(res), arb_radref(z));
2828
}
29-
else if (arf_is_inf(y) && arb_is_nonzero(x))
30-
{
31-
if (arf_sgn(arb_midref(x)) > 0)
32-
arb_add_arf(res, z, y, prec);
33-
else
34-
arb_sub_arf(res, z, y, prec);
35-
}
3629
else if (ARB_IS_LAGOM(res) && ARB_IS_LAGOM(x) && ARF_IS_LAGOM(y) && ARB_IS_LAGOM(z))
3730
{
3831
mag_t tm;
@@ -46,6 +39,13 @@ arb_fma_arf(arb_t res, const arb_t x, const arf_t y, const arb_t z, slong prec)
4639
if (inexact)
4740
arf_mag_fast_add_ulp(arb_radref(res), arb_radref(res), arb_midref(res), prec);
4841
}
42+
else if (arf_is_inf(y) && arb_is_nonzero(x))
43+
{
44+
if (arf_sgn(arb_midref(x)) > 0)
45+
arb_add_arf(res, z, y, prec);
46+
else
47+
arb_sub_arf(res, z, y, prec);
48+
}
4949
else
5050
{
5151
mag_t tm;
@@ -80,20 +80,6 @@ arb_fma(arb_t res, const arb_t x, const arb_t y, const arb_t z, slong prec)
8080
{
8181
arb_fma_arf(res, y, arb_midref(x), z, prec);
8282
}
83-
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y))
84-
{
85-
if (arf_sgn(arb_midref(y)) > 0)
86-
arb_add_arf(res, z, arb_midref(x), prec);
87-
else
88-
arb_sub_arf(res, z, arb_midref(x), prec);
89-
}
90-
else if (arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
91-
{
92-
if (arf_sgn(arb_midref(x)) > 0)
93-
arb_add_arf(res, z, arb_midref(y), prec);
94-
else
95-
arb_sub_arf(res, z, arb_midref(y), prec);
96-
}
9783
else if (ARB_IS_LAGOM(res) && ARB_IS_LAGOM(x) && ARB_IS_LAGOM(y) && ARB_IS_LAGOM(z))
9884
{
9985
mag_fast_init_set_arf(xm, arb_midref(x));
@@ -112,6 +98,20 @@ arb_fma(arb_t res, const arb_t x, const arb_t y, const arb_t z, slong prec)
11298

11399
*arb_radref(res) = *zr;
114100
}
101+
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y))
102+
{
103+
if (arf_sgn(arb_midref(y)) > 0)
104+
arb_add_arf(res, z, arb_midref(x), prec);
105+
else
106+
arb_sub_arf(res, z, arb_midref(x), prec);
107+
}
108+
else if (arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
109+
{
110+
if (arf_sgn(arb_midref(x)) > 0)
111+
arb_add_arf(res, z, arb_midref(y), prec);
112+
else
113+
arb_sub_arf(res, z, arb_midref(y), prec);
114+
}
115115
else
116116
{
117117
mag_init_set_arf(xm, arb_midref(x));

arb/mul.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ arb_mul_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
2626
else
2727
mag_zero(arb_radref(z));
2828
}
29-
else if (arf_is_inf(y) && arb_is_nonzero(x))
30-
{
31-
mag_zero(arb_radref(z));
32-
33-
if (arf_sgn(arb_midref(x)) * arf_sgn(y) > 0)
34-
arf_pos_inf(arb_midref(z));
35-
else
36-
arf_neg_inf(arb_midref(z));
37-
}
3829
else if (ARB_IS_LAGOM(x) && ARF_IS_LAGOM(y) && ARB_IS_LAGOM(z))
3930
{
4031
mag_fast_init_set_arf(ym, y);
@@ -49,6 +40,15 @@ arb_mul_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
4940

5041
*arb_radref(z) = *zr;
5142
}
43+
else if (arf_is_inf(y) && arb_is_nonzero(x))
44+
{
45+
mag_zero(arb_radref(z));
46+
47+
if (arf_sgn(arb_midref(x)) * arf_sgn(y) > 0)
48+
arf_pos_inf(arb_midref(z));
49+
else
50+
arf_neg_inf(arb_midref(z));
51+
}
5252
else
5353
{
5454
mag_init_set_arf(ym, y);
@@ -83,16 +83,6 @@ arb_mul(arb_t z, const arb_t x, const arb_t y, slong prec)
8383
{
8484
arb_mul_arf(z, x, arb_midref(y), prec);
8585
}
86-
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y) ||
87-
arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
88-
{
89-
mag_zero(arb_radref(z));
90-
91-
if (arf_sgn(arb_midref(x)) * arf_sgn(arb_midref(y)) > 0)
92-
arf_pos_inf(arb_midref(z));
93-
else
94-
arf_neg_inf(arb_midref(z));
95-
}
9686
else if (ARB_IS_LAGOM(x) && ARB_IS_LAGOM(y) && ARB_IS_LAGOM(z))
9787
{
9888
mag_fast_init_set_arf(xm, arb_midref(x));
@@ -110,6 +100,16 @@ arb_mul(arb_t z, const arb_t x, const arb_t y, slong prec)
110100

111101
*arb_radref(z) = *zr;
112102
}
103+
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y) ||
104+
arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
105+
{
106+
mag_zero(arb_radref(z));
107+
108+
if (arf_sgn(arb_midref(x)) * arf_sgn(arb_midref(y)) > 0)
109+
arf_pos_inf(arb_midref(z));
110+
else
111+
arf_neg_inf(arb_midref(z));
112+
}
113113
else
114114
{
115115
mag_init_set_arf(xm, arb_midref(x));

arb/submul.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ arb_submul_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
2424
if (inexact)
2525
arf_mag_add_ulp(arb_radref(z), arb_radref(z), arb_midref(z), prec);
2626
}
27-
else if (arf_is_inf(y) && arb_is_nonzero(x))
28-
{
29-
if (arf_sgn(arb_midref(x)) > 0)
30-
arb_sub_arf(z, z, y, prec);
31-
else
32-
arb_add_arf(z, z, y, prec);
33-
}
3427
else if (ARB_IS_LAGOM(x) && ARF_IS_LAGOM(y) && ARB_IS_LAGOM(z))
3528
{
3629
mag_fast_init_set_arf(ym, y);
@@ -40,6 +33,13 @@ arb_submul_arf(arb_t z, const arb_t x, const arf_t y, slong prec)
4033
if (inexact)
4134
arf_mag_fast_add_ulp(arb_radref(z), arb_radref(z), arb_midref(z), prec);
4235
}
36+
else if (arf_is_inf(y) && arb_is_nonzero(x))
37+
{
38+
if (arf_sgn(arb_midref(x)) > 0)
39+
arb_sub_arf(z, z, y, prec);
40+
else
41+
arb_add_arf(z, z, y, prec);
42+
}
4343
else
4444
{
4545
mag_init_set_arf(ym, y);
@@ -67,20 +67,6 @@ arb_submul(arb_t z, const arb_t x, const arb_t y, slong prec)
6767
{
6868
arb_submul_arf(z, y, arb_midref(x), prec);
6969
}
70-
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y))
71-
{
72-
if (arf_sgn(arb_midref(y)) > 0)
73-
arb_sub_arf(z, z, arb_midref(x), prec);
74-
else
75-
arb_add_arf(z, z, arb_midref(x), prec);
76-
}
77-
else if (arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
78-
{
79-
if (arf_sgn(arb_midref(x)) > 0)
80-
arb_sub_arf(z, z, arb_midref(y), prec);
81-
else
82-
arb_add_arf(z, z, arb_midref(y), prec);
83-
}
8470
else if (ARB_IS_LAGOM(x) && ARB_IS_LAGOM(y) && ARB_IS_LAGOM(z))
8571
{
8672
mag_fast_init_set_arf(xm, arb_midref(x));
@@ -99,6 +85,20 @@ arb_submul(arb_t z, const arb_t x, const arb_t y, slong prec)
9985

10086
*arb_radref(z) = *zr;
10187
}
88+
else if (arf_is_inf(arb_midref(x)) && mag_is_finite(arb_radref(x)) && arb_is_nonzero(y))
89+
{
90+
if (arf_sgn(arb_midref(y)) > 0)
91+
arb_sub_arf(z, z, arb_midref(x), prec);
92+
else
93+
arb_add_arf(z, z, arb_midref(x), prec);
94+
}
95+
else if (arf_is_inf(arb_midref(y)) && mag_is_finite(arb_radref(y)) && arb_is_nonzero(x))
96+
{
97+
if (arf_sgn(arb_midref(x)) > 0)
98+
arb_sub_arf(z, z, arb_midref(y), prec);
99+
else
100+
arb_add_arf(z, z, arb_midref(y), prec);
101+
}
102102
else
103103
{
104104
mag_init_set_arf(xm, arb_midref(x));

0 commit comments

Comments
 (0)