[system] / trunk / pg / lib / Parser / Function / numeric2.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/Function/numeric2.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5130 - (download) (as text) (annotate)
Mon Jul 9 12:45:06 2007 UTC (5 years, 10 months ago) by dpvc
File size: 1342 byte(s)
Added new flags to error checking of operands and function arguments.
This is so that a context can be developed that is more forgiving
about what can be put next to what.  Such a context can NOT be used
for evaluation or answer checking, but can be used to generate TeX
output in more sophisticated situations.

    1 #########################################################################
    2 #
    3 #  Implement functions having two real inputs
    4 #
    5 package Parser::Function::numeric2;
    6 use strict;
    7 our @ISA = qw(Parser::Function);
    8 
    9 #
   10 #  Check for two real-valued arguments
   11 #
   12 sub _check {
   13   my $self = shift;
   14   return if ($self->checkArgCount(2));
   15   if (($self->{params}->[0]->isNumber && $self->{params}->[1]->isNumber &&
   16       !$self->{params}->[0]->isComplex && !$self->{params}->[1]->isComplex) ||
   17       $self->context->flag("allowBadFunctionInputs")) {
   18     $self->{type} = $Value::Type{number};
   19   } else {
   20     $self->Error("Function '%s' has the wrong type of inputs",$self->{name});
   21   }
   22 }
   23 
   24 #
   25 #  Check that the inputs are OK
   26 #
   27 sub _call {
   28   my $self = shift; my $name = shift;
   29   Value::Error("Function '%s' has too many inputs",$name) if scalar(@_) > 2;
   30   Value::Error("Function '%s' has too few inputs",$name) if scalar(@_) < 2;
   31   Value::Error("Function '%s' has the wrong type of inputs",$name)
   32     unless Value::matchNumber($_[0]) && Value::matchNumber($_[1]);
   33   return $self->$name(@_);
   34 }
   35 
   36 #
   37 #  Call the appropriate routine
   38 #
   39 sub _eval {
   40   my $self = shift; my $name = $self->{name};
   41   $self->$name(@_);
   42 }
   43 
   44 #
   45 #  Do the core atan2 call
   46 #
   47 sub atan2 {shift; CORE::atan2($_[0],$_[1])}
   48 
   49 #########################################################################
   50 
   51 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9