I'm committing the attached patch to fix PR#27311. The exponent shouldn't be calculated when the number is 0 or below, as the log is either negative infinity or NaN. We can also now use log10 rather than dividing two separate logarithms.
I'll commit this to the release branch as well.
Changelog:
2006-05-07 Andrew John Hughes <[EMAIL PROTECTED]>
* gnu/java/text/StringFormatBuffer.java:
(toString()): Implemented so we can see the contents.
* java/text/DecimalFormat.java:
(formatInternal(double,StringFormatBuffer,FieldPosition)):
Don't calculate the exponent when the number is 0 or less.
Also, use log10 instead of log now it's available.
--
Andrew :-)
Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
If you use Microsoft Office, support movement towards the end of vendor lock-in:
http://opendocumentfellowship.org/petition/
"Value your freedom, or you will lose it, teaches history.
`Don't bother us with politics' respond those who don't want to learn."
-- Richard Stallman
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: gnu/java/text/StringFormatBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/text/StringFormatBuffer.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 StringFormatBuffer.java
--- gnu/java/text/StringFormatBuffer.java 2 Jul 2005 20:32:15 -0000
1.2
+++ gnu/java/text/StringFormatBuffer.java 7 May 2006 19:29:43 -0000
@@ -118,4 +118,10 @@ public class StringFormatBuffer implemen
{
return buffer;
}
+
+ public String toString()
+ {
+ return buffer.toString();
+ }
+
}
Index: java/text/DecimalFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DecimalFormat.java,v
retrieving revision 1.25
diff -u -3 -p -u -r1.25 DecimalFormat.java
--- java/text/DecimalFormat.java 7 Dec 2005 15:12:21 -0000 1.25
+++ java/text/DecimalFormat.java 7 May 2006 19:29:44 -0000
@@ -542,9 +542,9 @@ public class DecimalFormat extends Numbe
// Compute exponent.
long exponent = 0;
double baseNumber;
- if (useExponentialNotation)
+ if (useExponentialNotation && number > 0)
{
- exponent = (long) Math.floor (Math.log(number) / Math.log(10));
+ exponent = (long) Math.floor (Math.log10(number));
exponent = exponent - (exponent % exponentRound);
if (minimumIntegerDigits > 0)
exponent -= minimumIntegerDigits - 1;
@@ -654,7 +654,7 @@ public class DecimalFormat extends Numbe
index = dest.length();
dest.setDefaultAttribute(NumberFormat.Field.EXPONENT);
String exponentString = Long.toString ((long) exponent);
-
+
for (count = 0; count < minExponentDigits-exponentString.length();
count++)
dest.append((char) symbols.getZeroDigit());
signature.asc
Description: Digital signature
