[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 6160 - (download) (as text) (annotate)
Wed Nov 4 17:14:45 2009 UTC (10 years, 3 months ago) by dpvc
File size: 4442 byte(s)
Fix problem with useBaseTenLog in perl code

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9