Revision: 9407
Author: [email protected]
Date: Fri Dec 10 11:30:52 2010
Log: Fix a problem with BigDecimal, where the bitlength of a zero value
was not being computed properly.

Patch by: jat
Review by: conroy, janz

http://code.google.com/p/google-web-toolkit/source/detail?r=9407

Modified:
 /trunk/user/super/com/google/gwt/emul/java/math/BigDecimal.java
/trunk/user/test/com/google/gwt/emultest/java/math/BigDecimalConstructorsTest.java

=======================================
--- /trunk/user/super/com/google/gwt/emul/java/math/BigDecimal.java Mon Jun 7 12:20:31 2010 +++ /trunk/user/super/com/google/gwt/emul/java/math/BigDecimal.java Fri Dec 10 11:30:52 2010
@@ -309,6 +309,10 @@
   private static int bitLength(double value) {
     // if |value| is less than 2^47, use log
     if (value > -POW47 && value < POW47) {
+      if (value == 0.0) {
+        // special-case zero, otherwise we get -INFINITY below
+        return 0;
+      }
       boolean negative = (value < 0.0);
       if (negative) {
         value = -value;
=======================================
--- /trunk/user/test/com/google/gwt/emultest/java/math/BigDecimalConstructorsTest.java Thu Mar 25 10:46:07 2010 +++ /trunk/user/test/com/google/gwt/emultest/java/math/BigDecimalConstructorsTest.java Fri Dec 10 11:30:52 2010
@@ -722,6 +722,24 @@
     assertEquals("incorrect value", bA, aNumber.unscaledValue());
     assertEquals("incorrect scale", aScale, aNumber.scale());
   }
+
+  /**
+   * Test that constructing BigDecimals from zeros works properly.
+   */
+  public void testConstrZero() {
+    BigDecimal bd = new BigDecimal("0");
+    assertEquals(0, bd.intValueExact());
+    assertEquals(1, bd.precision());
+    assertEquals(0, bd.scale());
+    bd = new BigDecimal("0.0");
+    assertEquals(0, bd.intValueExact());
+    assertEquals(1, bd.precision());
+    assertEquals(1, bd.scale());
+    bd = new BigDecimal("0.00");
+    assertEquals(0, bd.intValueExact());
+    assertEquals(1, bd.precision());
+    assertEquals(2, bd.scale());
+  }

   /**
    * check ONE.

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to