[Jspro-cvs] jsPro math.js,1.20,1.21
Brought to you by:
wigleys
|
From: <wi...@us...> - 2003-09-12 14:20:43
|
Update of /cvsroot/jspro/jsPro
In directory sc8-pr-cvs1:/tmp/cvs-serv26969
Modified Files:
math.js
Log Message:
- new pi calculation method
- addition of @summary comment
Index: math.js
===================================================================
RCS file: /cvsroot/jspro/jsPro/math.js,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** math.js 3 Sep 2003 23:06:31 -0000 1.20
--- math.js 12 Sep 2003 14:20:37 -0000 1.21
***************
*** 30,33 ****
--- 30,34 ----
* Cartesian space.
*
+ * @summary inverse hyperbolic cosine
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 75,78 ****
--- 76,80 ----
* space.
*
+ * @summary inverse cotangent
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 119,122 ****
--- 121,125 ----
* Cartesian space.
*
+ * @summary inverse hyperbolic cotangent
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 165,168 ****
--- 168,172 ----
* space.
*
+ * @summary inverse cosecant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 211,214 ****
--- 215,219 ----
* Cartesian space.
*
+ * @summary inverse hyperbolic cosecant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 255,258 ****
--- 260,264 ----
* space.
*
+ * @summary inverse secant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 301,304 ****
--- 307,311 ----
* Cartesian space.
*
+ * @summary inverse hyperbolic secant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 347,350 ****
--- 354,358 ----
* Cartesian space.
*
+ * @summary inverse hyperbolic sine
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 391,394 ****
--- 399,403 ----
* Cartesian space.
*
+ * @summary inverse hyperbolic tangent
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 436,439 ****
--- 445,449 ----
* Converts a number from one base to another base.
*
+ * @summary convert base
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 491,494 ****
--- 501,505 ----
* Converts a binary number into its decimal equivalent.
*
+ * @summary binary to decimal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 534,537 ****
--- 545,549 ----
* Converts a binary number into its hexadecimal equivalent.
*
+ * @summary binary to hexadecimal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 577,580 ****
--- 589,593 ----
* Converts a binary number into its octal equivalent.
*
+ * @summary binary to octal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 621,624 ****
--- 634,638 ----
* space.
*
+ * @summary hyperbolic cosine
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 664,667 ****
--- 678,682 ----
* Calculates and returns the cotangent of a number in 2D Cartesian space.
*
+ * @summary cotangent
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 708,711 ****
--- 723,727 ----
* space.
*
+ * @summary hyperbolic cotangent
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 751,754 ****
--- 767,771 ----
* Calculates and returns the coversine of a number in 2D Cartesian space.
*
+ * @summary coversine
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 794,797 ****
--- 811,815 ----
* Calculates and returns the cosecant of a number in 2D Cartesian space.
*
+ * @summary cosecant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 838,841 ****
--- 856,860 ----
* space.
*
+ * @summary hyperbolic cosecant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 881,884 ****
--- 900,904 ----
* Converts a decimal number into its binary equivalent.
*
+ * @summary decimal to binary conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 924,927 ****
--- 944,948 ----
* Converts a decimal number into its hexadecimal equivalent.
*
+ * @summary decimal to hexadecimal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 967,970 ****
--- 988,992 ----
* Converts a decimal number into its octal equivalent.
*
+ * @summary decimal to octal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1010,1013 ****
--- 1032,1036 ----
* Converts an angle in degrees into its equivalent in gradians.
*
+ * @summary degree to gradian conversion
* @author Randolph Fielding
* @author Stuart Wigley
***************
*** 1053,1056 ****
--- 1076,1080 ----
* Converts an angle in degrees into its equivalent in radians.
*
+ * @summary degree to radian conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1096,1099 ****
--- 1120,1124 ----
* Calculates and returns exp(x) - 1 for a number x.
*
+ * @summary exp(x) - 1
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1139,1142 ****
--- 1164,1168 ----
* Calculates and returns the exsecant of a number in 2D Cartesian space.
*
+ * @summary exsecant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1182,1185 ****
--- 1208,1212 ----
* Calculates and returns the xth term of the Fibonacci sequence.
*
+ * @summary fibonacci sequence
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1227,1230 ****
--- 1254,1258 ----
* by another number.
*
+ * @summary floating point modulus
* @author Stuart Wigley
* @version 1.0, 09/03/03
***************
*** 1277,1280 ****
--- 1305,1309 ----
* space using the Gudermannian function.
*
+ * @summary gudermannian function
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1320,1323 ****
--- 1349,1353 ----
* Converts an angle in gradians into its equivalent in degrees.
*
+ * @summary gradian to degree conversion
* @author Randolph Fielding
* @author Stuart Wigley
***************
*** 1363,1366 ****
--- 1393,1397 ----
* Converts an angle in gradians into its equivalent in radians.
*
+ * @summary gradian to radian conversion
* @author Randolph Fielding
* @author Stuart Wigley
***************
*** 1406,1409 ****
--- 1437,1441 ----
* Calculates and returns the haversine of a number in 2D Cartesian space.
*
+ * @summary haversine
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1449,1452 ****
--- 1481,1485 ----
* Converts a hexadecimal number into its binary equivalent.
*
+ * @summary hexadecimal to binary conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1492,1495 ****
--- 1525,1529 ----
* Converts a hexadecimal number into its decimal equivalent.
*
+ * @summary hexadecimal to decimal converison
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1535,1538 ****
--- 1569,1573 ----
* Converts a hexadecimal number into its octal equivalent.
*
+ * @summary hexadecimal to octal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1579,1582 ****
--- 1614,1618 ----
* (side C) in 2D Cartesian space.
*
+ * @summary hypotenuse
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1628,1631 ****
--- 1664,1668 ----
* Determines if a number is even.
*
+ * @summary is even?
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1672,1675 ****
--- 1709,1713 ----
* Determines if a number is odd.
*
+ * @summary is odd?
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1717,1720 ****
--- 1755,1759 ----
* no positive integer divisors other than 1 and itself).
*
+ * @summary is prime?
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1771,1774 ****
--- 1810,1814 ----
* Calculates and returns the base-10 logarithm of a number.
*
+ * @summary base-10 logarithm
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1815,1818 ****
--- 1855,1859 ----
* Calculates and returns the base-2 logarithm of a number.
*
+ * @summary base-2 logarithm
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1859,1862 ****
--- 1900,1904 ----
* Calculates and returns log(1 + x) for a number x.
*
+ * @summary log(1 + x)
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1903,1906 ****
--- 1945,1949 ----
* Determines if a number is valid according to the LUHN formula.
*
+ * @summary luhn formula
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 1964,1967 ****
--- 2007,2011 ----
* Converts an octal number into its binary equivalent.
*
+ * @summary octal to binary conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2007,2010 ****
--- 2051,2055 ----
* Converts an octal number into its decimal equivalent.
*
+ * @summary octal to decimal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2050,2053 ****
--- 2095,2099 ----
* Converts an octal number into its hexadecimal equivalent.
*
+ * @summary octal to hexadecimal conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2091,2096 ****
--- 2137,2210 ----
/**
+ * 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
+ */
+ Math.pi = function() {
+
+ try {
+
+ 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) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fPi;
+ }
+ }
+
+
+ /**
* Converts an angle in radians into its equivalent in degrees.
*
+ * @summary radian to degree conversion
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2136,2139 ****
--- 2250,2254 ----
* Converts an angle in radians into its equivalent in gradians.
*
+ * @summary radian to gradian conversion
* @author Randolph Fielding
* @author Stuart Wigley
***************
*** 2179,2182 ****
--- 2294,2298 ----
* Calculates and returns the secant of a number in 2D Cartesian space.
*
+ * @summary secant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2223,2226 ****
--- 2339,2343 ----
* space.
*
+ * @summary hyperbolic secant
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2267,2270 ****
--- 2384,2388 ----
* the sigmoid function.
*
+ * @summary sigmoid function
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2310,2313 ****
--- 2428,2432 ----
* Calculates and returns the sign of a number.
*
+ * @summary sign
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2356,2359 ****
--- 2475,2479 ----
* sinc function.
*
+ * @summary sinc function
* @author Randolph Fielding
* @author Stuart Wigley
***************
*** 2400,2403 ****
--- 2520,2524 ----
* space.
*
+ * @summary hyperbolic sine
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2443,2446 ****
--- 2564,2568 ----
* Calculates and returns the square of a number.
*
+ * @summary square
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2487,2490 ****
--- 2609,2613 ----
* tanc function.
*
+ * @summary tanc function
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2531,2534 ****
--- 2654,2658 ----
* space.
*
+ * @summary hyperbolic tangent
* @author Stuart Wigley
* @author Randolph Fielding
***************
*** 2574,2577 ****
--- 2698,2702 ----
* Calculates and returns the versine of a number in 2D Cartesian space.
*
+ * @summary versine
* @author Stuart Wigley
* @author Randolph Fielding
|