[Jspro-cvs] jsPro math.js,1.22,1.23
Brought to you by:
wigleys
|
From: <gat...@us...> - 2003-09-22 06:56:11
|
Update of /cvsroot/jspro/jsPro
In directory sc8-pr-cvs1:/tmp/cvs-serv12429
Modified Files:
math.js
Log Message:
updated certain TypeMismatchExceptions to test for and display the correct datatype ('integer' instead of 'number') and updated methods with new error IllegalValueException
Index: math.js
===================================================================
RCS file: /cvsroot/jspro/jsPro/math.js,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** math.js 15 Sep 2003 01:53:22 -0000 1.22
--- math.js 22 Sep 2003 06:56:07 -0000 1.23
***************
*** 453,461 ****
* @param vNumber an integer, a floating-point number, or a string to
* convert from one base to another base
! * @param iBaseFrom the base to convert from
! * @param iBaseTo the base to convert to
* @return a string representation of the converted number
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
* @throws TypeMismatchException
*/
--- 453,463 ----
* @param vNumber an integer, a floating-point number, or a string to
* convert from one base to another base
! * @param iBaseFrom the base to convert from as an integer between 2 and
! * 36
! * @param iBaseTo the base to convert to as an integer between 2 and 36
* @return a string representation of the converted number
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
+ * @throws IllegalValueException
* @throws TypeMismatchException
*/
***************
*** 475,484 ****
}
! if ((typeof iBaseFrom != 'number') || (parseInt(iBaseFrom.toString()) != iBaseFrom)) {
! throw vError = new TypeMismatchException('Math.baseConvert', 'number', typeof iBaseFrom);
}
! if ((typeof iBaseTo != 'number') || (parseInt(iBaseTo.toString()) != iBaseTo)) {
! throw vError = new TypeMismatchException('Math.baseConvert', 'number', typeof iBaseTo);
}
--- 477,494 ----
}
! if ((typeof iBaseFrom != 'number') || (iBaseFrom.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.baseConvert', 'integer', typeof iBaseFrom);
}
! if ((iBaseFrom < 2) || (iBaseFrom > 36)) {
! throw vError = new IllegalValueException('Math.baseConvert', 'iBaseFrom', '2, 3, 4, ..., 35 or 36', iBaseFrom);
! }
!
! if ((typeof iBaseTo != 'number') || (iBaseTo.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.baseConvert', 'integer', typeof iBaseTo);
! }
!
! if ((iBaseTo < 2) || (iBaseTo > 36)) {
! throw vError = new IllegalValueException('Math.baseConvert', 'iBaseTo', '2, 3, 4, ..., 35 or 36', iBaseTo);
}
***************
*** 508,511 ****
--- 518,523 ----
* @param lBinaryNum a binary number
* @return the decimal equivalent of <code>lBinaryNum</code>
+ * @return <code>NaN</code> if <code>lBinaryNum</code> is not a
+ * binary number
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
***************
*** 523,528 ****
}
! if ((typeof lBinaryNum != 'number') || (parseInt(lBinaryNum.toString()) != lBinaryNum)) {
! throw vError = new TypeMismatchException('Math.bin2dec', 'number', typeof lBinaryNum);
}
--- 535,540 ----
}
! if ((typeof lBinaryNum != 'number') || (lBinaryNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.bin2dec', 'long', typeof lBinaryNum);
}
***************
*** 552,555 ****
--- 564,569 ----
* @param lBinaryNum a binary number
* @return the hexadecimal equivalent of <code>lBinaryNum</code>
+ * @return <code>NaN</code> if <code>lBinaryNum</code> is not a
+ * binary number
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
***************
*** 567,572 ****
}
! if ((typeof lBinaryNum != 'number') || (parseInt(lBinaryNum.toString()) != lBinaryNum)) {
! throw vError = new TypeMismatchException('Math.bin2hex', 'number', typeof lBinaryNum);
}
--- 581,586 ----
}
! if ((typeof lBinaryNum != 'number') || (lBinaryNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.bin2hex', 'long', typeof lBinaryNum);
}
***************
*** 596,599 ****
--- 610,615 ----
* @param lBinaryNum a binary number
* @return the octal equivalent of <code>lBinaryNum</code>
+ * @return <code>NaN</code> if <code>lBinaryNum</code> is not a
+ * binary number
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
***************
*** 611,616 ****
}
! if ((typeof lBinaryNum != 'number') || (parseInt(lBinaryNum.toString()) != lBinaryNum)) {
! throw vError = new TypeMismatchException('Math.bin2oct', 'number', typeof lBinaryNum);
}
--- 627,632 ----
}
! if ((typeof lBinaryNum != 'number') || (lBinaryNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.bin2oct', 'long', typeof lBinaryNum);
}
***************
*** 922,927 ****
}
! if ((typeof lDecimalNum != 'number') || (parseInt(lDecimalNum.toString()) != lDecimalNum)) {
! throw vError = new TypeMismatchException('Math.dec2bin', 'number', typeof lDecimalNum);
}
--- 938,943 ----
}
! if ((typeof lDecimalNum != 'number') || (lDecimalNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.dec2bin', 'long', typeof lDecimalNum);
}
***************
*** 966,971 ****
}
! if ((typeof lDecimalNum != 'number') || (parseInt(lDecimalNum.toString()) != lDecimalNum)) {
! throw vError = new TypeMismatchException('Math.dec2hex', 'number', typeof lDecimalNum);
}
--- 982,987 ----
}
! if ((typeof lDecimalNum != 'number') || (lDecimalNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.dec2hex', 'long', typeof lDecimalNum);
}
***************
*** 1010,1015 ****
}
! if ((typeof lDecimalNum != 'number') || (parseInt(lDecimalNum.toString()) != lDecimalNum)) {
! throw vError = new TypeMismatchException('Math.dec2oct', 'number', typeof lDecimalNum);
}
--- 1026,1031 ----
}
! if ((typeof lDecimalNum != 'number') || (lDecimalNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.dec2oct', 'long', typeof lDecimalNum);
}
***************
*** 1231,1236 ****
}
! if ((typeof iX != 'number') || (parseInt(iX.toString()) != iX)) {
! throw vError = new TypeMismatchException('Math.fibonacci', 'number', typeof iX);
}
--- 1247,1252 ----
}
! if ((typeof iX != 'number') || (iX.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.fibonacci', 'integer', typeof iX);
}
***************
*** 1765,1768 ****
--- 1781,1785 ----
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
+ * @throws IllegalValueException
* @throws TypeMismatchException
*/
***************
*** 1778,1783 ****
}
! if ((typeof iX != 'number') || (parseInt(iX.toString()) != iX)) {
! throw vError = new TypeMismatchException('Math.isPrime', 'number', typeof iX);
}
--- 1795,1804 ----
}
! if ((typeof iX != 'number') || (iX.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.isPrime', 'integer', typeof iX);
! }
!
! if (iX < 2) {
! throw vError = new IllegalValueException('Math.isPrime', 'iX', '2 or greater', iX);
}
***************
*** 1955,1958 ****
--- 1976,1980 ----
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
+ * @throws IllegalValueException
* @throws TypeMismatchException
*/
***************
*** 1968,1973 ****
}
! if ((typeof lX != 'number') || (parseInt(lX.toString()) != lX)) {
! throw vError = new TypeMismatchException('Math.luhn', 'number', typeof lX);
}
--- 1990,1999 ----
}
! if ((typeof lX != 'number') || (lX.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.luhn', 'long', typeof lX);
! }
!
! if (lX < 10) {
! throw vError = new IllegalValueException('Math.luhn', 'lX', '10 or greater', lX);
}
***************
*** 2029,2034 ****
}
! if ((typeof lOctalNum != 'number') || (parseInt(lOctalNum.toString()) != lOctalNum)) {
! throw vError = new TypeMismatchException('Math.oct2bin', 'number', typeof lOctalNum);
}
--- 2055,2060 ----
}
! if ((typeof lOctalNum != 'number') || (lOctalNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.oct2bin', 'long', typeof lOctalNum);
}
***************
*** 2073,2078 ****
}
! if ((typeof lOctalNum != 'number') || (parseInt(lOctalNum.toString()) != lOctalNum)) {
! throw vError = new TypeMismatchException('Math.oct2dec', 'number', typeof lOctalNum);
}
--- 2099,2104 ----
}
! if ((typeof lOctalNum != 'number') || (lOctalNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.oct2dec', 'long', typeof lOctalNum);
}
***************
*** 2117,2122 ****
}
! if ((typeof lOctalNum != 'number') || (parseInt(lOctalNum.toString()) != lOctalNum)) {
! throw vError = new TypeMismatchException('Math.oct2hex', 'number', typeof lOctalNum);
}
--- 2143,2148 ----
}
! if ((typeof lOctalNum != 'number') || (lOctalNum.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.oct2hex', 'long', typeof lOctalNum);
}
***************
*** 2152,2155 ****
--- 2178,2182 ----
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
+ * @throws IllegalValueException
* @throws TypeMismatchException
*/
***************
*** 2168,2173 ****
}
! if ((typeof iFormula != 'number') || (parseInt(iFormula.toString()) != iFormula)) {
! throw vError = new TypeMismatchException('Math.pi', 'number', typeof iFormula);
}
--- 2195,2204 ----
}
! if ((typeof iFormula != 'number') || (iFormula.toString().indexOf('.') != -1)) {
! throw vError = new TypeMismatchException('Math.pi', 'integer', typeof iFormula);
! }
!
! if ((iFormula != 0) && (iFormula != 1) && (iFormula != 2) && (iFormula != 3)) {
! throw vError = new IllegalValueException('Math.pi', 'iFormula', '0, 1, 2 or 3', iFormula);
}
|