Kaydet (Commit) 177183f6 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Proper fix for coverity#1326893

FindBugs' FE.FE_FLOATING_POINT_EQUALITY is about double value inaccuracies, not
about NaN or negative zero (which is the topic of java.lang.Double.equals vs.
==).

Reuse existing qa.TestCaseOldAPI.approxEqual method, moved to util.utils.

Change-Id: I65f7bb1faf921e1c4035bb96aeff1eaf2cfb3153
üst 5a29db7a
......@@ -32,8 +32,8 @@ import com.sun.star.awt.*;
import com.sun.star.container.*;
import com.sun.star.util.XCloseable;
import com.sun.star.util.CloseVetoException;
import com.sun.star.uno.AnyConverter;
import util.utils;
/**
* The following Complex Test will test the
......@@ -360,7 +360,7 @@ public class TestCaseOldAPI extends ComplexTestCase {
assure( "AutoMax is on", ! AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMax" )) );
assure( "Maximum value invalid",
approxEqual(
utils.approxEqual(
AnyConverter.toDouble( xProp.getPropertyValue( "Max" )),
nNewMax ));
......@@ -369,7 +369,7 @@ public class TestCaseOldAPI extends ComplexTestCase {
xProp.setPropertyValue( "Origin", new Double( nNewOrigin ));
assure( "Origin invalid",
approxEqual(
utils.approxEqual(
AnyConverter.toDouble( xProp.getPropertyValue( "Origin" )),
nNewOrigin ));
xProp.setPropertyValue( "AutoOrigin", Boolean.TRUE);
......@@ -942,19 +942,6 @@ public class TestCaseOldAPI extends ComplexTestCase {
return aResult;
}
/// see rtl/math.hxx
private boolean approxEqual( double a, double b )
{
if( a == b )
return true;
double x = a - b;
return (x < 0.0 ? -x : x)
< ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 * 16777216.0)));
}
/** returns true if a and b differ no more than tolerance.
@param tolerance
......
......@@ -874,4 +874,14 @@ public class utils {
* Default short wait time for the Office
*/
public static final int DEFAULT_SHORT_WAIT_MS = 500;
/// see rtl/math.hxx
public static boolean approxEqual( double a, double b )
{
if( a == b )
return true;
double x = a - b;
return (x < 0.0 ? -x : x)
< ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 * 16777216.0)));
}
}
......@@ -19,6 +19,7 @@
package ifc.table;
import lib.MultiMethodTest;
import util.utils;
import com.sun.star.table.CellContentType;
import com.sun.star.table.XCell;
......@@ -149,7 +150,7 @@ public class _XCell extends MultiMethodTest {
oObj.setValue(inValue) ;
double cellValue = oObj.getValue() ;
boolean result = Double.valueOf(cellValue).equals(inValue);
boolean result = utils.approxEqual(cellValue, inValue);
tRes.tested("setValue()", result);
} // end setValue()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment