[Jspro-cvs] jsPro math.js,1.24,1.25 CHANGES,1.20,1.21
Brought to you by:
wigleys
|
From: <wi...@us...> - 2003-10-06 12:21:36
|
Update of /cvsroot/jspro/jsPro
In directory sc8-pr-cvs1:/tmp/cvs-serv20844
Modified Files:
math.js CHANGES
Log Message:
8 new mathematical methods
Index: math.js
===================================================================
RCS file: /cvsroot/jspro/jsPro/math.js,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** math.js 24 Sep 2003 13:10:23 -0000 1.24
--- math.js 6 Oct 2003 12:21:32 -0000 1.25
***************
*** 165,168 ****
--- 165,213 ----
/**
+ * Calculates and returns the inverse coversine of a number in 2D Cartesian
+ * space.
+ *
+ * @summary inverse coversine
+ * @author Stuart Wigley
+ * @version 1.0, 10/09/03
+ * @interface <code>Math.acov(fX)</code>
+ * @param fX a floating-point number
+ * @return the inverse coversine of <code>fX</code> in radians
+ * @return <code>NaN</code> if <code>0 < fX < 2</code>
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.acov = function(fX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.acov', 1, iNumArguments);
+ }
+
+ if (typeof fX != 'number') {
+ throw vError = new TypeMismatchException('Math.acov', 'number', typeof fX);
+ }
+
+ var fInvCoversine = Math.atan((1 - fX) / Math.sqrt(2 * fX - fX * fX));
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fInvCoversine;
+ }
+ }
+
+
+ /**
* Calculates and returns the inverse cosecant of a number in 2D Cartesian
* space.
***************
*** 257,260 ****
--- 302,395 ----
/**
+ * Calculates and returns the inverse exsecant of a number in 2D Cartesian
+ * space.
+ *
+ * @summary inverse exsecant
+ * @author Stuart Wigley
+ * @version 1.0, 10/06/03
+ * @interface <code>Math.aexsec(fX)</code>
+ * @param fX a floating-point number
+ * @return the inverse exsecant of <code>fX</code>
+ * @return <code>NaN</code> if <code>-2 < fX < 0</code>
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.aexsec = function(fX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.aexsec', 1, iNumArguments);
+ }
+
+ if (typeof fX != 'number') {
+ throw vError = new TypeMismatchException('Math.aexsec', 'number', typeof fX);
+ }
+
+ var fInvExsecant = Math.atan(Math.sqrt((fX * fX) + (2 * fX)));
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fInvExsecant;
+ }
+ }
+
+
+ /**
+ * Calculates and returns the inverse haversine of a number in 2D Cartesian
+ * space.
+ *
+ * @summary inverse haversine
+ * @author Stuart Wigley
+ * @version 1.0, 10/09/03
+ * @interface <code>Math.ahav(fX)</code>
+ * @param fX a floating-point number
+ * @return the inverse haversine of <code>fX</code> in radians
+ * @return <code>NaN</code> if <code>0 < fX < 1</code>
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.ahav = function(fX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.ahav', 1, iNumArguments);
+ }
+
+ if (typeof fX != 'number') {
+ throw vError = new TypeMismatchException('Math.ahav', 'number', typeof fX);
+ }
+
+ var fInvHaversine = Math.atan(2 * Math.sqrt(fX - fX * fX) / (1 - 2 * fX)) ;
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fInvHaversine;
+ }
+ }
+
+
+ /**
* Calculates if two numbers are approximately equal. Approximation defaults
* to +/- 0.01 but can be optionally set using the <code>fEpsilon</code>
***************
*** 561,564 ****
--- 696,744 ----
/**
+ * Calculates and returns the inverse versine of a number in 2D Cartesian
+ * space.
+ *
+ * @summary inverse versine
+ * @author Stuart Wigley
+ * @version 1.0, 10/02/03
+ * @interface <code>Math.avers(fX)</code>
+ * @param fX a floating-point number
+ * @return the inverse versine of <code>fX</code>
+ * @return <code>NaN</code> if <code>0 < fX < 2</code>
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.avers = function(fX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.avers', 1, iNumArguments);
+ }
+
+ if (typeof fX != 'number') {
+ throw vError = new TypeMismatchException('Math.avers', 'number', typeof fX);
+ }
+
+ var fAvers = Math.atan(Math.sqrt(2 * fX - fX * fX) / (1 - fX));
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fAvers;
+ }
+ }
+
+
+ /**
* Converts a number from one base to another base.
*
***************
*** 765,768 ****
--- 945,991 ----
/**
+ * Calculates and returns the coexsecant of a number in 2D Cartesian space.
+ *
+ * @summary coexsecant
+ * @author Stuart Wigley
+ * @version 1.0, 10/02/03
+ * @interface <code>Math.coexsec(fX)</code>
+ * @param fX a floating-point number
+ * @return the coexsecant of <code>fX</code>
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.coexsec = function(fX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.coexsec', 1, iNumArguments);
+ }
+
+ if (typeof fX != 'number') {
+ throw vError = new TypeMismatchException('Math.coexsec', 'number', typeof fX);
+ }
+
+ var fCoexsecant = (1 / Math.sin(fX)) - 1;
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fCoexsecant;
+ }
+ }
+
+
+ /**
* Calculates and returns the hyperbolic cosine of a number in 2D Cartesian
* space.
***************
*** 1383,1386 ****
--- 1606,1656 ----
/**
+ * Calculates and returns the factorial of a number.
+ *
+ * @summary factorial
+ * @author Stuart Wigley
+ * @version 1.0, 10/02/03
+ * @interface <code>Math.factorial(iX)</code>
+ * @param fX an integer
+ * @return the factorial of <code>iX</code>
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.factorial = function(iX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.factorial', 1, iNumArguments);
+ }
+
+ if ((typeof iX != 'number') || (iX.toString().indexOf('.') != -1)) {
+ throw vError = new TypeMismatchException('Math.factorial', 'integer', typeof iX);
+ }
+
+ var iFactorial = 1;
+
+ for (var i = 1; i <= iX; i++) {
+ iFactorial *= i;
+ }
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : iFactorial;
+ }
+ }
+
+
+ /**
* Calculates and returns the xth term of the Fibonacci sequence.
*
***************
*** 1612,1615 ****
--- 1882,1928 ----
/**
+ * Calculates and returns the hacoversine of a number in 2D Cartesian space.
+ *
+ * @summary hacoversine
+ * @author Stuart Wigley
+ * @version 1.0, 10/02/03
+ * @interface <code>Math.hac(fX)</code>
+ * @param fX a floating-point number
+ * @return the hacoversine of <code>fX</code>
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.hac = function(fX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.hac', 1, iNumArguments);
+ }
+
+ if (typeof fX != 'number') {
+ throw vError = new TypeMismatchException('Math.hac', 'number', typeof fX);
+ }
+
+ var fHacoversine = (1 - Math.sin(fX)) / 2;
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fHacoversine;
+ }
+ }
+
+
+ /**
* Calculates and returns the haversine of a number in 2D Cartesian space.
*
***************
*** 2187,2190 ****
--- 2500,2554 ----
return vError ? null : bIsValidLuhn;
+ }
+ }
+
+
+ /**
+ * Returns the mantissa part of a floating point number, or zero for an integer.
+ *
+ * @summary mantissa
+ * @author Stuart Wigley
+ * @version 1.0, 10/01/03
+ * @interface <code>Math.mantissa(fX)</code>
+ * @param fX a floating-point number
+ * @return the mantissa part of a floating point number
+ * @return zero for an integer
+ * @return <code>null</code> if an exception is encountered
+ * @throws IllegalArgumentException
+ * @throws TypeMismatchException
+ */
+ Math.mantissa = function(fX) {
+
+ try {
+
+ var vError = null;
+ var iNumArguments = arguments.length;
+
+ if (iNumArguments != 1) {
+ throw vError = new IllegalArgumentException('Math.mantissa', 1, iNumArguments);
+ }
+
+ if (typeof fX != 'number') {
+ throw vError = new TypeMismatchException('Math.mantissa', 'number', typeof fX);
+ }
+
+ var fMantissa = 0;
+ var absfX = Math.abs(fX);
+
+ if (fX.toString().indexOf('.') != -1) {
+ //FIXME:
+ // 67.8 - 67 = 0.7999999999999972
+ fMantissa = absfX - Math.floor(absfX);
+ }
+ }
+ catch (vError) {
+
+ if (vError instanceof Error) {
+ vError.handleError();
+ }
+ }
+ finally {
+
+ return vError ? null : fMantissa;
}
}
Index: CHANGES
===================================================================
RCS file: /cvsroot/jspro/jsPro/CHANGES,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** CHANGES 1 Oct 2003 10:02:14 -0000 1.20
--- CHANGES 6 Oct 2003 12:21:32 -0000 1.21
***************
*** 1,4 ****
===============================================================================
! Whats new in R3? (01 Oct 2003)
===============================================================================
--- 1,21 ----
===============================================================================
! Whats new in R2? (Not Released Yet)
! ===============================================================================
!
! Additions:
!
! math.js:
!
! - Math.acov()
! - Math.aexsec()
! - Math.ahav()
! - Math.avers()
! - Math.coexsec()
! - Math.factorial()
! - Math.hac()
! - Math.mantissa()
!
! ===============================================================================
! Whats new in R3? (Released 01 Oct 2003)
===============================================================================
|