예제 #1
0
 /**
  * Print a ConstantNode.
  *
  * @param ConstantNode $node
  */
 public function visitConstantNode(ConstantNode $node)
 {
     return $node->getName();
 }
예제 #2
0
 /**
  * Evaluate a ConstantNode
  *
  * Returns the value of a ConstantNode recognized by StdMathLexer and StdMathParser.
  *
  * @see \MathParser\Lexer\StdMathLexer StdMathLexer
  * @see \MathParser\StdMathParser StdMathParser
  * @throws UnknownConstantException if the variable respresented by the
  *      ConstantNode is *not* recognized.
  *
  * @param ConstantNode $node AST to be evaluated
  * @retval float
  */
 public function visitConstantNode(ConstantNode $node)
 {
     switch ($node->getName()) {
         case 'pi':
             return new Complex(M_PI, 0);
         case 'e':
             return new Complex(M_E, 0);
         case 'i':
             return new Complex(0, 1);
         default:
             throw new UnknownConstantException($node->getName());
     }
 }
예제 #3
0
 /**
  * Evaluate a ConstantNode
  *
  * Returns the value of a ConstantNode recognized by StdMathLexer and StdMathParser.
  *
  * @see \MathParser\Lexer\StdMathLexer StdMathLexer
  * @see \MathParser\StdMathParser StdMathParser
  * @throws UnknownConstantException if the variable respresented by the
  *      ConstantNode is *not* recognized.
  *
  * @param ConstantNode $node AST to be evaluated
  * @retval float
  */
 public function visitConstantNode(ConstantNode $node)
 {
     switch ($node->getName()) {
         case 'pi':
             return M_PI;
         case 'e':
             return exp(1);
         default:
             throw new UnknownConstantException($node->getName());
     }
 }
예제 #4
0
 /**
  * Differentiate a ConstantNode
  *
  * Create a NumberNode representing '0'. (The derivative of
  * a constant is indentically 0).
  *
  * @param ConstantNode $node AST to be differentiated
  * @retval Node
  */
 public function visitConstantNode(ConstantNode $node)
 {
     if ($node->getName() == 'NAN') {
         return $node;
     }
     return new IntegerNode(0);
 }
예제 #5
0
 public function visitConstantNode(ConstantNode $node)
 {
     switch ($node->getName()) {
         case 'pi':
             return 'pi';
         case 'e':
             return 'e';
         case 'i':
             return 'i';
         case 'NAN':
             return 'NAN';
         case 'INF':
             return 'INF';
         default:
             throw new UnknownConstantException($node->getName());
     }
 }
예제 #6
0
 /**
  * Evaluate a ConstantNode
  *
  * Returns the value of a ConstantNode recognized by StdMathLexer and StdMathParser.
  *
  * @see \MathParser\Lexer\StdMathLexer StdMathLexer
  * @see \MathParser\StdMathParser StdMathParser
  * @throws UnknownConstantException if the variable respresented by the
  *      ConstantNode is *not* recognized.
  *
  * @param ConstantNode $node AST to be evaluated
  * @retval float
  */
 public function visitConstantNode(ConstantNode $node)
 {
     switch ($node->getName()) {
         case 'pi':
         case 'e':
             throw new \UnexpectedValueException();
         default:
             throw new UnknownConstantException($node->getName());
     }
 }
예제 #7
0
 /**
  * Generate LaTeX code for a ConstantNode
  *
  * Create a string giving LaTeX code for a ConstantNode.
  * `pi` typesets as `\pi` and `e` simply as `e`.
  *
  * @throws UnknownConstantException for nodes representing other constants.
  * @param ConstantNode $node AST to be typeset
  * @retval string
  */
 public function visitConstantNode(ConstantNode $node)
 {
     switch ($node->getName()) {
         case 'pi':
             return '\\pi{}';
         case 'e':
             return 'e';
         case 'i':
             return 'i';
         case 'NAN':
             return '\\operatorname{NAN}';
         case 'INF':
             return '\\infty{}';
         default:
             throw new UnknownConstantException($node->getName());
     }
 }
예제 #8
0
 /**
  * Evaluate a ConstantNode
  *
  * Returns the value of a ConstantNode recognized by StdMathLexer and StdMathParser.
  *
  * @see \MathParser\Lexer\StdMathLexer StdMathLexer
  * @see \MathParser\StdMathParser StdMathParser
  * @throws UnknownConstantException if the variable respresented by the
  *      ConstantNode is *not* recognized.
  *
  * @param ConstantNode $node AST to be evaluated
  * @retval float
  */
 public function visitConstantNode(ConstantNode $node)
 {
     switch ($node->getName()) {
         case 'pi':
         case 'e':
         case 'i':
         case 'NAN':
         case 'INF':
             throw new \UnexpectedValueException("Expecting rational number");
         default:
             throw new UnknownConstantException($node->getName());
     }
 }