Revision: 7302
Author: [email protected]
Date: Fri Dec 11 22:46:18 2009
Log: Fix most float rounding issues.  Still have problems with  
Float.MAX_VALUE,
plus the int/long minvalue conversions.

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

Modified:
  /changes/jat/bigdecimal/user/super/com/google/gwt/emul/java/lang/Float.java
   
/changes/jat/bigdecimal/user/super/com/google/gwt/emul/java/math/BigInteger.java
   
/changes/jat/bigdecimal/user/test/com/google/gwt/emultest/java/math/BigIntegerConvertTest.java

=======================================
---  
/changes/jat/bigdecimal/user/super/com/google/gwt/emul/java/lang/Float.java     
 
Fri Jun 13 17:45:25 2008
+++  
/changes/jat/bigdecimal/user/super/com/google/gwt/emul/java/lang/Float.java     
 
Fri Dec 11 22:46:18 2009
@@ -55,7 +55,13 @@
    }-*/;

    public static float parseFloat(String s) throws NumberFormatException {
-    return (float) __parseAndValidateDouble(s);
+    double doubleValue = __parseAndValidateDouble(s);
+    if (doubleValue > Float.MAX_VALUE) {
+      return Float.POSITIVE_INFINITY;
+    } else if (doubleValue < -Float.MAX_VALUE) {
+      return Float.NEGATIVE_INFINITY;
+    }
+    return (float) doubleValue;
    }

    public static String toString(float b) {
=======================================
---  
/changes/jat/bigdecimal/user/super/com/google/gwt/emul/java/math/BigInteger.java
         
Fri Dec 11 13:21:45 2009
+++  
/changes/jat/bigdecimal/user/super/com/google/gwt/emul/java/math/BigInteger.java
         
Fri Dec 11 22:46:18 2009
@@ -760,7 +760,7 @@
     */
    @Override
    public float floatValue() {
-    return (float) doubleValue();
+    return Float.parseFloat(this.toString());
    }

    /**
=======================================
---  
/changes/jat/bigdecimal/user/test/com/google/gwt/emultest/java/math/BigIntegerConvertTest.java
   
Fri Dec 11 13:21:45 2009
+++  
/changes/jat/bigdecimal/user/test/com/google/gwt/emultest/java/math/BigIntegerConvertTest.java
   
Fri Dec 11 22:46:18 2009
@@ -318,18 +318,18 @@
      String a = "-27467238";
      float result = -2.7467238E7f;
      float aNumber = new BigInteger(a).floatValue();
-    assertEquals("incorrect value", aNumber, result, 1);
+    assertEquals("incorrect value", result, aNumber, 1);
    }

    /**
-   * Convert a negative number to a doufloatble value. The number's bit  
length
+   * Convert a negative number to a double value. The number's bit length
     * is inside [63, 1024].
     */
    public void testFloatValueNegative2() {
      String a = "-27467238945723645782";
      float result = -2.7467239E19f;
      float aNumber = new BigInteger(a).floatValue();
-    assertEquals("incorrect value", aNumber, result, 1e12);
+    assertEquals("incorrect value", result, aNumber, 1e12);
    }

    /**
@@ -339,7 +339,7 @@
    public void testFloatValueNegativeInfinity1() {
      String a  
= 
"-2746723894572364578265426346273456972283746872364768676747462342342342342342342342323423423423423423426767456345745293762384756238475634563456845634568934568347586346578648576478568456457634875673845678456786587345873645767456834756745763457863485768475678465783456702897830296720476846578634576384567845678346573465786457863";
      float aNumber = new BigInteger(a).floatValue();
-    assertEquals("incorrect value", aNumber, Float.NEGATIVE_INFINITY);
+    assertEquals("incorrect value", Float.NEGATIVE_INFINITY, aNumber);
    }

    /**

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

Reply via email to