summaryrefslogtreecommitdiff
path: root/src/Persistent_cohomology/include
diff options
context:
space:
mode:
authorHind-M <hind.montassif@gmail.com>2021-07-12 11:25:57 +0200
committerHind-M <hind.montassif@gmail.com>2021-07-12 11:25:57 +0200
commitaa1a040f6338ec938b9360de35196ad0518be502 (patch)
treeaa4028509ed3263af7f7997dafce2782ef2e0483 /src/Persistent_cohomology/include
parent62b63fd55442b152b934dc0c9ed662970ddb32dc (diff)
Limit homology_coeff_field value to max allowed
Add test with first prime outside the allowed range
Diffstat (limited to 'src/Persistent_cohomology/include')
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
index 4bfd95c0..7ecc9a80 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h
@@ -14,7 +14,6 @@
#include <utility>
#include <vector>
#include <stdexcept>
-#include <cmath>
namespace Gudhi {
@@ -39,6 +38,10 @@ class Field_Zp {
Prime = charac;
+ // Check that the provided prime is less than the maximum allowed as int and calculation below : 46337 ; i.e (max_prime-1)**2 <= INT_MAX
+ if(Prime > 46337)
+ throw std::invalid_argument("Maximum homology_coeff_field allowed value is 46337");
+
// Check for primality
if ((Prime == 0) || (Prime == 1) || ((Prime > 3) && ((Prime % 2 == 0) || (Prime % 3 == 0))))
throw std::invalid_argument("homology_coeff_field must be a prime number");
@@ -56,7 +59,7 @@ class Field_Zp {
mult = inv * i;
}
inverse_.push_back(inv);
- if ( (i <= std::sqrt(Prime)) && (((i-5)%6) == 0) ) {
+ if ( (i*i <= Prime) && (((i-5)%6) == 0) ) {
if ((Prime % i == 0) || (Prime % (i + 2) == 0))
throw std::invalid_argument("homology_coeff_field must be a prime number");
}