Bug 613492 - Remove Infinity and NaN checks from dtoa, so that isNaN(parseFloat("infinity")). r=jwalden
authorJan de Mooij <jandemooij@gmail.com>
Fri, 19 Nov 2010 13:56:27 +0100
changeset 58296 1b24f8e54d1b9ea9d9f1b9a46e0b1eceafdfe649
parent 58295 9123f97f059c4aba1af51ea6b657be1d21d45ea1
child 58297 91c193d27482d84d44a0d3a98fff7c2d58db8d98
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersjwalden
bugs613492
milestone2.0b8pre
Bug 613492 - Remove Infinity and NaN checks from dtoa, so that isNaN(parseFloat("infinity")). r=jwalden
js/src/dtoa.c
js/src/tests/ecma_5/Global/jstests.list
js/src/tests/ecma_5/Global/parseFloat-01.js
--- a/js/src/dtoa.c
+++ b/js/src/dtoa.c
@@ -111,23 +111,16 @@
  *	unless #defined to be a different length.  This default length
  *	suffices to get rid of MALLOC calls except for unusual cases,
  *	such as decimal-to-binary conversion of a very long string of
  *	digits.  The longest string dtoa can return is about 751 bytes
  *	long.  For conversions by strtod of strings of 800 digits and
  *	all dtoa conversions in single-threaded executions with 8-byte
  *	pointers, PRIVATE_MEM >= 7400 appears to suffice; with 4-byte
  *	pointers, PRIVATE_MEM >= 7112 appears adequate.
- * #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK
- *	#defined automatically on IEEE systems.  On such systems,
- *	when INFNAN_CHECK is #defined, strtod checks
- *	for Infinity and NaN (case insensitively).  On some systems
- *	(e.g., some HP systems), it may be necessary to #define NAN_WORD0
- *	appropriately -- to the most significant word of a quiet NaN.
- *	(On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
  * #define MULTIPLE_THREADS if the system offers preemptively scheduled
  *	multiple threads.  In this case, you must provide (or suitably
  *	#define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
  *	by FREE_DTOA_LOCK(n) for n = 0 or 1.  (The second lock, accessed
  *	in pow5mult, ensures lazy evaluation of only one copy of high
  *	powers of 5; omitting this lock would introduce a small
  *	probability of wasting memory, but would otherwise be harmless.)
  *	You must also invoke freedtoa(s) to free the value s returned by
@@ -207,25 +200,16 @@ extern void *MALLOC(size_t);
 #undef Avoid_Underflow
 #ifdef IEEE_MC68k
 #define IEEE_Arith
 #endif
 #ifdef IEEE_8087
 #define IEEE_Arith
 #endif
 
-#ifdef IEEE_Arith
-#ifndef NO_INFNAN_CHECK
-#undef INFNAN_CHECK
-#define INFNAN_CHECK
-#endif
-#else
-#undef INFNAN_CHECK
-#endif
-
 #include "errno.h"
 
 #ifdef Bad_float_h
 
 #ifdef IEEE_Arith
 #define DBL_DIG 15
 #define DBL_MAX_10_EXP 308
 #define DBL_MAX_EXP 1024
@@ -1485,49 +1469,16 @@ static CONST double tinytens[] = { 1e-16
 #define n_bigtens 3
 #else
 bigtens[] = { 1e16, 1e32 };
 static CONST double tinytens[] = { 1e-16, 1e-32 };
 #define n_bigtens 2
 #endif
 #endif
 
-#ifdef INFNAN_CHECK
-
-#ifndef NAN_WORD0
-#define NAN_WORD0 0x7ff80000
-#endif
-
-#ifndef NAN_WORD1
-#define NAN_WORD1 0
-#endif
-
- static int
-match
-#ifdef KR_headers
-	(sp, t) char **sp, *t;
-#else
-	(CONST char **sp, CONST char *t)
-#endif
-{
-	int c, d;
-	CONST char *s = *sp;
-
-	while((d = *t++)) {
-		if ((c = *++s) >= 'A' && c <= 'Z')
-			c += 'a' - 'A';
-		if (c != d)
-			return 0;
-		}
-	*sp = s + 1;
-	return 1;
-	}
-
-#endif /* INFNAN_CHECK */
-
  static double
 _strtod
 #ifdef KR_headers
 	(STATE_PARAM s00, se) STATE_PARAM_DECL CONST char *s00; char **se;
 #else
 	(STATE_PARAM CONST char *s00, char **se)
 #endif
 {
@@ -1678,39 +1629,16 @@ match
 			else
 				e = 0;
 			}
 		else
 			s = s00;
 		}
 	if (!nd) {
 		if (!nz && !nz0) {
-#ifdef INFNAN_CHECK
-			/* Check for Nan and Infinity */
-			switch(c) {
-			  case 'i':
-			  case 'I':
-				if (match(&s,"nf")) {
-					--s;
-					if (!match(&s,"inity"))
-						++s;
-					word0(rv) = 0x7ff00000;
-					word1(rv) = 0;
-					goto ret;
-					}
-				break;
-			  case 'n':
-			  case 'N':
-				if (match(&s, "an")) {
-					word0(rv) = NAN_WORD0;
-					word1(rv) = NAN_WORD1;
-					goto ret;
-					}
-			  }
-#endif /* INFNAN_CHECK */
  ret0:
 			s = s00;
 			sign = 0;
 			}
 		goto ret;
 		}
 	e1 = e -= nf;
 
--- a/js/src/tests/ecma_5/Global/jstests.list
+++ b/js/src/tests/ecma_5/Global/jstests.list
@@ -1,8 +1,9 @@
 url-prefix ../../jsreftest.html?test=ecma_5/Global/
 script parseInt-01.js
+script parseFloat-01.js
 script eval-01.js
 script eval-02.js
 script eval-inside-with-is-direct.js
 script parenthesized-eval-is-direct.js
 script eval-native-callback-is-indirect.js
 script direct-eval-but-not.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/Global/parseFloat-01.js
@@ -0,0 +1,24 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 613492;
+var summary = "ES5 15.1.2.3 parseFloat(string)";
+
+print(BUGNUMBER + ": " + summary);
+
+assertEq(parseFloat("Infinity"), Infinity);
+assertEq(parseFloat("+Infinity"), Infinity);
+assertEq(parseFloat("-Infinity"), -Infinity);
+
+assertEq(parseFloat("inf"), NaN);
+assertEq(parseFloat("Inf"), NaN);
+assertEq(parseFloat("infinity"), NaN);
+
+assertEq(parseFloat("nan"), NaN);
+assertEq(parseFloat("NaN"), NaN);
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("All tests passed!");