Skip to content

Commit

Permalink
- Added the method Number.is_semiprime(), which tests if a number has…
Browse files Browse the repository at this point in the history
… exactly two prime factors.

- Math::Prime::Util::GMP >= 0.42 is required.
  • Loading branch information
trizen committed Mar 1, 2017
1 parent 94327a4 commit 3830f95
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Build.PL
Expand Up @@ -58,7 +58,7 @@ my $builder = Module::Build->new(
'Time::HiRes' => 0,
'Getopt::Std' => 0,
'Term::ReadLine' => 0,
'Math::Prime::Util::GMP' => 0.41,
'Math::Prime::Util::GMP' => 0.42,
},

recommends => {
Expand Down
1 change: 1 addition & 0 deletions lib/Sidef/Types/Number/Inf.pm
Expand Up @@ -67,6 +67,7 @@ package Sidef::Types::Number::Inf {
*is_nan = \&is_real;
*is_neg = \&is_real;
*is_prime = \&is_real;
*is_semiprime = \&is_real;
*is_prob_prime = \&is_real;
*is_prov_prime = \&is_real;
*is_mersenne_prime = \&is_real;
Expand Down
1 change: 1 addition & 0 deletions lib/Sidef/Types/Number/Nan.pm
Expand Up @@ -235,6 +235,7 @@ package Sidef::Types::Number::Nan {
*is_square = \&is_real;
*is_sqr = \&is_real;
*is_prime = \&is_real;
*is_semiprime = \&is_real;
*is_prob_prime = \&is_real;
*is_prov_prime = \&is_real;
*is_mersenne_prime = \&is_real;
Expand Down
8 changes: 8 additions & 0 deletions lib/Sidef/Types/Number/Number.pm
Expand Up @@ -3058,6 +3058,14 @@ package Sidef::Types::Number::Number {
_mpz2big($x);
}

sub is_semiprime {
my $x = ${$_[0]};
Math::GMPq::Rmpq_integer_p($x)
&& Math::Prime::Util::GMP::is_semiprime(Math::GMPq::Rmpq_get_str($x, 10))
? Sidef::Types::Bool::Bool::TRUE
: Sidef::Types::Bool::Bool::FALSE;
}

sub is_prime {
my $x = ${$_[0]};
Math::GMPq::Rmpq_integer_p($x)
Expand Down

0 comments on commit 3830f95

Please sign in to comment.