summaryrefslogtreecommitdiff
path: root/mpq
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2018-04-26 23:37:52 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2018-04-26 23:37:52 +0200
commit50af3bf618a4a1e693b129779ed8cbe7c88dc430 (patch)
treea1501d13d45123d95f4f7f916a90792ee97b00c1 /mpq
parent252c79afb2e57270a9b1c590ebc5db311a147642 (diff)
downloadgmp-50af3bf618a4a1e693b129779ed8cbe7c88dc430.tar.gz
mpq/: Support lazy mpq_t also in the denominator.
Diffstat (limited to 'mpq')
-rw-r--r--mpq/clear.c3
-rw-r--r--mpq/clears.c3
-rw-r--r--mpq/div.c9
-rw-r--r--mpq/inp_str.c2
-rw-r--r--mpq/md_2exp.c2
-rw-r--r--mpq/mul.c2
-rw-r--r--mpq/set_d.c4
-rw-r--r--mpq/set_f.c4
-rw-r--r--mpq/set_si.c2
-rw-r--r--mpq/set_str.c2
-rw-r--r--mpq/set_ui.c2
-rw-r--r--mpq/set_z.c2
12 files changed, 18 insertions, 19 deletions
diff --git a/mpq/clear.c b/mpq/clear.c
index c5baa77f4..89c7933c6 100644
--- a/mpq/clear.c
+++ b/mpq/clear.c
@@ -35,5 +35,6 @@ mpq_clear (mpq_t x)
{
if (ALLOC (NUM(x)))
__GMP_FREE_FUNC_LIMBS (PTR(NUM(x)), ALLOC(NUM(x)));
- __GMP_FREE_FUNC_LIMBS (PTR(DEN(x)), ALLOC(DEN(x)));
+ if (ALLOC (DEN(x)))
+ __GMP_FREE_FUNC_LIMBS (PTR(DEN(x)), ALLOC(DEN(x)));
}
diff --git a/mpq/clears.c b/mpq/clears.c
index 1631067f6..ad1cf5e0e 100644
--- a/mpq/clears.c
+++ b/mpq/clears.c
@@ -42,7 +42,8 @@ mpq_clears (mpq_ptr x, ...)
{
if (ALLOC (NUM(x)))
__GMP_FREE_FUNC_LIMBS (PTR(NUM(x)), ALLOC(NUM(x)));
- __GMP_FREE_FUNC_LIMBS (PTR(DEN(x)), ALLOC(DEN(x)));
+ if (ALLOC (DEN(x)))
+ __GMP_FREE_FUNC_LIMBS (PTR(DEN(x)), ALLOC(DEN(x)));
x = va_arg (ap, mpq_ptr);
}
while (x != NULL);
diff --git a/mpq/div.c b/mpq/div.c
index c3a60a7e6..32d77b645 100644
--- a/mpq/div.c
+++ b/mpq/div.c
@@ -48,12 +48,9 @@ mpq_div (mpq_ptr quot, mpq_srcptr op1, mpq_srcptr op2)
if (UNLIKELY (quot == op2))
{
- if (op1 == op2)
+ if (UNLIKELY (op1 == op2))
{
- PTR(NUM(quot))[0] = 1;
- SIZ(NUM(quot)) = 1;
- PTR(DEN(quot))[0] = 1;
- SIZ(DEN(quot)) = 1;
+ mpq_set_ui (quot, 1, 1);
return;
}
@@ -82,7 +79,7 @@ mpq_div (mpq_ptr quot, mpq_srcptr op1, mpq_srcptr op2)
/* We special case this to simplify allocation logic; gcd(0,x) = x
is a singular case for the allocations. */
SIZ(NUM(quot)) = 0;
- PTR(DEN(quot))[0] = 1;
+ MPZ_NEWALLOC (DEN(quot), 1)[0] = 1;
SIZ(DEN(quot)) = 1;
return;
}
diff --git a/mpq/inp_str.c b/mpq/inp_str.c
index e2407eb9b..b1fbbc9e1 100644
--- a/mpq/inp_str.c
+++ b/mpq/inp_str.c
@@ -43,7 +43,7 @@ mpq_inp_str (mpq_ptr q, FILE *fp, int base)
fp = stdin;
SIZ(DEN(q)) = 1;
- PTR(DEN(q))[0] = 1;
+ MPZ_NEWALLOC (DEN(q), 1)[0] = 1;
nread = mpz_inp_str (mpq_numref(q), fp, base);
if (nread == 0)
diff --git a/mpq/md_2exp.c b/mpq/md_2exp.c
index 13623d83a..76f1f4436 100644
--- a/mpq/md_2exp.c
+++ b/mpq/md_2exp.c
@@ -102,7 +102,7 @@ mpq_div_2exp (mpq_ptr dst, mpq_srcptr src, mp_bitcnt_t n)
{
SIZ(NUM(dst)) = 0;
SIZ(DEN(dst)) = 1;
- PTR(DEN(dst))[0] = 1;
+ MPZ_NEWALLOC (DEN(dst), 1)[0] = 1;
return;
}
diff --git a/mpq/mul.c b/mpq/mul.c
index 3fcae2fc7..270dafc95 100644
--- a/mpq/mul.c
+++ b/mpq/mul.c
@@ -61,7 +61,7 @@ mpq_mul (mpq_ptr prod, mpq_srcptr op1, mpq_srcptr op2)
/* We special case this to simplify allocation logic; gcd(0,x) = x
is a singular case for the allocations. */
SIZ(NUM(prod)) = 0;
- PTR(DEN(prod))[0] = 1;
+ MPZ_NEWALLOC (DEN(prod), 1)[0] = 1;
SIZ(DEN(prod)) = 1;
return;
}
diff --git a/mpq/set_d.c b/mpq/set_d.c
index 3c02b876d..9d900d8d6 100644
--- a/mpq/set_d.c
+++ b/mpq/set_d.c
@@ -76,7 +76,7 @@ mpq_set_d (mpq_ptr dest, double d)
{
SIZ(NUM(dest)) = 0;
SIZ(DEN(dest)) = 1;
- PTR(DEN(dest))[0] = 1;
+ MPZ_NEWALLOC (DEN(dest), 1)[0] = 1;
return;
}
@@ -157,7 +157,7 @@ mpq_set_d (mpq_ptr dest, double d)
break;
#endif
}
- *PTR(DEN(dest)) = 1;
+ MPZ_NEWALLOC (DEN(dest), 1)[0] = 1;
SIZ(DEN(dest)) = 1;
}
SIZ(NUM(dest)) = negative ? -nn : nn;
diff --git a/mpq/set_f.c b/mpq/set_f.c
index a84d2d08b..14d4d0537 100644
--- a/mpq/set_f.c
+++ b/mpq/set_f.c
@@ -46,7 +46,7 @@ mpq_set_f (mpq_ptr q, mpf_srcptr f)
/* set q=0 */
SIZ(NUM(q)) = 0;
SIZ(DEN(q)) = 1;
- PTR(DEN(q))[0] = 1;
+ MPZ_NEWALLOC (DEN(q), 1)[0] = 1;
return;
}
@@ -65,7 +65,7 @@ mpq_set_f (mpq_ptr q, mpf_srcptr f)
SIZ(NUM(q)) = fsize >= 0 ? fexp : -fexp;
SIZ(DEN(q)) = 1;
- PTR(DEN(q))[0] = 1;
+ MPZ_NEWALLOC (DEN(q), 1)[0] = 1;
}
else
{
diff --git a/mpq/set_si.c b/mpq/set_si.c
index ea7e5c15b..0a4514463 100644
--- a/mpq/set_si.c
+++ b/mpq/set_si.c
@@ -59,6 +59,6 @@ mpq_set_si (mpq_t dest, signed long int num, unsigned long int den)
SIZ(NUM(dest)) = num > 0 ? 1 : -1;
}
- PTR(DEN(dest))[0] = den;
+ MPZ_NEWALLOC (DEN(dest), 1)[0] = den;
SIZ(DEN(dest)) = (den != 0);
}
diff --git a/mpq/set_str.c b/mpq/set_str.c
index 0e0e75299..a176c251e 100644
--- a/mpq/set_str.c
+++ b/mpq/set_str.c
@@ -49,7 +49,7 @@ mpq_set_str (mpq_ptr q, const char *str, int base)
if (slash == NULL)
{
SIZ(DEN(q)) = 1;
- PTR(DEN(q))[0] = 1;
+ MPZ_NEWALLOC (DEN(q), 1)[0] = 1;
return mpz_set_str (mpq_numref(q), str, base);
}
diff --git a/mpq/set_ui.c b/mpq/set_ui.c
index 32c23dcdf..d977fed84 100644
--- a/mpq/set_ui.c
+++ b/mpq/set_ui.c
@@ -55,6 +55,6 @@ mpq_set_ui (mpq_t dest, unsigned long int num, unsigned long int den)
SIZ(NUM(dest)) = 1;
}
- PTR(DEN(dest))[0] = den;
+ MPZ_NEWALLOC (DEN(dest), 1)[0] = den;
SIZ(DEN(dest)) = (den != 0);
}
diff --git a/mpq/set_z.c b/mpq/set_z.c
index af00056c1..e60174cdd 100644
--- a/mpq/set_z.c
+++ b/mpq/set_z.c
@@ -43,6 +43,6 @@ mpq_set_z (mpq_ptr dest, mpz_srcptr src)
dp = MPZ_NEWALLOC (NUM(dest), abs_num_size);
MPN_COPY (dp, PTR(src), abs_num_size);
- PTR(DEN(dest))[0] = 1;
+ MPZ_NEWALLOC (DEN(dest), 1)[0] = 1;
SIZ(DEN(dest)) = 1;
}