From 992e575b64a7cd3975a728342d1e4f837c0b90cc Mon Sep 17 00:00:00 2001 From: mark Date: Fri, 7 Feb 2003 21:05:12 +0000 Subject: [PATCH] 2003-02-07 Stephen Crawley * java/math/BigDecimal(valueOf): fix DiagBigDecimal val008, val013 tests; see patch #1016 on Savannah. 2003-02-07 Stephen Crawley * java/math/BigDecimal.java (BigDecimal): enhance parsing of exponents (toString): do not return Strings starting with . and - erroneously. Improves Mauve results to 12 of 600 instead of 16 of 338 on DiagBigDecimal. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@62540 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 12 ++++++++ libjava/java/math/BigDecimal.java | 60 +++++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 32167d5425e..493794200f7 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,17 @@ 2003-02-07 Stephen Crawley + * java/math/BigDecimal(valueOf): fix DiagBigDecimal val008, val013 + tests; see patch #1016 on Savannah. + +2003-02-07 Stephen Crawley + + * java/math/BigDecimal.java (BigDecimal): enhance parsing of exponents + (toString): do not return Strings starting with . and - erroneously. + Improves Mauve results to 12 of 600 instead of 16 of 338 on + DiagBigDecimal. + +2003-02-07 Stephen Crawley + * java/beans/PropertyDescriptor.java (PropertyDescriptor(String, Class)): Sanity check getter and setter methods. diff --git a/libjava/java/math/BigDecimal.java b/libjava/java/math/BigDecimal.java index 713ba08e151..9c6e194a016 100644 --- a/libjava/java/math/BigDecimal.java +++ b/libjava/java/math/BigDecimal.java @@ -178,15 +178,29 @@ public class BigDecimal extends Number implements Comparable // Now parse exponent. if (point < len) { - int exp = Integer.parseInt (num.substring (point + 1)); - exp -= scale; - if (exp > 0) + point++; + if (num.charAt(point) == '+') + point++; + + if (point >= len ) + throw new NumberFormatException ("no exponent following e or E"); + + try { - intVal = intVal.multiply (BigInteger.valueOf (10).pow (exp)); - scale = 0; + int exp = Integer.parseInt (num.substring (point)); + exp -= scale; + if (exp > 0) + { + intVal = intVal.multiply (BigInteger.valueOf (10).pow (exp)); + scale = 0; + } + else + scale = - exp; + } + catch (NumberFormatException ex) + { + throw new NumberFormatException ("malformed exponent"); } - else - scale = - exp; } } @@ -198,7 +212,7 @@ public class BigDecimal extends Number implements Comparable public static BigDecimal valueOf (long val, int scale) throws NumberFormatException { - if (scale == 0) + if ((scale == 0) && ((int)val == val)) switch ((int) val) { case 0: @@ -431,19 +445,29 @@ public class BigDecimal extends Number implements Comparable if (scale == 0) return bigStr; - int point = bigStr.length() - scale; boolean negative = (bigStr.charAt(0) == '-'); - StringBuffer sb = new StringBuffer(bigStr.length() + 1 + - (point <= 0 ? -point+1 : 0)); - if (negative) - sb.append('-'); - while (point <= 0) + + int point = bigStr.length() - scale - (negative ? 1 : 0); + + StringBuffer sb = new StringBuffer(bigStr.length() + 2 + + (point <= 0 ? (-point + 1) : 0)); + if (point <= 0) + { + if (negative) + sb.append('-'); + sb.append('0').append('.'); + while (point < 0) + { + sb.append('0'); + point++; + } + sb.append(bigStr.substring(negative ? 1 : 0)); + } + else { - sb.append('0'); - point++; + sb.append(bigStr); + sb.insert(point + (negative ? 1 : 0), '.'); } - sb.append(bigStr.substring(negative ? 1 : 0)); - sb.insert(point, '.'); return sb.toString(); } -- 2.11.4.GIT