本文整理了Java中org.apache.commons.math3.util.Precision.equals()
方法的一些代码示例,展示了Precision.equals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Precision.equals()
方法的具体详情如下:
包路径:org.apache.commons.math3.util.Precision
类名称:Precision
方法名:equals
[英]Returns true iff they are equal as defined by #equals(double,double,int).
[中]如果它们等于#equals(double,double,int)定义的值,则返回true。
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns true if both arguments are NaN or they are
* equal as defined by {@link #equals(float,float) equals(x, y, 1)}.
*
* @param x first value
* @param y second value
* @return {@code true} if the values are equal or both are NaN.
* @since 2.2
*/
public static boolean equalsIncludingNaN(float x, float y) {
return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, 1);
}
代码示例来源:origin: org.apache.commons/commons-math3
/** {@inheritDoc} */
public boolean converged(final int iteration,
final Evaluation previous,
final Evaluation current) {
final double prevRms = previous.getRMS();
final double currRms = current.getRMS();
return Precision.equals(prevRms, currRms, this.absTol) ||
Precision.equalsWithRelativeTolerance(prevRms, currRms, this.relTol);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns true iff they are equal as defined by
* {@link #equals(double,double,int) equals(x, y, 1)}.
*
* @param x first value
* @param y second value
* @return {@code true} if the values are equal.
*/
public static boolean equals(double x, double y) {
return equals(x, y, 1);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns true if the arguments are both NaN or they are
* equal as defined by {@link #equals(double,double) equals(x, y, 1)}.
*
* @param x first value
* @param y second value
* @return {@code true} if the values are equal or both are NaN.
* @since 2.2
*/
public static boolean equalsIncludingNaN(double x, double y) {
return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, 1);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns true iff they are equal as defined by
* {@link #equals(float,float,int) equals(x, y, 1)}.
*
* @param x first value
* @param y second value
* @return {@code true} if the values are equal.
*/
public static boolean equals(float x, float y) {
return equals(x, y, 1);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns true if the arguments are both NaN or if they are equal as defined
* by {@link #equals(float,float,int) equals(x, y, maxUlps)}.
*
* @param x first value
* @param y second value
* @param maxUlps {@code (maxUlps - 1)} is the number of floating point
* values between {@code x} and {@code y}.
* @return {@code true} if both arguments are NaN or if there are less than
* {@code maxUlps} floating point values between {@code x} and {@code y}.
* @since 2.2
*/
public static boolean equalsIncludingNaN(float x, float y, int maxUlps) {
return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, maxUlps);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns true if both arguments are NaN or if they are equal as defined
* by {@link #equals(double,double,int) equals(x, y, maxUlps)}.
*
* @param x first value
* @param y second value
* @param maxUlps {@code (maxUlps - 1)} is the number of floating point
* values between {@code x} and {@code y}.
* @return {@code true} if both arguments are NaN or if there are less than
* {@code maxUlps} floating point values between {@code x} and {@code y}.
* @since 2.2
*/
public static boolean equalsIncludingNaN(double x, double y, int maxUlps) {
return (x != x || y != y) ? !(x != x ^ y != y) : equals(x, y, maxUlps);
}
代码示例来源:origin: org.apache.commons/commons-math3
/** Returns whether this diagonal matrix is singular, i.e. any diagonal entry
* is equal to {@code 0} within the given threshold.
*
* @param threshold Singularity threshold.
* @return {@code true} if the matrix is singular, {@code false} otherwise
* @since 3.3
*/
public boolean isSingular(double threshold) {
for (int i = 0; i < data.length; i++) {
if (Precision.equals(data[i], 0.0, threshold)) {
return true;
}
}
return false;
}
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns whether the calculated eigen values are complex or real.
* <p>The method performs a zero check for each element of the
* {@link #getImagEigenvalues()} array and returns {@code true} if any
* element is not equal to zero.
*
* @return {@code true} if the eigen values are complex, {@code false} otherwise
* @since 3.1
*/
public boolean hasComplexEigenvalues() {
for (int i = 0; i < imagEigenvalues.length; i++) {
if (!Precision.equals(imagEigenvalues[i], 0.0, EPSILON)) {
return true;
}
}
return false;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Compares two numbers given some amount of allowed error.
*
* @param x the first number
* @param y the second number
* @param eps the amount of error to allow when checking for equality
* @return <ul><li>0 if {@link #equals(double, double, double) equals(x, y, eps)}</li>
* <li>< 0 if !{@link #equals(double, double, double) equals(x, y, eps)} && x < y</li>
* <li>> 0 if !{@link #equals(double, double, double) equals(x, y, eps)} && x > y or
* either argument is NaN</li></ul>
*/
public static int compareTo(double x, double y, double eps) {
if (equals(x, y, eps)) {
return 0;
} else if (x < y) {
return -1;
}
return 1;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns {@code true} if, both for the real part and for the imaginary
* part, there is no double value strictly between the arguments or the
* difference between them is within the range of allowed error
* (inclusive). Returns {@code false} if either of the arguments is NaN.
*
* @param x First value (cannot be {@code null}).
* @param y Second value (cannot be {@code null}).
* @param eps Amount of allowed absolute error.
* @return {@code true} if the values are two adjacent floating point
* numbers or they are within range of each other.
*
* @see Precision#equals(double,double,double)
* @since 3.3
*/
public static boolean equals(Complex x, Complex y, double eps) {
return Precision.equals(x.real, y.real, eps) &&
Precision.equals(x.imaginary, y.imaginary, eps);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Checks whether the instance is a unit quaternion within a given
* tolerance.
*
* @param eps Tolerance (absolute error).
* @return {@code true} if the norm is 1 within the given tolerance,
* {@code false} otherwise
*/
public boolean isUnitQuaternion(double eps) {
return Precision.equals(getNorm(), 1d, eps);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns true if the arguments are equal or within the range of allowed
* error (inclusive). Returns {@code false} if either of the arguments
* is NaN.
*
* @param x first value
* @param y second value
* @param eps the amount of absolute error to allow.
* @return {@code true} if the values are equal or within range of each other.
* @since 2.2
*/
public static boolean equals(float x, float y, float eps) {
return equals(x, y, 1) || FastMath.abs(y - x) <= eps;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns {@code true} if there is no double value strictly between the
* arguments or the difference between them is within the range of allowed
* error (inclusive). Returns {@code false} if either of the arguments
* is NaN.
*
* @param x First value.
* @param y Second value.
* @param eps Amount of allowed absolute error.
* @return {@code true} if the values are two adjacent floating point
* numbers or they are within range of each other.
*/
public static boolean equals(double x, double y, double eps) {
return equals(x, y, 1) || FastMath.abs(y - x) <= eps;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Checks whether this instance is equal to another quaternion
* within a given tolerance.
*
* @param q Quaternion with which to compare the current quaternion.
* @param eps Tolerance.
* @return {@code true} if the each of the components are equal
* within the allowed absolute error.
*/
public boolean equals(final Quaternion q,
final double eps) {
return Precision.equals(q0, q.getQ0(), eps) &&
Precision.equals(q1, q.getQ1(), eps) &&
Precision.equals(q2, q.getQ2(), eps) &&
Precision.equals(q3, q.getQ3(), eps);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Checks whether the given column is basic.
* @param col index of the column to check
* @return the row that the variable is basic in. null if the column is not basic
*/
protected Integer getBasicRow(final int col) {
Integer row = null;
for (int i = 0; i < getHeight(); i++) {
final double entry = getEntry(i, col);
if (Precision.equals(entry, 1d, maxUlps) && (row == null)) {
row = i;
} else if (!Precision.equals(entry, 0d, maxUlps)) {
return null;
}
}
return row;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns the row in which the given column is basic.
* @param col index of the column
* @return the row that the variable is basic in, or {@code null} if the variable is not basic.
*/
private Integer findBasicRow(final int col) {
Integer row = null;
for (int i = 0; i < getHeight(); i++) {
final double entry = getEntry(i, col);
if (Precision.equals(entry, 1d, maxUlps) && (row == null)) {
row = i;
} else if (!Precision.equals(entry, 0d, maxUlps)) {
return null;
}
}
return row;
}
代码示例来源:origin: prestodb/presto
public static void assertAggregation(InternalAggregationFunction function, Object expectedValue, Page page)
{
BiFunction<Object, Object, Boolean> equalAssertion;
if (expectedValue instanceof Double && !expectedValue.equals(Double.NaN)) {
equalAssertion = (actual, expected) -> Precision.equals((double) actual, (double) expected, 1e-10);
}
else if (expectedValue instanceof Float && !expectedValue.equals(Float.NaN)) {
equalAssertion = (actual, expected) -> Precision.equals((float) actual, (float) expected, 1e-10f);
}
else {
equalAssertion = Objects::equals;
}
assertAggregation(function, equalAssertion, null, page, expectedValue);
}
代码示例来源:origin: org.apache.commons/commons-math3
/** Ensure a value is zero.
* @param value value to check
* @exception NumberIsTooLargeException if value is not zero
*/
private void ensureZero(final double value) throws NumberIsTooLargeException {
if (!Precision.equals(0.0, value, 1)) {
throw new NumberIsTooLargeException(FastMath.abs(value), 0, true);
}
}
代码示例来源:origin: org.apache.commons/commons-math3
/** Filter out spurious vertices on straight lines (at machine precision).
* @param loop segments loop to filter (will be modified in-place)
*/
private void filterSpuriousVertices(final List<Segment> loop) {
for (int i = 0; i < loop.size(); ++i) {
final Segment previous = loop.get(i);
int j = (i + 1) % loop.size();
final Segment next = loop.get(j);
if (next != null &&
Precision.equals(previous.getLine().getAngle(), next.getLine().getAngle(), Precision.EPSILON)) {
// the vertex between the two edges is a spurious one
// replace the two segments by a single one
loop.set(j, new Segment(previous.getStart(), next.getEnd(), previous.getLine()));
loop.remove(i--);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!