summaryrefslogtreecommitdiff
path: root/mpz/root.c
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2000-04-13 07:55:52 +0200
committerKevin Ryde <user42@zip.com.au>2000-04-13 07:55:52 +0200
commit307863f67cd49c2fabc5ae53ddf687b03bc958e3 (patch)
treea44de2b95cc37728aa17a9b3dfbedde378a9f5e7 /mpz/root.c
parent423431b3d5f75cd8d0784aa2d4c8e7c263c97115 (diff)
downloadgmp-307863f67cd49c2fabc5ae53ddf687b03bc958e3.tar.gz
Add K&R function definitions.
Use SQRT_OF_NEGATIVE on even roots of negatives. Use DIVIDE_BY_ZERO on a "zero'th" root.
Diffstat (limited to 'mpz/root.c')
-rw-r--r--mpz/root.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/mpz/root.c b/mpz/root.c
index a25ac484b..62945af3f 100644
--- a/mpz/root.c
+++ b/mpz/root.c
@@ -31,7 +31,14 @@ MA 02111-1307, USA. */
#include "longlong.h"
int
+#if __STDC__
mpz_root (mpz_ptr r, mpz_srcptr c, unsigned long int nth)
+#else
+mpz_root (r, c, nth)
+ mpz_ptr r;
+ mpz_srcptr c;
+ unsigned long int nth;
+#endif
{
mpz_t x, t0, t1, t2;
__mpz_struct ccs, *cc = &ccs;
@@ -42,6 +49,15 @@ mpz_root (mpz_ptr r, mpz_srcptr c, unsigned long int nth)
unsigned long int lowz;
unsigned long int rl;
+ /* even roots of negatives provoke an exception */
+ if (mpz_sgn (c) < 0 && (nth & 1) == 0)
+ SQRT_OF_NEGATIVE;
+
+ /* root extraction interpreted as c^(1/nth) means a zeroth root should
+ provoke a divide by zero, do this even if c==0 */
+ if (nth == 0)
+ DIVIDE_BY_ZERO;
+
if (mpz_sgn (c) == 0)
{
if (r != NULL)