1 // natDouble.cc - Implementation of java.lang.Double native methods.
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 /* AIX requires this to be the first thing in the file. */
19 # ifndef alloca /* predefined by HP cc +Olibcalls */
29 #include <java/lang/String.h>
30 #include <java/lang/Double.h>
31 #include <java/lang/NumberFormatException.h>
46 java::lang::Double::doubleToLongBits(jdouble value)
54 java::lang::Double::longBitsToDouble(jlong bits)
62 java::lang::Double::toString(jdouble value, jboolean isFloat)
65 return JvNewStringLatin1 ("NaN", sizeof ("NaN") - 1);
67 if (value == POSITIVE_INFINITY)
68 return JvNewStringLatin1 ("Infinity", sizeof ("Infinity") - 1);
70 if (value == NEGATIVE_INFINITY)
71 return JvNewStringLatin1 ("-Infinity", sizeof ("-Infinity") - 1);
73 char buffer[50], result[50];
76 _dtoa (value, 0, 20, &decpt, &sign, NULL, buffer, (int)isFloat);
86 if (value >= 1e-3 && value < 1e7 || value == 0)
92 for (int i = 0; i < decpt; i++)
115 return JvNewStringLatin1 (result, strlen (result));
138 char *e = exp + sizeof exp;
143 *--e = '0' + decpt % 10;
154 return JvNewStringLatin1 (result, strlen (result));
158 java::lang::Double::doubleValueOf(jstring str)
160 int length = str->length();
161 // Note that UTF can expand 3x.
164 char *data = (char *) alloca (3 * length + 1);
166 #error --- need an alternate implementation here ---
169 data[_Jv_GetStringUTFRegion (str, 0, length, data)] = 0;
171 struct _Jv_reent reent;
172 memset (&reent, 0, sizeof reent);
174 double val = _strtod_r (&reent, data, NULL);
177 _Jv_Throw (new NumberFormatException);