Skip to content

Commit

Permalink
- Handle negative n in is_palindrome(n) and next_palindrome(n).
Browse files Browse the repository at this point in the history
Negative numbers are not considered palindromic, therefore `is_palindrome(n)` will always return false when n < 0.

Additionally, `next_palindrome(n)` will now return NaN when n < 0.
  • Loading branch information
trizen committed Jul 19, 2021
1 parent 10cad12 commit 1bab26c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18664,6 +18664,9 @@ package Sidef::Types::Number::Number {
$k = _any2mpz($$k) // return Sidef::Types::Bool::Bool::FALSE;
}

Math::GMPz::Rmpz_sgn($n) >= 0
or return Sidef::Types::Bool::Bool::FALSE;

# Optimization for bases <= 62
if (!defined($k) or Math::GMPz::Rmpz_cmp_ui($k, 62) <= 0) {

Expand Down Expand Up @@ -18700,6 +18703,9 @@ package Sidef::Types::Number::Number {

$n = _any2mpz($$n) // goto &nan;

Math::GMPz::Rmpz_sgn($n) >= 0
or goto &nan;

my @d;

if ($base <= 10) {
Expand Down

0 comments on commit 1bab26c

Please sign in to comment.