Update of /cvsroot/jspro/jsPro
In directory sc8-pr-cvs1:/tmp/cvs-serv19066
Modified Files:
math.js
Log Message:
added support for constants within Math.pi() and did some small amount of QA
Index: math.js
===================================================================
RCS file: /cvsroot/jspro/jsPro/math.js,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** math.js 12 Sep 2003 14:20:37 -0000 1.21
--- math.js 15 Sep 2003 01:53:22 -0000 1.22
***************
*** 1208,1212 ****
* Calculates and returns the xth term of the Fibonacci sequence.
*
! * @summary fibonacci sequence
* @author Stuart Wigley
* @author Randolph Fielding
--- 1208,1212 ----
* Calculates and returns the xth term of the Fibonacci sequence.
*
! * @summary Fibonacci sequence
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1254,1258 ****
* by another number.
*
! * @summary floating point modulus
* @author Stuart Wigley
* @version 1.0, 09/03/03
--- 1254,1258 ----
* by another number.
*
! * @summary floating-point remainder
* @author Stuart Wigley
* @version 1.0, 09/03/03
***************
*** 1305,1309 ****
* space using the Gudermannian function.
*
! * @summary gudermannian function
* @author Stuart Wigley
* @author Randolph Fielding
--- 1305,1309 ----
* space using the Gudermannian function.
*
! * @summary Gudermannian function
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1525,1529 ****
* Converts a hexadecimal number into its decimal equivalent.
*
! * @summary hexadecimal to decimal converison
* @author Stuart Wigley
* @author Randolph Fielding
--- 1525,1529 ----
* Converts a hexadecimal number into its decimal equivalent.
*
! * @summary hexadecimal to decimal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1945,1949 ****
* Determines if a number is valid according to the LUHN formula.
*
! * @summary luhn formula
* @author Stuart Wigley
* @author Randolph Fielding
--- 1945,1949 ----
* Determines if a number is valid according to the LUHN formula.
*
! * @summary LUHN formula
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2137,2159 ****
/**
! * Calculates pi using the four two-term Machin-like formulas. The default is
! * Machin's Formula. The choice of formula can be specified by setting the
! * <code>sFormula</code> argument as follows:
! *
! * 'e' Euler's Machin-like Formula
! * 'h' Hermann's Formula
! * 'm' Machin's Formula
! * 'u' Hutton's Formula
*
* @summary calculate pi
* @author Stuart Wigley
! * @version 1.0, 09/12/03
* @interface <code>Math.pi()</code>
! * @interface <code>Math.pi(sFormula)</code>
! * @param sFormula a string representing the choice of formula
* @return pi
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
- * @throws MethodNotAvailableException
* @throws TypeMismatchException
*/
--- 2137,2155 ----
/**
! * Calculates pi using one of the four two-term, Machin-like formulas.
*
* @summary calculate pi
* @author Stuart Wigley
! * @author Randolph Fielding
! * @version 1.1, 09/14/03
* @interface <code>Math.pi()</code>
! * @interface <code>Math.pi(iFormula)</code>
! * @param iFormula an integer representing the two-term, Machin-like
! * formula to use for calculating pi (Machin's formula: 0;
! * Euler's Machin-like formula: 1; Hermann's formula: 2;
! * Hutton's formula: 3) (optional)
* @return pi
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
* @throws TypeMismatchException
*/
***************
*** 2164,2192 ****
var vError = null;
var iNumArguments = arguments.length;
! var sFormula
! if (iNumArguments == 0) {
! sFormula = 's'
! } else if (iNumArguments == 1) {
! sFormula = arguments[0];
! } else {
throw vError = new IllegalArgumentException('Math.pi', '0 or 1', iNumArguments);
}
! if (typeof sFormula != 'string') {
! throw vError = new TypeMismatchException('Math.pi', 'string', typeof sFormula);
}
! var fPi;
!
! switch (sFormula) {
!
! case 'e' : fPi = 4 * (Math.atan(1/2) + Math.atan(1/3)); break;
! case 'h' : fPi = 4 * ((2 * Math.atan(1/2)) - Math.atan(1/7)); break;
! case 'u' : fPi = 4 * ((2 * Math.atan(1/3)) + Math.atan(1/7)); break;
! case 'm' :
! default : fPi = 4 * ((4 * Math.atan(1/5)) - Math.atan(1/239)); break;
}
-
}
catch (vError) {
--- 2160,2182 ----
var vError = null;
var iNumArguments = arguments.length;
! var iFormula = 0;
! if (iNumArguments > 1) {
throw vError = new IllegalArgumentException('Math.pi', '0 or 1', iNumArguments);
+ } else if (iNumArguments == 1) {
+ iFormula = arguments[0];
}
! if ((typeof iFormula != 'number') || (parseInt(iFormula.toString()) != iFormula)) {
! throw vError = new TypeMismatchException('Math.pi', 'number', typeof iFormula);
}
! switch (iFormula) {
! case 1 : var fPi = 4 * (Math.atan(1 / 2) + Math.atan(1 / 3)); break;
! case 2 : var fPi = 4 * ((2 * Math.atan(1 / 2)) - Math.atan(1 / 7)); break;
! case 3 : var fPi = 4 * ((2 * Math.atan(1 / 3)) + Math.atan(1 / 7)); break;
! case 0 :
! default : var fPi = 4 * ((4 * Math.atan(1 / 5)) - Math.atan(1 / 239)); break;
}
}
catch (vError) {
|