OSDN Git Service

* exception.cc (java_eh_info): Make value type jthrowable.
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / natDouble.cc
index 49ec680..7e8e0b7 100644 (file)
@@ -1,6 +1,6 @@
 // natDouble.cc - Implementation of java.lang.Double native methods.
 
-/* Copyright (C) 1998, 1999  Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -10,33 +10,19 @@ details.  */
 
 #include <config.h>
 
-/* AIX requires this to be the first thing in the file.  */
-#ifndef __GNUC__
-# if HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  ifdef _AIX
- #pragma alloca
-#  else
-#   ifndef alloca /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#   endif
-#  endif
-# endif
-#endif
-
 #include <stdlib.h>
 
 #include <gcj/cni.h>
 #include <java/lang/String.h>
 #include <java/lang/Double.h>
+#include <java/lang/Character.h>
 #include <java/lang/NumberFormatException.h>
 #include <jvm.h>
 
 #include <stdio.h>
 #include <string.h>
 
-#include "mprec.h"
+#include "fdlibm.h"
 
 union u
 {
@@ -59,6 +45,14 @@ java::lang::Double::doubleToLongBits(jdouble value)
   return u.l;
 }
 
+jlong 
+java::lang::Double::doubleToRawLongBits(jdouble value)
+{
+  union u u;
+  u.d = value;
+  return u.l;
+}
+
 jdouble 
 java::lang::Double::longBitsToDouble(jlong bits)
 {
@@ -164,26 +158,31 @@ java::lang::Double::toString(jdouble value, jboolean isFloat)
 }
 
 jdouble 
-java::lang::Double::doubleValueOf(jstring str)
+java::lang::Double::parseDouble(jstring str)
 {
   int length = str->length();
-  // Note that UTF can expand 3x.
-
-#ifdef HAVE_ALLOCA
-  char *data = (char *) alloca (3 * length + 1);
-#else
-#error --- need an alternate implementation here ---
-#endif
-
-  data[_Jv_GetStringUTFRegion (str, 0, length, data)] = 0; 
-
-  struct _Jv_reent reent;  
-  memset (&reent, 0, sizeof reent);
-
-  double val = _strtod_r (&reent, data, NULL);
-
-  if (reent._errno)
-    _Jv_Throw (new NumberFormatException);
-
-  return val;
+  while (length > 0
+        && Character::isWhitespace(str->charAt(length - 1)))
+    length--;
+  jsize start = 0;
+  while (length > 0
+        && Character::isWhitespace(str->charAt(start)))
+    start++, length--;
+
+  if (length > 0)
+    {
+      // Note that UTF can expand 3x.
+      char *data = (char *) __builtin_alloca (3 * length + 1);
+      jsize blength = _Jv_GetStringUTFRegion (str, start, length, data);
+      data[blength] = 0; 
+
+      struct _Jv_reent reent;  
+      memset (&reent, 0, sizeof reent);
+
+      char *endptr;
+      double val = _strtod_r (&reent, data, &endptr);
+      if (endptr == data + blength)
+       return val;
+    }
+  throw new NumberFormatException;
 }