Skip to content

Commit

Permalink
- Added the Complex.root(), Complex.polars() and Complex.reals() meth…
Browse files Browse the repository at this point in the history
…ods.
  • Loading branch information
trizen committed Nov 27, 2015
1 parent 36b2f3d commit 501b714
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 0 additions & 2 deletions lib/Sidef/Types/Glob/FileHandle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ package Sidef::Types::Glob::FileHandle {
Sidef::Types::Bool::Bool->new(CORE::syswrite $self->{fh}, @args);
}

*write_string = \&syswrite;

sub print {
my ($self, @args) = @_;
Sidef::Types::Bool::Bool->new(CORE::print {$self->{fh}} @args);
Expand Down
24 changes: 22 additions & 2 deletions lib/Sidef/Types/Number/Complex.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ package Sidef::Types::Number::Complex {

sub cartesian {
my ($self) = @_;
${$self}->display_format('cartesian');
$$self->display_format('cartesian');
$self;
}

sub polar {
my ($self) = @_;
${$self}->display_format('polar');
$$self->display_format('polar');
$self;
}

Expand All @@ -110,6 +110,18 @@ package Sidef::Types::Number::Complex {

*re = \ℜ

sub parts {
my ($self) = @_;
map { Sidef::Types::Number::Number->new($_) } @{$$self->_cartesian};
}

*reals = \&parts;

sub polars {
my ($self) = @_;
map { Sidef::Types::Number::Number->new($_) } @{$$self->_polar};
}

sub imaginary {
my ($self) = @_;
$self->new(Math::Complex::Im($$self));
Expand Down Expand Up @@ -250,6 +262,14 @@ package Sidef::Types::Number::Complex {
$self->new($$self**$arg->get_value);
}

sub root {
my ($self, $n, $k) = @_;
local $Sidef::Types::Number::Number::GET_PERL_VALUE = 1;
@_ == 2
? Sidef::Types::Array::Array->new(map { $self->new($_) } $$self->root($n->get_value))
: $self->new($$self->root($n->get_value, $k->get_value));
}

sub int {
my ($self) = @_;
$self->new(CORE::int($$self));
Expand Down

0 comments on commit 501b714

Please sign in to comment.