[Jspro-cvs] jsPro math.js,1.26,1.27
Brought to you by:
wigleys
From: <gat...@us...> - 2003-10-30 22:31:57
|
Update of /cvsroot/jspro/jsPro In directory sc8-pr-cvs1:/tmp/cvs-serv6761 Modified Files: math.js Log Message: QA: methods since R3 now QA'd Index: math.js =================================================================== RCS file: /cvsroot/jspro/jsPro/math.js,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** math.js 13 Oct 2003 08:57:46 -0000 1.26 --- math.js 30 Oct 2003 22:31:54 -0000 1.27 *************** *** 170,178 **** * @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 --- 170,180 ---- * @summary inverse coversine * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 10/30/03 * @interface <code>Math.acov(fX)</code> ! * @param fX a floating-point number between 0 and 2 inclusive * @return the inverse coversine of <code>fX</code> in radians ! * @return <code>NaN</code> if <code>fX < 0</code> or ! * <code>fX > 2</code> * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException *************** *** 194,198 **** } ! var fInvCoversine = Math.atan((1 - fX) / Math.sqrt(2 * fX - fX * fX)); } catch (vError) { --- 196,200 ---- } ! var fInvCoversine = Math.atan((1 - fX) / Math.sqrt(fX * (2 - fX))); } catch (vError) { *************** *** 307,314 **** * @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 --- 309,318 ---- * @summary inverse exsecant * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 10/30/03 * @interface <code>Math.aexsec(fX)</code> ! * @param fX a floating-point number less than or equal to -2 or ! * greater than or equal to 0 ! * @return the inverse exsecant of <code>fX</code> in radians * @return <code>NaN</code> if <code>-2 < fX < 0</code> * @return <code>null</code> if an exception is encountered *************** *** 331,335 **** } ! var fInvExsecant = Math.atan(Math.sqrt((fX * fX) + (2 * fX))); } catch (vError) { --- 335,339 ---- } ! var fInvExsecant = Math.atan(Math.sqrt(fX * (fX + 2))); } catch (vError) { *************** *** 352,360 **** * @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 --- 356,366 ---- * @summary inverse haversine * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 10/30/03 * @interface <code>Math.ahav(fX)</code> ! * @param fX a floating-point number between 0 and 1 inclusive * @return the inverse haversine of <code>fX</code> in radians ! * @return <code>NaN</code> if <code>fX < 0</code> or ! * <code>fX > 1</code> * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException *************** *** 376,380 **** } ! var fInvHaversine = Math.atan(2 * Math.sqrt(fX - fX * fX) / (1 - 2 * fX)) ; } catch (vError) { --- 382,386 ---- } ! var fInvHaversine = Math.atan((2 * Math.sqrt(fX * (1 - fX))) / (1 - (2 * fX))); } catch (vError) { *************** *** 392,402 **** /** ! * Calculates if two numbers are approximately equal. Approximation defaults ! * to +/- 0.01 but can be optionally set using the <code>fEpsilon</code> ! * argument * ! * @summary approximately equal * @author Stuart Wigley ! * @version 1.0, 09/24/03 * @interface <code>Math.approx(fX, fY)</code> * @interface <code>Math.approx(fX, fY, fEpsilon)</code> --- 398,411 ---- /** ! * Determines whether two numbers are approximately equal. Given two numbers ! * (x and y) and an accuracy of approximation (epsilon), the range of values ! * where y is approximately equal to x is defined by |x| < epsilon for y = 0 ! * and by |(y - x) / y| < epsilon for all other y. By default epsilon is set ! * to 0.01, but this can be overridden with the optional epsilon argument. * ! * @summary are numbers approximately equal? * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 09/25/03 * @interface <code>Math.approx(fX, fY)</code> * @interface <code>Math.approx(fX, fY, fEpsilon)</code> *************** *** 404,414 **** * @param fY a floating-point number * @param fEpsilon accuracy of approximation (optional) ! * @return true if <code>fX</code> and <code>fY</code> are ! * approximately equal; false otherwise * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException * @throws TypeMismatchException */ ! Math.approx = function() { try { --- 413,426 ---- * @param fY a floating-point number * @param fEpsilon accuracy of approximation (optional) ! * @return <code>true</code> if <code>fX</code> and ! * <code>fY</code> are approximately equal ! * @return <code>false</code> if <code>fX</code> and ! * <code>fY</code> are not approximately equal * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException + * @throws IllegalValueException * @throws TypeMismatchException */ ! Math.approx = function(fX, fY) { try { *************** *** 416,431 **** var vError = null; var iNumArguments = arguments.length; - var fX, fY; var fEpsilon = 0.01; ! if (iNumArguments == 2) { ! fX = arguments[0]; ! fY = arguments[1]; } else if (iNumArguments == 3) { - fX = arguments[0]; - fY = arguments[1]; fEpsilon = arguments[2]; - } else { - throw vError = new IllegalArgumentException('Math.approx', '2 or 3', iNumArguments); } --- 428,437 ---- var vError = null; var iNumArguments = arguments.length; var fEpsilon = 0.01; ! if ((iNumArguments < 2) || (iNumArguments > 3)) { ! throw vError = new IllegalArgumentException('Math.approx', '2 or 3', iNumArguments); } else if (iNumArguments == 3) { fEpsilon = arguments[2]; } *************** *** 433,444 **** throw vError = new TypeMismatchException('Math.approx', 'number', typeof fX); } if (typeof fY != 'number') { throw vError = new TypeMismatchException('Math.approx', 'number', typeof fY); } if (typeof fEpsilon != 'number') { throw vError = new TypeMismatchException('Math.approx', 'number', typeof fEpsilon); } ! var bApprox = (Math.abs(fX - fY) < fEpsilon) ? true : false; } catch (vError) { --- 439,456 ---- throw vError = new TypeMismatchException('Math.approx', 'number', typeof fX); } + if (typeof fY != 'number') { throw vError = new TypeMismatchException('Math.approx', 'number', typeof fY); } + if (typeof fEpsilon != 'number') { throw vError = new TypeMismatchException('Math.approx', 'number', typeof fEpsilon); } ! if (fEpsilon < 0) { ! throw vError = new IllegalValueException('Math.approx', 'fEpsilon', '0 or greater', fEpsilon); ! } ! ! var bApprox = (fY == 0) ? Math.abs(fX) < fEpsilon : Math.abs((fY - fX) / fY) < fEpsilon; } catch (vError) { *************** *** 456,474 **** /** ! * Calculates the polar angle (argument) of a pair of rectangular coordinates. * * @summary polar angle (argument) * @author Stuart Wigley ! * @version 1.0, 09/24/03 ! * @interface <code>Math.arg(fX, fY)</code> ! * @requires <code>math.sign()</code> ! * @param fX a floating-point number ! * @param fY a floating-point number ! * @return the polar angle (argument) * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException - * @throws TypeMismatchException * @throws MethodNotAvailableException ! * @see <code>math.sign()</code> */ Math.arg = function(fX, fY) { --- 468,488 ---- /** ! * Calculates and returns the polar angle (argument) of a point (x, y) in 2D ! * Cartesian space. * * @summary polar angle (argument) * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 09/25/03 ! * @interface <code>Math.arg(fAbscissa, fOrdinate)</code> ! * @requires <code>Math.sign(fX)</code> ! * @param fAbscissa the x-coordinate of an ordered pair ! * @param fOrdinate the y-coordinate of an ordered pair ! * @return the polar angle (argument) of the point (x, y) * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException * @throws MethodNotAvailableException ! * @throws TypeMismatchException ! * @see <code>Math.sign()</code> */ Math.arg = function(fX, fY) { *************** *** 490,498 **** throw vError = new TypeMismatchException('Math.arg', 'number', typeof fX); } if (typeof fY != 'number') { throw vError = new TypeMismatchException('Math.arg', 'number', typeof fY); } ! var fArgument = Math.atan2(fY, fX) + (Math.PI / 2) * Math.sign(fY) * (1 - Math.sign(fX)); } catch (vError) { --- 504,513 ---- throw vError = new TypeMismatchException('Math.arg', 'number', typeof fX); } + if (typeof fY != 'number') { throw vError = new TypeMismatchException('Math.arg', 'number', typeof fY); } ! var fArgument = Math.atan2(fY, fX) + ((Math.PI / 2) * Math.sign(fY) * (1 - Math.sign(fX))); } catch (vError) { *************** *** 701,709 **** * @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 --- 716,726 ---- * @summary inverse versine * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 10/30/03 * @interface <code>Math.avers(fX)</code> ! * @param fX a floating-point number between 0 and 2 inclusive ! * @return the inverse versine of <code>fX</code> in radians ! * @return <code>NaN</code> if <code>fX < 0</code> or ! * <code>fX > 2</code> * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException *************** *** 725,729 **** } ! var fAvers = Math.atan(Math.sqrt(2 * fX - fX * fX) / (1 - fX)); } catch (vError) { --- 742,746 ---- } ! var fInvVersine = Math.atan(Math.sqrt(fX * (2 - fX)) / (1 - fX)); } catch (vError) { *************** *** 735,739 **** finally { ! return vError ? null : fAvers; } } --- 752,756 ---- finally { ! return vError ? null : fInvVersine; } } *************** *** 1519,1527 **** /** ! * Calculates the exponent of 10. ie 10 to the power of <code>fX</code> * ! * @summary exponent of 10 * @author Stuart Wigley ! * @version 1.0, 09/24/03 * @interface <code>Math.exp10(fX)</code> * @param fX a floating-point number --- 1536,1545 ---- /** ! * Calculates and returns 10 raised to the power of x for a number x. * ! * @summary 10 raised to the power of x * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 09/25/03 * @interface <code>Math.exp10(fX)</code> * @param fX a floating-point number *************** *** 1546,1550 **** } ! var fExponent10 = Math.pow(10, fX); } catch (vError) { --- 1564,1568 ---- } ! var fExp10 = Math.pow(10, fX); } catch (vError) { *************** *** 1556,1560 **** finally { ! return vError ? null : fExponent10; } } --- 1574,1578 ---- finally { ! return vError ? null : fExp10; } } *************** *** 1650,1663 **** /** ! * 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 */ --- 1668,1683 ---- /** ! * Calculates and returns the factorial of a positive integer. * * @summary factorial * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 10/30/03 * @interface <code>Math.factorial(iX)</code> ! * @param iX a positive integer * @return the factorial of <code>iX</code> * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException + * @throws IllegalValueException * @throws TypeMismatchException */ *************** *** 1677,1680 **** --- 1697,1704 ---- } + if (iX < 0) { + throw vError = new IllegalValueException('Math.factorial', 'iX', '0 or greater', iX); + } + var iFactorial = 1; *************** *** 2593,2605 **** /** ! * 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 --- 2617,2630 ---- /** ! * Returns the mantissa (i.e. the positive, fractional part) of a floating- ! * point number. * * @summary mantissa * @author Stuart Wigley ! * @author Randolph Fielding ! * @version 1.1, 10/30/03 * @interface <code>Math.mantissa(fX)</code> * @param fX a floating-point number ! * @return the mantissa of <code>fX</code> * @return <code>null</code> if an exception is encountered * @throws IllegalArgumentException *************** *** 2621,2632 **** } ! 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) { --- 2646,2651 ---- } ! var fAbsX = Math.abs(fX); ! var fMantissa = fAbsX - Math.floor(fAbsX); } catch (vError) { |