[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: small patches for BigInteger, BigDecimal, Double
From: |
J. Russell Smyth |
Subject: |
Re: small patches for BigInteger, BigDecimal, Double |
Date: |
Wed, 25 Apr 2001 21:45:45 -0700 |
As requested!
Tom Tromey wrote:
> >>>>> ">" == J Russell Smyth <address@hidden> writes:
>
> >> I ran acrossed a few small problems with BigInteger, BigDecimal and
> >> Double, and gnu.java.io.decoder.DecoderEightBitLookup which I have
> >> corrected. Included here are the changes. These will need to be
> >> applied by hand!
>
> Could you resubmit these as uni- or context-diffs with ChangeLog
> entries? If so then I will check in the fixes.
>
> Tom
diff -ru -x CVS classpath/ChangeLog classpath.mine/ChangeLog
--- classpath/ChangeLog Wed Apr 25 21:40:09 2001
+++ classpath.mine/ChangeLog Wed Apr 25 21:37:26 2001
@@ -1,3 +1,18 @@
+2001-04-20 J. Russell Smyth <address@hidden>
+
+ * java/math/BigInteger.java
+ (forEachDigit): corrected ArrayIndexOutOfBounds exception
+
+ * java/math/BigDecimal.java
+ (ctor(String)): added exponent handling
+
+ * gnu/java/io/decode/DecoderEightBitLookup.java
+ (convertToChars): corrected table lookup index
+
+ * native/java.lang/Double.c
+ (toString): correted format specifiers for sprintf call to
+ give better precision
+
2001-04-20 Warren Levy <address@hidden>
* java/text/SimpleDateFormat.java
Only in classpath: configure.in
diff -ru -x CVS classpath/gnu/java/io/decode/DecoderEightBitLookup.java
classpath.mine/gnu/java/io/decode/DecoderEightBitLookup.java
--- classpath/gnu/java/io/decode/DecoderEightBitLookup.java Wed Apr 25
21:39:15 2001
+++ classpath.mine/gnu/java/io/decode/DecoderEightBitLookup.java Wed Apr
25 21:37:26 2001
@@ -98,7 +98,8 @@
int cbuf_offset)
{
for (int i = 0; i < len; i++)
- cbuf[cbuf_offset + i] = lookup_table[buf[buf_offset + i]];
+ cbuf[cbuf_offset + i] = lookup_table[buf[buf_offset+i] & 0xff];
+
return(cbuf);
}
diff -ru -x CVS classpath/java/math/BigDecimal.java
classpath.mine/java/math/BigDecimal.java
--- classpath/java/math/BigDecimal.java Wed Apr 25 21:39:18 2001
+++ classpath.mine/java/math/BigDecimal.java Wed Apr 25 21:37:26 2001
@@ -68,11 +68,31 @@
public BigDecimal (String num) throws NumberFormatException
{
+ String exponent;
+ int scaleAdj = 0;
+ int epos = num.indexOf('E');
+ if(epos == -1){
+ epos = num.indexOf('e');
+ }
+ if(epos != -1){
+ if(num.charAt(epos+1)=='+'){
+ // Skip '+' in exponent
+ exponent = num.substring(epos+2);
+ }else{
+ exponent = num.substring(epos+1);
+ }
+ scaleAdj = Integer.parseInt(exponent);
+ // Strip exponent
+ num = num.substring(0,epos);
+ }
int point = num.indexOf('.');
- this.intVal = new BigInteger (point == -1 ? num :
- num.substring (0, point) +
- num.substring (point + 1));
- scale = num.length() - (point == -1 ? num.length () : point + 1);
+ scale = num.length() - (point == -1 ? num.length () : point + 1) -
scaleAdj;
+ StringBuffer val = new StringBuffer(point == -1 ? num : num.substring
(0, point) + num.substring (point + 1));
+ // correct for negative scale as per BigDecimal javadoc
+ for(;scale<0;scale++){
+ val.append("0");
+ }
+ this.intVal = new BigInteger (val.toString());
}
public static BigDecimal valueOf (long val)
diff -ru -x CVS classpath/java/math/BigInteger.java
classpath.mine/java/math/BigInteger.java
--- classpath/java/math/BigInteger.java Wed Apr 25 21:39:18 2001
+++ classpath.mine/java/math/BigInteger.java Wed Apr 25 21:37:26 2001
@@ -61,11 +61,11 @@
if (str.charAt(0) == '-')
buf[i++] = '-';
- while (i < buf.length)
- if ((buf[i++] =
+ for( ; i < buf.length ; i++ )
+ if ((buf[i] =
Character.forDigit(Character.digit(str.charAt(i), radix), radix))
- == '\u0000')
- throw new NumberFormatException(str + " not valid in radix " + radix);
+ == '\u0000')
+ throw new NumberFormatException(str + " not valid in radix " +
radix);
return new String(buf);
}
diff -ru -x CVS classpath/native/java.lang/Double.c
classpath.mine/native/java.lang/Double.c
--- classpath/native/java.lang/Double.c Wed Apr 25 21:39:20 2001
+++ classpath.mine/native/java.lang/Double.c Wed Apr 25 21:37:26 2001
@@ -69,7 +69,7 @@
char buf[1024];
jstring retval;
- sprintf((char*)&buf, "%G", d);
+ sprintf(buf, "%.17G", d);
retval = (*env)->NewStringUTF(env, buf);
return retval;
}
- small patches for BigInteger, BigDecimal, Double, J. Russell Smyth, 2001/04/25
- Re: small patches for BigInteger, BigDecimal, Double, Erwin Bolwidt, 2001/04/25
- Re: small patches for BigInteger, BigDecimal, Double, Tom Tromey, 2001/04/25
- Re: small patches for BigInteger, BigDecimal, Double,
J. Russell Smyth <=
- Re: small patches for BigInteger, BigDecimal, Double, John Leuner, 2001/04/25