BigDecimal (valueOf): fix DiagBigDecimal val008, val013 tests; see patch #1016 on Savannah.
2003-02-07 Stephen Crawley <crawley@dstc.edu.au> * java/math/BigDecimal(valueOf): fix DiagBigDecimal val008, val013 tests; see patch #1016 on Savannah. 2003-02-07 Stephen Crawley <crawley@dstc.edu.au> * 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. From-SVN: r62540
This commit is contained in:
parent
b20fcd47a2
commit
364df9fc18
2 changed files with 54 additions and 18 deletions
|
@ -1,3 +1,15 @@
|
||||||
|
2003-02-07 Stephen Crawley <crawley@dstc.edu.au>
|
||||||
|
|
||||||
|
* java/math/BigDecimal(valueOf): fix DiagBigDecimal val008, val013
|
||||||
|
tests; see patch #1016 on Savannah.
|
||||||
|
|
||||||
|
2003-02-07 Stephen Crawley <crawley@dstc.edu.au>
|
||||||
|
|
||||||
|
* 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 <crawley@dstc.edu.au>
|
2003-02-07 Stephen Crawley <crawley@dstc.edu.au>
|
||||||
|
|
||||||
* java/beans/PropertyDescriptor.java
|
* java/beans/PropertyDescriptor.java
|
||||||
|
|
|
@ -178,15 +178,29 @@ public class BigDecimal extends Number implements Comparable
|
||||||
// Now parse exponent.
|
// Now parse exponent.
|
||||||
if (point < len)
|
if (point < len)
|
||||||
{
|
{
|
||||||
int exp = Integer.parseInt (num.substring (point + 1));
|
point++;
|
||||||
exp -= scale;
|
if (num.charAt(point) == '+')
|
||||||
if (exp > 0)
|
point++;
|
||||||
|
|
||||||
|
if (point >= len )
|
||||||
|
throw new NumberFormatException ("no exponent following e or E");
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
intVal = intVal.multiply (BigInteger.valueOf (10).pow (exp));
|
int exp = Integer.parseInt (num.substring (point));
|
||||||
scale = 0;
|
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)
|
public static BigDecimal valueOf (long val, int scale)
|
||||||
throws NumberFormatException
|
throws NumberFormatException
|
||||||
{
|
{
|
||||||
if (scale == 0)
|
if ((scale == 0) && ((int)val == val))
|
||||||
switch ((int) val)
|
switch ((int) val)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -431,19 +445,29 @@ public class BigDecimal extends Number implements Comparable
|
||||||
if (scale == 0)
|
if (scale == 0)
|
||||||
return bigStr;
|
return bigStr;
|
||||||
|
|
||||||
int point = bigStr.length() - scale;
|
|
||||||
boolean negative = (bigStr.charAt(0) == '-');
|
boolean negative = (bigStr.charAt(0) == '-');
|
||||||
StringBuffer sb = new StringBuffer(bigStr.length() + 1 +
|
|
||||||
(point <= 0 ? -point+1 : 0));
|
int point = bigStr.length() - scale - (negative ? 1 : 0);
|
||||||
if (negative)
|
|
||||||
sb.append('-');
|
StringBuffer sb = new StringBuffer(bigStr.length() + 2 +
|
||||||
while (point <= 0)
|
(point <= 0 ? (-point + 1) : 0));
|
||||||
|
if (point <= 0)
|
||||||
{
|
{
|
||||||
sb.append('0');
|
if (negative)
|
||||||
point++;
|
sb.append('-');
|
||||||
|
sb.append('0').append('.');
|
||||||
|
while (point < 0)
|
||||||
|
{
|
||||||
|
sb.append('0');
|
||||||
|
point++;
|
||||||
|
}
|
||||||
|
sb.append(bigStr.substring(negative ? 1 : 0));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.append(bigStr);
|
||||||
|
sb.insert(point + (negative ? 1 : 0), '.');
|
||||||
}
|
}
|
||||||
sb.append(bigStr.substring(negative ? 1 : 0));
|
|
||||||
sb.insert(point, '.');
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue