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)
51 jlong e = u.l & 0x7ff0000000000000LL;
52 jlong f = u.l & 0x000fffffffffffffLL;
54 if (e == 0x7ff0000000000000LL && f != 0L)
55 u.l = 0x7ff8000000000000LL;
61 java::lang::Double::longBitsToDouble(jlong bits)
69 java::lang::Double::toString(jdouble value, jboolean isFloat)
72 return JvNewStringLatin1 ("NaN", sizeof ("NaN") - 1);
74 if (value == POSITIVE_INFINITY)
75 return JvNewStringLatin1 ("Infinity", sizeof ("Infinity") - 1);
77 if (value == NEGATIVE_INFINITY)
78 return JvNewStringLatin1 ("-Infinity", sizeof ("-Infinity") - 1);
80 char buffer[50], result[50];
83 _dtoa (value, 0, 20, &decpt, &sign, NULL, buffer, (int)isFloat);
93 if (value >= 1e-3 && value < 1e7 || value == 0)
99 for (int i = 0; i < decpt; i++)
122 return JvNewStringLatin1 (result, strlen (result));
145 char *e = exp + sizeof exp;
150 *--e = '0' + decpt % 10;
161 return JvNewStringLatin1 (result, strlen (result));
165 java::lang::Double::doubleValueOf(jstring str)
167 int length = str->length();
168 // Note that UTF can expand 3x.
171 char *data = (char *) alloca (3 * length + 1);
173 #error --- need an alternate implementation here ---
176 data[_Jv_GetStringUTFRegion (str, 0, length, data)] = 0;
178 struct _Jv_reent reent;
179 memset (&reent, 0, sizeof reent);
181 double val = _strtod_r (&reent, data, NULL);
184 _Jv_Throw (new NumberFormatException);