Skip to content

Commit

Permalink
- Added the Number pn_primes(n) method, which returns the first n p…
Browse files Browse the repository at this point in the history
…rimes.

Example:

	say pn_primes(25)	 # the first 25 primes
	say pn_primes(100, 110)  # the primes from 100-th prime to 110-th prime (inclusive)
  • Loading branch information
trizen committed Jul 14, 2019
1 parent 24e20ef commit a4815ce
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
45 changes: 28 additions & 17 deletions lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -786,20 +786,17 @@ package Sidef::Types::Number::Number {
my ($x) = @_;
goto(ref($x) =~ tr/:/_/rs);

Math_MPFR: {
push @_, $ROUND;
Math_GMPz: {

if (Math::MPFR::Rmpfr_integer_p($x)) {
if (Math::MPFR::Rmpfr_fits_slong_p($x, $ROUND)) {
goto &Math::MPFR::Rmpfr_get_si;
}
if (Math::GMPz::Rmpz_fits_slong_p($x)) {
goto &Math::GMPz::Rmpz_get_si;
}

if (Math::MPFR::Rmpfr_fits_ulong_p($x, $ROUND)) {
goto &Math::MPFR::Rmpfr_get_ui;
}
if (Math::GMPz::Rmpz_fits_ulong_p($x)) {
goto &Math::GMPz::Rmpz_get_ui;
}

goto &Math::MPFR::Rmpfr_get_d;
goto &Math::GMPz::Rmpz_get_d;
}

Math_GMPq: {
Expand All @@ -812,17 +809,20 @@ package Sidef::Types::Number::Number {
goto &Math::GMPq::Rmpq_get_d;
}

Math_GMPz: {
Math_MPFR: {
push @_, $ROUND;

if (Math::GMPz::Rmpz_fits_slong_p($x)) {
goto &Math::GMPz::Rmpz_get_si;
}
if (Math::MPFR::Rmpfr_integer_p($x)) {
if (Math::MPFR::Rmpfr_fits_slong_p($x, $ROUND)) {
goto &Math::MPFR::Rmpfr_get_si;
}

if (Math::GMPz::Rmpz_fits_ulong_p($x)) {
goto &Math::GMPz::Rmpz_get_ui;
if (Math::MPFR::Rmpfr_fits_ulong_p($x, $ROUND)) {
goto &Math::MPFR::Rmpfr_get_ui;
}
}

goto &Math::GMPz::Rmpz_get_d;
goto &Math::MPFR::Rmpfr_get_d;
}

Math_MPC: {
Expand Down Expand Up @@ -9322,6 +9322,17 @@ package Sidef::Types::Number::Number {
);
}

sub pn_primes {
my ($x, $y) = @_;

if (defined($y)) {
_valid(\$y);
return $x->nth_prime->primes($y->nth_prime);
}

$x->nth_prime->primes;
}

sub sum_primes {
my ($x, $y) = @_;

Expand Down
8 changes: 8 additions & 0 deletions lib/Sidef/Types/Number/Number.pod
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,14 @@ Return the

=cut

=head2 pn_primes

Number.pn_primes() -> I<Obj>

Return the

=cut

=head2 pn_primorial

Number.pn_primorial() -> I<Obj>
Expand Down

0 comments on commit a4815ce

Please sign in to comment.