Author: luc
Date: Mon Jan 24 19:14:02 2011
New Revision: 1062929

URL: http://svn.apache.org/viewvc?rev=1062929&view=rev
Log:
fixed scalb for very large powers

Modified:
    
commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
    
commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java

Modified: 
commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1062929&r1=1062928&r2=1062929&view=diff
==============================================================================
--- 
commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
 (original)
+++ 
commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/FastMath.java
 Mon Jan 24 19:14:02 2011
@@ -3421,6 +3421,12 @@ public class FastMath {
         if (Double.isNaN(d) || Double.isInfinite(d) || (d == 0)) {
             return d;
         }
+        if (n < -2098) {
+            return (d > 0) ? 0.0 : -0.0;
+        }
+        if (n > 2097) {
+            return (d > 0) ? Double.POSITIVE_INFINITY : 
Double.NEGATIVE_INFINITY;
+        }
 
         // decompose d
         final long bits = Double.doubleToLongBits(d);
@@ -3499,6 +3505,12 @@ public class FastMath {
         if (Float.isNaN(f) || Float.isInfinite(f) || (f == 0f)) {
             return f;
         }
+        if (n < -277) {
+            return (f > 0) ? 0.0f : -0.0f;
+        }
+        if (n > 276) {
+            return (f > 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
+        }
 
         // decompose f
         final int bits = Float.floatToIntBits(f);

Modified: 
commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java?rev=1062929&r1=1062928&r2=1062929&view=diff
==============================================================================
--- 
commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java
 (original)
+++ 
commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java
 Mon Jan 24 19:14:02 2011
@@ -1061,6 +1061,12 @@ public class FastMathTest {
         Assert.assertEquals(Double.NEGATIVE_INFINITY, 
FastMath.scalb(-1.1102230246251565E-16,  1079), 0D);
         Assert.assertEquals(Double.NEGATIVE_INFINITY, 
FastMath.scalb(-2.2250738585072014E-308, 2047), 0D);
         Assert.assertEquals(Double.NEGATIVE_INFINITY, 
FastMath.scalb(-2.2250738585072014E-308, 2048), 0D);
+        Assert.assertEquals(Double.NEGATIVE_INFINITY, 
FastMath.scalb(-1.7976931348623157E308,  2147483647), 0D);
+        Assert.assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 
1.7976931348623157E308,  2147483647), 0D);
+        Assert.assertEquals(Double.NEGATIVE_INFINITY, 
FastMath.scalb(-1.1102230246251565E-16,  2147483647), 0D);
+        Assert.assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 
1.1102230246251565E-16,  2147483647), 0D);
+        Assert.assertEquals(Double.NEGATIVE_INFINITY, 
FastMath.scalb(-2.2250738585072014E-308, 2147483647), 0D);
+        Assert.assertEquals(Double.POSITIVE_INFINITY, FastMath.scalb( 
2.2250738585072014E-308, 2147483647), 0D);
     }
 
     @Test
@@ -1077,6 +1083,8 @@ public class FastMathTest {
         Assert.assertEquals(Float.POSITIVE_INFINITY,  
FastMath.scalb(Float.POSITIVE_INFINITY, -1000000), 0F);
         Assert.assertEquals(-3.13994498e38f,          FastMath.scalb(-1.1e-7f, 
        151), 0F);
         Assert.assertEquals(Float.NEGATIVE_INFINITY,  FastMath.scalb(-1.1e-7f, 
        152), 0F);
+        Assert.assertEquals(Float.POSITIVE_INFINITY,  
FastMath.scalb(3.4028235E38f,  2147483647), 0F);
+        Assert.assertEquals(Float.NEGATIVE_INFINITY,  
FastMath.scalb(-3.4028235E38f, 2147483647), 0F);;
     }
 
     private boolean compareClassMethods(Class<?> class1, Class<?> class2){


Reply via email to