summaryrefslogtreecommitdiff
path: root/gmp-impl.h
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2000-02-18 01:01:28 +0100
committerKevin Ryde <user42@zip.com.au>2000-02-18 01:01:28 +0100
commit8e79733bf9a2bc56c605a41d9be791b8a1dadbb6 (patch)
tree0d5582c65a4061463bf842fda2f11554166c7ec1 /gmp-impl.h
parent527574c6a987d19eb5cacd1300943863e364b3f5 (diff)
downloadgmp-8e79733bf9a2bc56c605a41d9be791b8a1dadbb6.tar.gz
Add MPN_OVERLAP_P, assert_nocarry.
Diffstat (limited to 'gmp-impl.h')
-rw-r--r--gmp-impl.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/gmp-impl.h b/gmp-impl.h
index 91d1fe72c..65895c701 100644
--- a/gmp-impl.h
+++ b/gmp-impl.h
@@ -249,6 +249,31 @@ _MPN_COPY (d, s, n) mp_ptr d; mp_srcptr s; mp_size_t n;
#define KARATSUBA_SQR_THRESHOLD (2*KARATSUBA_MUL_THRESHOLD)
#endif
+/* Return non-zero if xp,xsize and yp,ysize overlap.
+ If xp+xsize<=yp there's no overlap, or if yp+ysize<=xp there's no
+ overlap. If both these are false, there's an overlap. */
+#define MPN_OVERLAP_P(xp, xsize, yp, ysize) \
+ ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp))
+
+/* assert_nocarry() uses assert() to check the given expression is zero.
+ If assertion checking is disabled, the expression is still evaluated.
+
+ The name of this macro is based on its typical use with routines like
+ mpn_add_n() where the return value represents a carry. Unless a carry is
+ expected and handled, a non-zero return would indicate an overflow and
+ should be guarded against. For example,
+
+ assert_nocarry (mpn_add_n (rp, s1p, s2p, size));
+
+ Obviously other routines can be checked in a similar way, eg. for a
+ borrow from mpn_sub_n(), remainder from mpn_divrem_1(), etc. */
+
+#ifdef NDEBUG
+#define assert_nocarry(expr) (expr)
+#else
+#define assert_nocarry(expr) assert ((expr) == 0)
+#endif
+
/* Structure for conversion between internal binary format and
strings in base 2..36. */
struct bases