[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Fri Jun 1 08:28:14 CEST 2012
details: /var/hg/gmp/rev/e2644b4af57d
changeset: 15031:e2644b4af57d
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Fri Jun 01 08:19:24 2012 +0200
description:
mpq: Use more macros and MPZ_REALLOC return value when possible.
details: /var/hg/gmp/rev/357486cfe1e7
changeset: 15032:357486cfe1e7
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Fri Jun 01 08:23:33 2012 +0200
description:
Macro LIMBS removed, always use PTR.
diffstat:
ChangeLog | 7 +++++++
gmp-impl.h | 1 -
mpq/abs.c | 12 ++++++------
mpq/get_den.c | 10 +++++-----
mpq/get_num.c | 11 ++++++-----
mpq/inv.c | 35 +++++++++++++++--------------------
mpq/md_2exp.c | 10 ++++------
mpq/neg.c | 19 ++++++++++---------
mpq/set.c | 13 +++++++------
mpq/set_d.c | 8 +++-----
mpq/set_den.c | 10 ++++++----
mpq/set_num.c | 9 +++++----
mpq/set_z.c | 7 ++++---
mpz/combit.c | 4 ++--
14 files changed, 80 insertions(+), 76 deletions(-)
diffs (truncated from 429 to 300 lines):
diff -r f773c0597bae -r 357486cfe1e7 ChangeLog
--- a/ChangeLog Thu May 31 23:31:48 2012 +0200
+++ b/ChangeLog Fri Jun 01 08:23:33 2012 +0200
@@ -1,3 +1,10 @@
+2012-06-01 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * mpq: Use more macros and MPZ_REALLOC return value when possible.
+
+ * gmp-impl.h (LIMBS): Removed, was an alias for PTR.
+ * mpz/combit.c: Use PTR and CNST_LIMB.
+
2012-05-31 Marc Glisse <marc.glisse at inria.fr>
* gmpxx.h (mpq_class::mpq_class): Handle mpq_class(0,1).
diff -r f773c0597bae -r 357486cfe1e7 gmp-impl.h
--- a/gmp-impl.h Thu May 31 23:31:48 2012 +0200
+++ b/gmp-impl.h Fri Jun 01 08:23:33 2012 +0200
@@ -517,7 +517,6 @@
#define SIZ(x) ((x)->_mp_size)
#define ABSIZ(x) ABS (SIZ (x))
#define PTR(x) ((x)->_mp_d)
-#define LIMBS(x) ((x)->_mp_d)
#define EXP(x) ((x)->_mp_exp)
#define PREC(x) ((x)->_mp_prec)
#define ALLOC(x) ((x)->_mp_alloc)
diff -r f773c0597bae -r 357486cfe1e7 mpq/abs.c
--- a/mpq/abs.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/abs.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,6 +1,6 @@
/* mpq_abs -- absolute value of a rational.
-Copyright 2000, 2001 Free Software Foundation, Inc.
+Copyright 2000, 2001, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -31,14 +31,14 @@
if (dst != src)
{
mp_size_t den_size = SIZ(DEN(src));
+ mp_ptr dp;
- MPZ_REALLOC (mpq_numref(dst), num_abs_size);
- MPZ_REALLOC (mpq_denref(dst), den_size);
+ dp = MPZ_REALLOC (NUM(dst), num_abs_size);
+ MPN_COPY (dp, PTR(NUM(src)), num_abs_size);
- MPN_COPY (PTR(NUM(dst)), PTR(NUM(src)), num_abs_size);
- MPN_COPY (PTR(DEN(dst)), PTR(DEN(src)), den_size);
-
+ dp = MPZ_REALLOC (DEN(dst), den_size);
SIZ(DEN(dst)) = den_size;
+ MPN_COPY (dp, PTR(DEN(src)), den_size);
}
SIZ(NUM(dst)) = num_abs_size;
diff -r f773c0597bae -r 357486cfe1e7 mpq/get_den.c
--- a/mpq/get_den.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/get_den.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,6 +1,6 @@
/* mpq_get_den(den,rat_src) -- Set DEN to the denominator of RAT_SRC.
-Copyright 1991, 1994, 1995, 2001 Free Software Foundation, Inc.
+Copyright 1991, 1994, 1995, 2001, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -21,12 +21,12 @@
#include "gmp-impl.h"
void
-mpq_get_den (MP_INT *den, const MP_RAT *src)
+mpq_get_den (mpz_ptr den, mpq_srcptr src)
{
mp_size_t size = SIZ(DEN(src));
+ mp_ptr dp;
- MPZ_REALLOC (den, size);
-
- MPN_COPY (PTR(den), PTR(DEN(src)), size);
+ dp = MPZ_REALLOC (den, size);
SIZ(den) = size;
+ MPN_COPY (dp, PTR(DEN(src)), size);
}
diff -r f773c0597bae -r 357486cfe1e7 mpq/get_num.c
--- a/mpq/get_num.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/get_num.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,6 +1,6 @@
/* mpq_get_num(num,rat_src) -- Set NUM to the numerator of RAT_SRC.
-Copyright 1991, 1994, 1995, 2001 Free Software Foundation, Inc.
+Copyright 1991, 1994, 1995, 2001, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -21,13 +21,14 @@
#include "gmp-impl.h"
void
-mpq_get_num (MP_INT *num, const MP_RAT *src)
+mpq_get_num (mpz_ptr num, mpq_srcptr src)
{
mp_size_t size = SIZ(NUM(src));
mp_size_t abs_size = ABS (size);
+ mp_ptr dp;
- MPZ_REALLOC (num, abs_size);
+ dp = MPZ_REALLOC (num, abs_size);
+ SIZ(num) = size;
- MPN_COPY (PTR(num), PTR(NUM(src)), abs_size);
- SIZ(num) = size;
+ MPN_COPY (dp, PTR(NUM(src)), abs_size);
}
diff -r f773c0597bae -r 357486cfe1e7 mpq/inv.c
--- a/mpq/inv.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/inv.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,7 +1,7 @@
/* mpq_inv(dest,src) -- invert a rational number, i.e. set DEST to SRC
with the numerator and denominator swapped.
-Copyright 1991, 1994, 1995, 2000, 2001 Free Software Foundation, Inc.
+Copyright 1991, 1994, 1995, 2000, 2001, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -22,44 +22,39 @@
#include "gmp-impl.h"
void
-mpq_inv (MP_RAT *dest, const MP_RAT *src)
+mpq_inv (mpq_ptr dest, mpq_srcptr src)
{
mp_size_t num_size = SIZ(NUM(src));
mp_size_t den_size = SIZ(DEN(src));
- if (UNLIKELY (num_size == 0))
- DIVIDE_BY_ZERO;
-
if (num_size < 0)
{
num_size = -num_size;
den_size = -den_size;
}
+ else if (UNLIKELY (num_size == 0))
+ DIVIDE_BY_ZERO;
+
SIZ(DEN(dest)) = num_size;
SIZ(NUM(dest)) = den_size;
- /* If dest == src we may just swap the numerator and denominator, but
- we have to ensure the new denominator is positive. */
+ /* If dest == src we may just swap the numerator and denominator;
+ we ensured that the new denominator is positive. */
if (dest == src)
{
- mp_size_t alloc = ALLOC(NUM(dest));
- mp_ptr limb_ptr = PTR(NUM(dest));
-
- ALLOC(NUM(dest)) = ALLOC(DEN(dest));
- PTR(NUM(dest)) = PTR(DEN(dest));
-
- ALLOC(DEN(dest)) = alloc;
- PTR(DEN(dest)) = limb_ptr;
+ MP_PTR_SWAP (PTR(NUM(dest)), PTR(DEN(dest)));
+ MP_SIZE_T_SWAP (ALLOC(NUM(dest)), ALLOC(DEN(dest)));
}
else
{
+ mp_ptr dp;
+
den_size = ABS (den_size);
+ dp = MPZ_REALLOC (NUM(dest), den_size);
+ MPN_COPY (dp, PTR(DEN(src)), den_size);
- MPZ_REALLOC (NUM(dest), den_size);
- MPZ_REALLOC (DEN(dest), num_size);
-
- MPN_COPY (PTR(NUM(dest)), PTR(DEN(src)), den_size);
- MPN_COPY (PTR(DEN(dest)), PTR(NUM(src)), num_size);
+ dp = MPZ_REALLOC (DEN(dest), num_size);
+ MPN_COPY (dp, PTR(NUM(src)), num_size);
}
}
diff -r f773c0597bae -r 357486cfe1e7 mpq/md_2exp.c
--- a/mpq/md_2exp.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/md_2exp.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,7 +1,7 @@
/* mpq_mul_2exp, mpq_div_2exp - multiply or divide by 2^N */
/*
-Copyright 2000, 2002 Free Software Foundation, Inc.
+Copyright 2000, 2002, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -82,14 +82,13 @@
void
mpq_mul_2exp (mpq_ptr dst, mpq_srcptr src, mp_bitcnt_t n)
{
- mord_2exp (mpq_numref (dst), mpq_denref (dst),
- mpq_numref (src), mpq_denref (src), n);
+ mord_2exp (NUM(dst), DEN(dst), NUM(src), DEN(src), n);
}
void
mpq_div_2exp (mpq_ptr dst, mpq_srcptr src, mp_bitcnt_t n)
{
- if (SIZ (mpq_numref(src)) == 0)
+ if (SIZ(NUM(src)) == 0)
{
SIZ(NUM(dst)) = 0;
SIZ(DEN(dst)) = 1;
@@ -97,6 +96,5 @@
return;
}
- mord_2exp (mpq_denref (dst), mpq_numref (dst),
- mpq_denref (src), mpq_numref (src), n);
+ mord_2exp (DEN(dst), NUM(dst), DEN(src), NUM(src), n);
}
diff -r f773c0597bae -r 357486cfe1e7 mpq/neg.c
--- a/mpq/neg.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/neg.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,6 +1,6 @@
/* mpq_neg -- negate a rational.
-Copyright 2000, 2001 Free Software Foundation, Inc.
+Copyright 2000, 2001, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -30,16 +30,17 @@
if (src != dst)
{
- mp_size_t num_abs_size = ABS(num_size);
- mp_size_t den_size = SIZ(DEN(src));
+ mp_size_t size;
+ mp_ptr dp;
- MPZ_REALLOC (mpq_numref(dst), num_abs_size);
- MPZ_REALLOC (mpq_denref(dst), den_size);
+ size = ABS(num_size);
+ dp = MPZ_REALLOC (NUM(dst), size);
+ MPN_COPY (dp, PTR(NUM(src)), size);
- MPN_COPY (PTR(NUM(dst)), PTR(NUM(src)), num_abs_size);
- MPN_COPY (PTR(DEN(dst)), PTR(DEN(src)), den_size);
-
- SIZ(DEN(dst)) = den_size;
+ size = SIZ(DEN(src));
+ dp = MPZ_REALLOC (DEN(dst), size);
+ SIZ(DEN(dst)) = size;
+ MPN_COPY (dp, PTR(DEN(src)), size);
}
SIZ(NUM(dst)) = -num_size;
diff -r f773c0597bae -r 357486cfe1e7 mpq/set.c
--- a/mpq/set.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/set.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,6 +1,6 @@
/* mpq_set(dest,src) -- Set DEST to SRC.
-Copyright 1991, 1994, 1995, 2001 Free Software Foundation, Inc.
+Copyright 1991, 1994, 1995, 2001, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -21,19 +21,20 @@
#include "gmp-impl.h"
void
-mpq_set (MP_RAT *dest, const MP_RAT *src)
+mpq_set (mpq_ptr dest, mpq_srcptr src)
{
mp_size_t num_size, den_size;
mp_size_t abs_num_size;
+ mp_ptr dp;
num_size = SIZ(NUM(src));
abs_num_size = ABS (num_size);
- MPZ_REALLOC (NUM(dest), abs_num_size);
- MPN_COPY (PTR(NUM(dest)), PTR(NUM(src)), abs_num_size);
+ dp = MPZ_REALLOC (NUM(dest), abs_num_size);
SIZ(NUM(dest)) = num_size;
+ MPN_COPY (dp, PTR(NUM(src)), abs_num_size);
den_size = SIZ(DEN(src));
- MPZ_REALLOC (DEN(dest), den_size);
- MPN_COPY (PTR(DEN(dest)), PTR(DEN(src)), den_size);
+ dp = MPZ_REALLOC (DEN(dest), den_size);
SIZ(DEN(dest)) = den_size;
+ MPN_COPY (dp, PTR(DEN(src)), den_size);
}
diff -r f773c0597bae -r 357486cfe1e7 mpq/set_d.c
--- a/mpq/set_d.c Thu May 31 23:31:48 2012 +0200
+++ b/mpq/set_d.c Fri Jun 01 08:23:33 2012 +0200
@@ -1,6 +1,6 @@
More information about the gmp-commit
mailing list