summaryrefslogtreecommitdiff
path: root/gmp-impl.h
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2001-10-30 00:34:32 +0100
committerKevin Ryde <user42@zip.com.au>2001-10-30 00:34:32 +0100
commitec09179fd7b6c7b803510b81018e32f72f29e347 (patch)
treec3de2c11ba48ebbb5caedbc29e322ee5557f6235 /gmp-impl.h
parentf06d77d9cec222aef725e4c16a7ce675a8be2432 (diff)
downloadgmp-ec09179fd7b6c7b803510b81018e32f72f29e347.tar.gz
* gmp-impl.h (ASSERT_MPQ_CANONICAL): New macro.
Diffstat (limited to 'gmp-impl.h')
-rw-r--r--gmp-impl.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/gmp-impl.h b/gmp-impl.h
index 15c91665c..502c4d58d 100644
--- a/gmp-impl.h
+++ b/gmp-impl.h
@@ -1109,6 +1109,33 @@ void __gmp_assert_fail _PROTO ((const char *filename, int linenum,
#endif
+/* Test that an mpq_t is in fully canonical form. This can be used as
+ protection on routines like mpq_equal which give wrong results on
+ non-canonical inputs. */
+#if WANT_ASSERT
+#define ASSERT_MPQ_CANONICAL(q) \
+ do { \
+ ASSERT (q->_mp_den._mp_size > 0); \
+ if (q->_mp_num._mp_size == 0) \
+ { \
+ /* zero should be 0/1 */ \
+ ASSERT (mpz_cmp_ui (mpq_denref(q), 1L) == 0); \
+ } \
+ else \
+ { \
+ /* no common factors */ \
+ mpz_t __g; \
+ mpz_init (__g); \
+ mpz_gcd (__g, mpq_numref(q), mpq_denref(q)); \
+ ASSERT (mpz_cmp_ui (__g, 1) == 0); \
+ mpz_clear (__g); \
+ } \
+ } while (0)
+#else
+#define ASSERT_MPQ_CANONICAL(q) do {} while (0)
+#endif
+
+
/* Assert that an mpn region {ptr,size} is zero, or non-zero.
size==0 is allowed, and in that case {ptr,size} considered to be zero. */
#if WANT_ASSERT