Skip to content

Commit

Permalink
- Redefined Inf**0 to return 1 instead of NaN
Browse files Browse the repository at this point in the history
Example:
	say 0.root(0).pow(0);       # => 1
	say ((0**(1/0))**0);        # => 1

This is consistent with 0**0

- Other minor fixes.
  • Loading branch information
trizen committed Dec 27, 2015
1 parent 788b2d1 commit b9fc23f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/Sidef/Types/Number/Complex.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ package Sidef::Types::Number::Complex {
$re eq '0' ? $sign eq '+' ? "${im}i" : "$sign${im}i" : "$re$sign${im}i";
}

sub reals {
($_[0]->re, $_[0]->im);
}

*parts = \ℝ

sub dump {
my $re = $_[0]->re;
my $im = $_[0]->im;
Expand Down
3 changes: 2 additions & 1 deletion lib/Sidef/Types/Number/Inf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ package Sidef::Types::Number::Inf {
*bin = \&nan;
*modpow = \&nan;
*modinv = \&nan;
*invmod = \&nan;
*and = \&nan;
*or = \&nan;
*xor = \&nan;
Expand Down Expand Up @@ -246,7 +247,7 @@ package Sidef::Types::Number::Inf {

sub pow {
my ($x, $y) = @_;
$y->is_neg ? $ZERO : $y->is_zero ? nan() : $x;
$y->is_neg ? $ZERO : $y->is_zero ? $ONE : $x;
}

#
Expand Down
3 changes: 2 additions & 1 deletion lib/Sidef/Types/Number/Ninf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ package Sidef::Types::Number::Ninf {
*bin = \&nan;
*modpow = \&nan;
*modinv = \&nan;
*invmod = \&nan;
*and = \&nan;
*or = \&nan;
*xor = \&nan;
Expand Down Expand Up @@ -246,7 +247,7 @@ package Sidef::Types::Number::Ninf {
#
sub pow {
my ($x, $y) = @_;
$y->is_neg ? $ZERO : $y->is_zero ? nan() : $y->is_even ? $x->neg : $x;
$y->is_neg ? $ZERO : $y->is_zero ? $ONE : $y->is_even ? $x->neg : $x;
}

#
Expand Down
5 changes: 5 additions & 0 deletions lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ package Sidef::Types::Number::Number {
}

_valid($y);

return $ZERO if Math::GMPq::Rmpq_sgn($$y) == 0;

my $r = Math::MPFR::Rmpfr_init2($PREC);
Math::MPFR::Rmpfr_root($r, _as_float($x), CORE::int(Math::GMPq::Rmpq_get_d($$y)), $ROUND);
_new(_mpfr2rat($r));
Expand Down Expand Up @@ -1123,6 +1126,8 @@ package Sidef::Types::Number::Number {
_new(_mpz2rat($r));
}

*invmod = \&modinv;

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

Expand Down

0 comments on commit b9fc23f

Please sign in to comment.