SPAS 3.0 RpnExp Project
What is the RpnExp project?
The RpnExp project is a part of the SPAS 3.0 project that consists in distributing an ActionScript 3.0 RPN calculator, under GNU GPL license.
The SPAS 3.0 RPN calculator uses postfix notation, also known as Reverse Polish Notation (RPN), to evaluate mathematical expressions.
The RPN calculator engine is provided by the SPAS 3.0 RpnExp
class, contained whithin the org.flashapi.swing.math
package.
About the Reverse Polish Notation
The RPN is a parenthesisfree method for performing calculations. This method has been popularized by HewlettPackard. The method depends on a stack of values as its organizing principle. When a number is entered, the previous entry is raised in the stack, so that several values can be stored. When a mathematical operation is performed, it is performed on the most recent value (or values, if more than one is required). This results in fewer operator errors when performing complex calculations.
For more information see the Wikipedia article: Reverse Polish Notation.
Download the RpnExp class
Current version: Version: beta 1.5, 26/05/2008
Download
RpnExp class online documentation
Last update: 26/05/08.
RpnExp class quick start
The RpnExp
class API is very similar to the RegExp
class, and it is really easy to use.
The following example performs a basic mathematical calculation using the RpnExp
constructor:
var rpn:RpnExp = new RpnExp("(2 + 7  1) * 8"); var c:Number = rpn.exec(); trace(c); //Output: 64
The following example returns the value of the constant PI:
var rpn:RpnExp = new RpnExp(); var p:Number = rpn.exec("pi"); trace(p); //Output: 3.141592653589793
The following example shows how to add RPN libraries to the RpnExp
class, to create extended capabilities:
import org.flashapi.swing.math.RpnExp; import org.flashapi.swing.math.rpnlib.Trigonometry; var rpn:RpnExp = new RpnExp(); rpn.addLibrary(Trigonometry); var t:Number = rpn.exec("sin(0) + cos(0)"); trace(t); //Output: 1
The following example calculates the sum of the rounded values of the Euler's constant:
var rpn:RpnExp = new RpnExp(); rpn.addLibrary(RpnMathLibrary); var e:Number = rpn.exec("ceil(e) + floor(e)"); trace(e); //Output: 5
Comming Features
The new structure of the RpnExp class allows to create autonomous mathematical functions integrated seamlessly.
The upcoming RpnMatrixLibrary
class will use this structure to perform matricial calculations, as shown below:
import org.flashapi.swing.math.RpnExp; import org.flashapi.swing.math.rpnlib.Matrix; var rpn:RpnExp = new RpnExp(); rpn.addLibrary(Matrix); var matrix:* = rpn.exec("mat( [ 1;2  3;4 ] + [ 5;6  7;8 ] )");
Project Architecture
The SPAS 3.0 RpnExp Project Architecture is available in PDF format (283 ko).
DownloadChange History
The following list reflects changes made to the RpnExp Project distribution:

Version: beta 1.5, 26/05/2008 21:52
addLibrary() function signature changed: addLibrary(library:Class):RpnLibrary replaced by addLibrary(library:RpnLibrary):RpnLibrary.
Added: addLibraryClass() function to replace addLibrary old version: addLibraryClass(library:Class):RpnLibrary. 
Version: beta 1.4, 19/05/2008 20:09
Added: "√" symbol into the Algebra class to calculate square root of numbers or expressions.
Added: internal proccesses based on the "rpn_internal" name space.
Added: final implementation of the "RpnOperator.parsingFunction" process. 
Version: beta 1.3, 17/05/2008 18:52
bug fix: constant values now can be used normaly.
Added: the Gaussian functions library.
Added: the Arithmetic library to compute "greatest common divisor" and "least common multiple".
Added: the sinh, cosh, tanh, sinc, involve functions into the trigonometry library. 
Version: beta 1.2, 15/05/2008 12:17
New project architecture: creation of the org.flashapi.swing.math.rpnlib package to centralize all mathematical functions libraries. 
Version: beta 1.1, 01/05/2008 11:02
RpnException class changes. 
Version: beta 1.0, 30/04/2008 14:30
Initial version.
Share this article:
Comments:
There are no comments yet for this article.