1 // natDouble.cc - Implementation of java.lang.Double native methods.
3 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
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
20 #include <java/lang/String.h>
21 #include <java/lang/Double.h>
22 #include <java/lang/NumberFormatException.h>
37 java::lang::Double::doubleToLongBits(jdouble value)
42 jlong e = u.l & 0x7ff0000000000000LL;
43 jlong f = u.l & 0x000fffffffffffffLL;
45 if (e == 0x7ff0000000000000LL && f != 0L)
46 u.l = 0x7ff8000000000000LL;
52 java::lang::Double::doubleToRawLongBits(jdouble value)
60 java::lang::Double::longBitsToDouble(jlong bits)
68 java::lang::Double::toString(jdouble value, jboolean isFloat)
71 return JvNewStringLatin1 ("NaN", sizeof ("NaN") - 1);
73 if (value == POSITIVE_INFINITY)
74 return JvNewStringLatin1 ("Infinity", sizeof ("Infinity") - 1);
76 if (value == NEGATIVE_INFINITY)
77 return JvNewStringLatin1 ("-Infinity", sizeof ("-Infinity") - 1);
79 char buffer[50], result[50];
82 _dtoa (value, 0, 20, &decpt, &sign, NULL, buffer, (int)isFloat);
92 if (value >= 1e-3 && value < 1e7 || value == 0)
98 for (int i = 0; i < decpt; i++)
121 return JvNewStringLatin1 (result, strlen (result));
144 char *e = exp + sizeof exp;
149 *--e = '0' + decpt % 10;
160 return JvNewStringLatin1 (result, strlen (result));
164 java::lang::Double::parseDouble(jstring str)
166 int length = str->length();
167 // Note that UTF can expand 3x.
170 char *data = (char *) alloca (3 * length + 1);
172 #error --- need an alternate implementation here ---
175 data[_Jv_GetStringUTFRegion (str, 0, length, data)] = 0;
177 struct _Jv_reent reent;
178 memset (&reent, 0, sizeof reent);
180 double val = _strtod_r (&reent, data, NULL);
183 _Jv_Throw (new NumberFormatException);