MATH-482 FastMath.max(50.0f, -50.0f) => -50.0f; should be +50.0f

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1060065 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2011-01-17 20:00:57 +00:00
parent d3dda59bef
commit 7aabd3b5a2
3 changed files with 14 additions and 10 deletions

View File

@ -3479,7 +3479,7 @@ public class FastMath {
* @return b if a is lesser or equal to b, a otherwise * @return b if a is lesser or equal to b, a otherwise
*/ */
public static float max(final float a, final float b) { public static float max(final float a, final float b) {
return (a <= b) ? b : (Float.isNaN(a + b) ? Float.NaN : b); return (a <= b) ? b : (Float.isNaN(a + b) ? Float.NaN : a);
} }
/** Compute the maximum of two values /** Compute the maximum of two values

View File

@ -52,6 +52,10 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces! If the output is not quite correct, check for invisible trailing spaces!
--> -->
<release version="2.2" date="TBD" description="TBD"> <release version="2.2" date="TBD" description="TBD">
<action dev="sebb" type="fix" issue="MATH-482">
FastMath.max(50.0f, -50.0f) => -50.0f; should be +50.0f
Fixed FastMath.max(float, float) so it returns correct value.
</action>
<action dev="luc" type="fix" issue="MATH-467"> <action dev="luc" type="fix" issue="MATH-467">
Fixed an awkward statement that triggered a false positive warning. Fixed an awkward statement that triggered a false positive warning.
</action> </action>

View File

@ -76,18 +76,18 @@ public class FastMathTest {
@Test @Test
public void testMinMaxFloat() { public void testMinMaxFloat() {
double[][] pairs = { float[][] pairs = {
{ -50.0, 50.0 }, { -50.0f, 50.0f },
{ Float.POSITIVE_INFINITY, 1.0 }, { Float.POSITIVE_INFINITY, 1.0f },
{ Float.NEGATIVE_INFINITY, 1.0 }, { Float.NEGATIVE_INFINITY, 1.0f },
{ Float.NaN, 1.0 }, { Float.NaN, 1.0f },
{ Float.POSITIVE_INFINITY, 0.0 }, { Float.POSITIVE_INFINITY, 0.0f },
{ Float.NEGATIVE_INFINITY, 0.0 }, { Float.NEGATIVE_INFINITY, 0.0f },
{ Float.NaN, 0.0 }, { Float.NaN, 0.0f },
{ Float.NaN, Float.NEGATIVE_INFINITY }, { Float.NaN, Float.NEGATIVE_INFINITY },
{ Float.NaN, Float.POSITIVE_INFINITY } { Float.NaN, Float.POSITIVE_INFINITY }
}; };
for (double[] pair : pairs) { for (float[] pair : pairs) {
Assert.assertEquals("min(" + pair[0] + ", " + pair[1] + ")", Assert.assertEquals("min(" + pair[0] + ", " + pair[1] + ")",
Math.min(pair[0], pair[1]), Math.min(pair[0], pair[1]),
FastMath.min(pair[0], pair[1]), FastMath.min(pair[0], pair[1]),