[system] / trunk / pg / macros / PGcommonFunctions.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/PGcommonFunctions.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3333 - (download) (as text) (annotate)
Sun Jul 3 20:06:33 2005 UTC (14 years, 7 months ago) by dpvc
File size: 4266 byte(s)
Adjusted some spacing

    1 ##############################################
    2 #
    3 #  Implements functions that are common to
    4 #  the new Parser.pm and the old PGauxiliaryFunctions.pl
    5 #
    6 
    7 sub _PGcommonFunctions_init {}
    8 
    9 #
   10 #  Make these interact nicely with Parser.pm
   11 #
   12 package CommonFunction;
   13 
   14 #
   15 #  Either call Parser (if it has been loaded) or
   16 #  the functions below.  (If it's ever the case
   17 #  that both the Parser and PGauxiliaryFunctions.pl are
   18 #  both preloaded, then there will be no need for
   19 #  this, as you can always use the Parser versions.
   20 #  We only need this because Parser might not be loaded.)
   21 #
   22 
   23 sub Call {
   24   my $self = shift;
   25   my $fn = shift;
   26   if ($main::_parser_loaded) {
   27     return Parser::Function->call($fn,@_)
   28       if Parser::Context->current->{functions}{$fn};
   29   }
   30   return $self->$fn(@_);
   31 }
   32 
   33 sub log {CORE::log($_[1])}
   34 sub ln {CORE::log($_[1])}
   35 sub logten {CORE::log($_[1])/CORE::log(10)}
   36 
   37 sub tan {CORE::sin($_[1])/CORE::cos($_[1])}
   38 sub cot {CORE::cos($_[1])/CORE::sin($_[1])}
   39 sub sec {1/CORE::cos($_[1])}
   40 sub csc {1/CORE::sin($_[1])}
   41 
   42 sub asin {CORE::atan2($_[1],CORE::sqrt(1-$_[1]*$_[1]))}
   43 sub acos {CORE::atan2(CORE::sqrt(1-$_[1]*$_[1]),$_[1])}
   44 sub atan {CORE::atan2($_[1],1)}
   45 sub acot {CORE::atan2(1,$_[1])}
   46 sub asec {acos($_[0],1.0/$_[1])}
   47 sub acsc {asin($_[0],1.0/$_[1])}
   48 
   49 sub sinh {(CORE::exp($_[1])-CORE::exp(-$_[1]))/2}
   50 sub cosh {(CORE::CORE::exp($_[1])+CORE::CORE::exp(-$_[1]))/2}
   51 sub tanh {(CORE::exp($_[1])-CORE::exp(-$_[1]))/(CORE::exp($_[1])+CORE::exp(-$_[1]))}
   52 sub sech {2/(CORE::exp($_[1])+CORE::exp(-$_[1]))}
   53 sub csch {2.0/(CORE::exp($_[1])-CORE::exp(-$_[1]))}
   54 sub coth {(CORE::exp($_[1])+CORE::exp(-$_[1]))/(CORE::exp($_[1])-CORE::exp(-$_[1]))}
   55 
   56 sub asinh {CORE::log($_[1]+CORE::sqrt($_[1]*$_[1]+1.0))}
   57 sub acosh {CORE::log($_[1]+CORE::sqrt($_[1]*$_[1]-1.0))}
   58 sub atanh {CORE::log((1.0+$_[1])/(1.0-$_[1]))/2.0}
   59 sub asech {CORE::log((1.0+CORE::sqrt(1-$_[1]*$_[1]))/$_[1])}
   60 sub acsch {CORE::log((1.0+CORE::sqrt(1+$_[1]*$_[1]))/$_[1])}
   61 sub acoth {CORE::log(($_[1]+1.0)/($_[1]-1.0))/2.0}
   62 
   63 sub sgn {$_[1] <=> 0}
   64 
   65 sub C {
   66   shift; my ($n,$r) = @_; my $C = 1;
   67   return(0) if ($r>$n);
   68   $r = $n-$r if ($r > $n-$r); # find the smaller of the two
   69   for (1..$r) {$C = ($C*($n-$_+1))/$_}
   70   return $C;
   71 }
   72 
   73 sub P {
   74   shift; my ($n,$r) = @_; my $P = 1;
   75   return(0) if ($r>$n);
   76   for (1..$r) {$P *= ($n-$_+1)}
   77   return $P;
   78 }
   79 
   80 
   81 #
   82 #  Back to main package
   83 #
   84 package main;
   85 
   86 #
   87 #  Make main versions call the checker to see
   88 #  which package-specific version to call
   89 #
   90 
   91 sub ln {CommonFunction->Call('log',@_)}
   92 sub logten {CommonFunction->Call('logten',@_)}
   93 
   94 sub tan {CommonFunction->Call('tan',@_)}
   95 sub cot {CommonFunction->Call('cot',@_)}
   96 sub sec {CommonFunction->Call('sec',@_)}
   97 sub csc {CommonFunction->Call('csc',@_)}
   98 
   99 sub arcsin {CommonFunction->Call('asin',@_)}; sub asin {CommonFunction->Call('asin',@_)}
  100 sub arccos {CommonFunction->Call('acos',@_)}; sub acos {CommonFunction->Call('acos',@_)}
  101 sub arctan {CommonFunction->Call('atan',@_)}; sub atan {CommonFunction->Call('atan',@_)}
  102 sub arccot {CommonFunction->Call('acot',@_)}; sub acot {CommonFunction->Call('acot',@_)}
  103 sub arcsec {CommonFunction->Call('asec',@_)}; sub asec {CommonFunction->Call('asec',@_)}
  104 sub arccsc {CommonFunction->Call('acsc',@_)}; sub acsc {CommonFunction->Call('acsc',@_)}
  105 
  106 sub sinh {CommonFunction->Call('sinh',@_)}
  107 sub cosh {CommonFunction->Call('cosh',@_)}
  108 sub tanh {CommonFunction->Call('tanh',@_)}
  109 sub sech {CommonFunction->Call('sech',@_)}
  110 sub csch {CommonFunction->Call('csch',@_)}
  111 sub coth {CommonFunction->Call('coth',@_)}
  112 
  113 sub arcsinh {CommonFunction->Call('asinh',@_)}; sub asinh {CommonFunction->Call('asinh',@_)}
  114 sub arccosh {CommonFunction->Call('acosh',@_)}; sub acosh {CommonFunction->Call('acosh',@_)}
  115 sub arctanh {CommonFunction->Call('atanh',@_)}; sub atanh {CommonFunction->Call('atanh',@_)}
  116 sub arcsech {CommonFunction->Call('asech',@_)}; sub asech {CommonFunction->Call('asech',@_)}
  117 sub arccsch {CommonFunction->Call('acsch',@_)}; sub acsch {CommonFunction->Call('acsch',@_)}
  118 sub arccoth {CommonFunction->Call('acoth',@_)}; sub acoth {CommonFunction->Call('acoth',@_)}
  119 
  120 sub sgn {CommonFunction->Call('sgn',@_)}
  121 
  122 sub C {CommonFunction->Call('C', @_)}
  123 sub P {CommonFunction->Call('P', @_)}
  124 sub Comb {CommonFunction->Call('C', @_)}
  125 sub Perm {CommonFunction->Call('P', @_)}
  126 
  127 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9