Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checks for scalar multiplication to not have to stringify the val… #330

Merged
merged 1 commit into from
Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/Value/Matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ sub mult {
#
# Constant multiplication
#
if (Value::matchNumber($r) || Value::isComplex($r)) {
if (Value::isNumber($r)) {
my @coords = ();
foreach my $x (@{$l->data}) {push(@coords,$x*$r)}
return $self->make(@coords);
Expand Down Expand Up @@ -247,8 +247,7 @@ sub mult {
sub div {
my ($l,$r,$flag) = @_; my $self = $l;
Value::Error("Can't divide by a Matrix") if $flag;
Value::Error("Matrices can only be divided by Numbers")
unless (Value::matchNumber($r) || Value::isComplex($r));
Value::Error("Matrices can only be divided by Numbers") unless Value::isNumber($r);
Value::Error("Division by zero") if $r == 0;
my @coords = ();
foreach my $x (@{$l->data}) {push(@coords,$x/$r)}
Expand Down
6 changes: 2 additions & 4 deletions lib/Value/Point.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ sub sub {

sub mult {
my ($l,$r) = @_; my $self = $l;
Value::Error("Points can only be multiplied by Numbers")
unless (Value::matchNumber($r) || Value::isComplex($r));
Value::Error("Points can only be multiplied by Numbers") unless Value::isNumber($r);
my @coords = ();
foreach my $x ($l->value) {push(@coords,$x*$r)}
return $self->make(@coords);
Expand All @@ -91,8 +90,7 @@ sub mult {
sub div {
my ($l,$r,$flag) = @_; my $self = $l;
Value::Error("Can't divide by a Point") if $flag;
Value::Error("Points can only be divided by Numbers")
unless (Value::matchNumber($r) || Value::isComplex($r));
Value::Error("Points can only be divided by Numbers") unless Value::isNumber($r);
Value::Error("Division by zero") if $r == 0;
my @coords = ();
foreach my $x ($l->value) {push(@coords,$x/$r)}
Expand Down
6 changes: 2 additions & 4 deletions lib/Value/Vector.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ sub sub {

sub mult {
my ($l,$r,$flag) = @_; my $self = $l;
Value::Error("Vectors can only be multiplied by Numbers")
unless (Value::matchNumber($r) || Value::isComplex($r));
Value::Error("Vectors can only be multiplied by Numbers") unless Value::isNumber($r);
my @coords = ();
foreach my $x ($l->value) {push(@coords,$x*$r)}
return $self->make(@coords);
Expand All @@ -102,8 +101,7 @@ sub mult {
sub div {
my ($l,$r,$flag) = @_; my $self = $l;
Value::Error("Can't divide by a Vector") if $flag;
Value::Error("Vectors can only be divided by Numbers")
unless (Value::matchNumber($r) || Value::isComplex($r));
Value::Error("Vectors can only be divided by Numbers") unless Value::isNumber($r);
Value::Error("Division by zero") if $r == 0;
my @coords = ();
foreach my $x ($l->value) {push(@coords,$x/$r)}
Expand Down