Diff for /loncom/homework/math_parser/ENode.pm between versions 1.1 and 1.4

version 1.1, 2015/06/29 15:42:13 version 1.4, 2017/01/19 19:24:57
Line 26  use strict; Line 26  use strict;
 use warnings;  use warnings;
 use utf8;  use utf8;
   
 use feature "switch"; # Perl 5.10.1  use Switch 'Perl6';
   
 use aliased 'Apache::math_parser::CalcException';  use aliased 'Apache::math_parser::CalcException';
 use aliased 'Apache::math_parser::Operator';  use aliased 'Apache::math_parser::Operator';
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 833  sub toTeX { Line 836  sub toTeX {
                         return "\\lim_{".$c2->toTeX()." \\to ".$c3->toTeX().                          return "\\lim_{".$c2->toTeX()." \\to ".$c3->toTeX().
                         "}".$c1->toTeX();                          "}".$c1->toTeX();
                     } else {                      } else {
                         return "\\lim_{".$c2->toTeX()." \\to ".$c3->toTeX().                          my $s = "\\lim_{".$c2->toTeX()." \\to ".$c3->toTeX();
                         (($c4->value eq "plus") ? "+" : "-").                          if ($c4->value eq "plus") {
                         "}".$c1->toTeX();                              $s .= "+";
                           } elsif ($c4->value eq "minus") {
                               $s .= "-";
                           }
                           $s .= "}".$c1->toTeX();
                           return $s;
                     }                      }
                 }                  }
                 when ("binomial") {                  when ("binomial") {
Line 1002  sub createVectorOrMatrix { Line 1010  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__

Removed from v.1.1  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>