You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Yannick TANGUY (JIRA)" <ji...@apache.org> on 2012/09/20 10:15:07 UTC
[jira] [Created] (MATH-866) New method to compute relative
deviation between two floating numbers
Yannick TANGUY created MATH-866:
-----------------------------------
Summary: New method to compute relative deviation between two floating numbers
Key: MATH-866
URL: https://issues.apache.org/jira/browse/MATH-866
Project: Commons Math
Issue Type: Improvement
Affects Versions: 3.1
Reporter: Yannick TANGUY
A new method to compute a relative deviation would be very useful.
In order to handle properly odd values (O+,0-,NaN,Infinity), we suggest to call first the classical equals() method (strict equality, using one ulp as a threshold) and then the relative tolerance.
Here is the code we use :
public static boolean equalsWithRelativeTolerance(final double x, final double y, final double eps) {
// Initialisation
boolean isEqual = false;
// very close (including both equals 0.0) case
if (equals(x, y)) {
isEqual = true;
}
// common case
else {
// Relative difference computation
final double absoluteMax = FastMath.max(FastMath.abs(x), FastMath.abs(y));
final double relativeDifference = FastMath.abs((x - y) / absoluteMax);
//test
if (relativeDifference < eps) {
isEqual = true;
}
}
return isEqual;
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (MATH-866) New method to compute relative
deviation between two floating numbers
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-866?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gilles updated MATH-866:
------------------------
Description:
A new method to compute a relative deviation would be very useful.
In order to handle properly odd values (O+,0-,NaN,Infinity), we suggest to call first the classical equals() method (strict equality, using one ulp as a threshold) and then the relative tolerance.
Here is the code we use :
{noformat}
public static boolean equalsWithRelativeTolerance(final double x, final double y, final double eps) {
// Initialisation
boolean isEqual = false;
// very close (including both equals 0.0) case
if (equals(x, y)) {
isEqual = true;
}
// common case
else {
// Relative difference computation
final double absoluteMax = FastMath.max(FastMath.abs(x), FastMath.abs(y));
final double relativeDifference = FastMath.abs((x - y) / absoluteMax);
//test
if (relativeDifference < eps) {
isEqual = true;
}
}
return isEqual;
}
{noformat}
was:
A new method to compute a relative deviation would be very useful.
In order to handle properly odd values (O+,0-,NaN,Infinity), we suggest to call first the classical equals() method (strict equality, using one ulp as a threshold) and then the relative tolerance.
Here is the code we use :
public static boolean equalsWithRelativeTolerance(final double x, final double y, final double eps) {
// Initialisation
boolean isEqual = false;
// very close (including both equals 0.0) case
if (equals(x, y)) {
isEqual = true;
}
// common case
else {
// Relative difference computation
final double absoluteMax = FastMath.max(FastMath.abs(x), FastMath.abs(y));
final double relativeDifference = FastMath.abs((x - y) / absoluteMax);
//test
if (relativeDifference < eps) {
isEqual = true;
}
}
return isEqual;
}
> New method to compute relative deviation between two floating numbers
> ---------------------------------------------------------------------
>
> Key: MATH-866
> URL: https://issues.apache.org/jira/browse/MATH-866
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.1
> Reporter: Yannick TANGUY
> Fix For: 3.1
>
>
> A new method to compute a relative deviation would be very useful.
> In order to handle properly odd values (O+,0-,NaN,Infinity), we suggest to call first the classical equals() method (strict equality, using one ulp as a threshold) and then the relative tolerance.
> Here is the code we use :
> {noformat}
> public static boolean equalsWithRelativeTolerance(final double x, final double y, final double eps) {
> // Initialisation
> boolean isEqual = false;
> // very close (including both equals 0.0) case
> if (equals(x, y)) {
> isEqual = true;
> }
> // common case
> else {
> // Relative difference computation
> final double absoluteMax = FastMath.max(FastMath.abs(x), FastMath.abs(y));
> final double relativeDifference = FastMath.abs((x - y) / absoluteMax);
> //test
> if (relativeDifference < eps) {
> isEqual = true;
> }
> }
> return isEqual;
> }
> {noformat}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (MATH-866) New method to compute relative
deviation between two floating numbers
Posted by "Gilles (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/MATH-866?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gilles resolved MATH-866.
-------------------------
Resolution: Fixed
Fix Version/s: 3.1
Committed revision 1387941.
> New method to compute relative deviation between two floating numbers
> ---------------------------------------------------------------------
>
> Key: MATH-866
> URL: https://issues.apache.org/jira/browse/MATH-866
> Project: Commons Math
> Issue Type: Improvement
> Affects Versions: 3.1
> Reporter: Yannick TANGUY
> Fix For: 3.1
>
>
> A new method to compute a relative deviation would be very useful.
> In order to handle properly odd values (O+,0-,NaN,Infinity), we suggest to call first the classical equals() method (strict equality, using one ulp as a threshold) and then the relative tolerance.
> Here is the code we use :
> public static boolean equalsWithRelativeTolerance(final double x, final double y, final double eps) {
> // Initialisation
> boolean isEqual = false;
> // very close (including both equals 0.0) case
> if (equals(x, y)) {
> isEqual = true;
> }
> // common case
> else {
> // Relative difference computation
> final double absoluteMax = FastMath.max(FastMath.abs(x), FastMath.abs(y));
> final double relativeDifference = FastMath.abs((x - y) / absoluteMax);
> //test
> if (relativeDifference < eps) {
> isEqual = true;
> }
> }
> return isEqual;
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira