summaryrefslogtreecommitdiff
path: root/gmpxx.h
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2015-11-10 22:20:39 +0100
committerMarc Glisse <marc.glisse@inria.fr>2015-11-10 22:20:39 +0100
commitbd5a7c516b870f1014c849dfb20f883912eb37c4 (patch)
tree8ca7f7223a869f137d943c5546530c896092e758 /gmpxx.h
parent13cb286cdfd25d9d2a6ab2d49007b3fc560b2cd0 (diff)
downloadgmp-bd5a7c516b870f1014c849dfb20f883912eb37c4.tar.gz
Reject negative operands for primorial, after Marco's suggestion.
Diffstat (limited to 'gmpxx.h')
-rw-r--r--gmpxx.h12
1 files changed, 5 insertions, 7 deletions
diff --git a/gmpxx.h b/gmpxx.h
index fb0833491..e4b26dd2c 100644
--- a/gmpxx.h
+++ b/gmpxx.h
@@ -1222,19 +1222,17 @@ struct __gmp_primorial_function
static void eval(mpz_ptr z, signed long l)
{
if (l < 0)
- mpz_set_ui(z, 1);
- else
- eval(z, static_cast<unsigned long>(l));
+ throw std::domain_error ("primorial(negative)");
+ eval(z, static_cast<unsigned long>(l));
}
static void eval(mpz_ptr z, mpz_srcptr w)
{
if (!mpz_fits_ulong_p(w))
if (mpz_sgn(w) < 0)
- mpz_set_ui(z, 1);
+ throw std::domain_error ("primorial(negative)");
else
- throw std::bad_alloc(); // or std::overflow_error ("factorial")?
- else
- eval(z, mpz_get_ui(w));
+ throw std::bad_alloc(); // or std::overflow_error ("primorial")?
+ eval(z, mpz_get_ui(w));
}
static void eval(mpz_ptr z, double d)
{ __GMPXX_TMPZ_D; eval (z, temp); }