version 1.2, 2015/06/29 17:47:00
|
version 1.3, 2015/06/30 17:42:14
|
Line 50 use enum qw(NOT_AN_INTERVAL OPEN_OPEN OP
|
Line 50 use enum qw(NOT_AN_INTERVAL OPEN_OPEN OP
|
# @param {interval_type} - The interval type, NOT_AN_INTERVAL | OPEN_OPEN | OPEN_CLOSED | CLOSED_OPEN | CLOSED_CLOSED |
# @param {interval_type} - The interval type, NOT_AN_INTERVAL | OPEN_OPEN | OPEN_CLOSED | CLOSED_OPEN | CLOSED_CLOSED |
## |
## |
sub new { |
sub new { |
my $class = shift; |
my ($class, $type, $op, $value, $children, $interval_type) = @_; |
|
if (!defined $interval_type) { |
|
$interval_type = NOT_AN_INTERVAL; |
|
} |
my $self = { |
my $self = { |
_type => shift, |
_type => $type, |
_op => shift, |
_op => $op, |
_value => shift, |
_value => $value, |
_children => shift, |
_children => $children, |
_interval_type => shift // NOT_AN_INTERVAL, |
_interval_type => $interval_type, |
}; |
}; |
bless $self, $class; |
bless $self, $class; |
return $self; |
return $self; |
Line 307 sub calc {
|
Line 310 sub calc {
|
die CalcException->new("Missing parameter for function [_1].", $fname); |
die CalcException->new("Missing parameter for function [_1].", $fname); |
} |
} |
my ($q1, $q2); |
my ($q1, $q2); |
if ($fname ~~ ['pow', 'sqrt', 'abs', 'exp', 'ln', 'log', 'log10', 'factorial', |
if (string_in_array(['pow', 'sqrt', 'abs', 'exp', 'ln', 'log', 'log10', 'factorial', |
'mod', 'sgn', 'ceil', 'floor', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', |
'mod', 'sgn', 'ceil', 'floor', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', |
'atan2', 'sinh', 'cosh', 'tanh', 'asinh', 'acosh', 'atanh']) { |
'atan2', 'sinh', 'cosh', 'tanh', 'asinh', 'acosh', 'atanh'], $fname)) { |
$q1 = $children[1]->calc($env); |
$q1 = $children[1]->calc($env); |
if (!$q1->isa(Quantity)) { |
if (!$q1->isa(Quantity)) { |
die CalcException->new("The [_1] function is not implemented for this type.", $fname); |
die CalcException->new("The [_1] function is not implemented for this type.", $fname); |
} |
} |
} |
} |
if ($fname ~~ ['pow', 'mod', 'atan2']) { |
if (string_in_array(['pow', 'mod', 'atan2'], $fname)) { |
if (!defined $children[2]) { |
if (!defined $children[2]) { |
die CalcException->new("Missing parameter for function [_1].", $fname); |
die CalcException->new("Missing parameter for function [_1].", $fname); |
} |
} |
Line 634 sub toTeX {
|
Line 637 sub toTeX {
|
"Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", |
"Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", |
"Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega", |
"Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega", |
); |
); |
if ($name ~~ @greek) { |
if (string_in_array(\@greek, $name)) { |
return('\\'.$name); |
return('\\'.$name); |
} elsif ($name eq "hbar") { |
} elsif ($name eq "hbar") { |
return("\\hbar"); |
return("\\hbar"); |
Line 1002 sub createVectorOrMatrix {
|
Line 1005 sub createVectorOrMatrix {
|
} |
} |
} |
} |
|
|
|
## |
|
# Tests if a string is in an array (using eq) (to avoid using $value ~~ @array) |
|
# @param {Array<string>} array - reference to the array of strings |
|
# @param {string} value - the string to look for |
|
# @returns 1 if found, 0 otherwise |
|
## |
|
sub string_in_array { |
|
my ($array, $value) = @_; |
|
foreach my $v (@{$array}) { |
|
if ($v eq $value) { |
|
return 1; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |