本文整理了Java中org.apache.commons.math3.util.Precision
类的一些代码示例,展示了Precision
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Precision
类的具体详情如下:
包路径:org.apache.commons.math3.util.Precision
类名称:Precision
[英]Utilities for comparing numbers.
[中]用于比较数字的实用程序。
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Rounds the given value to the specified number of decimal places.
* The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
*
* @param x Value to round.
* @param scale Number of digits to the right of the decimal point.
* @return the rounded value.
* @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
*/
public static float round(float x, int scale) {
return round(x, scale, BigDecimal.ROUND_HALF_UP);
}
代码示例来源: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
/**
* Returns true iff both arguments are null or have same dimensions and all
* their elements are equal as defined by
* {@link Precision#equalsIncludingNaN(double,double) this method}.
*
* @param x first array
* @param y second array
* @return true if the values are both null or have same dimension and
* equal elements
* @since 2.2
*/
public static boolean equalsIncludingNaN(float[] x, float[] y) {
if ((x == null) || (y == null)) {
return !((x == null) ^ (y == null));
}
if (x.length != y.length) {
return false;
}
for (int i = 0; i < x.length; ++i) {
if (!Precision.equalsIncludingNaN(x[i], y[i])) {
return false;
}
}
return true;
}
代码示例来源: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
if (Precision.compareTo(entry, 0d, cutOff) > 0) {
final double ratio = FastMath.abs(rhs / entry);
int column = i + tableau.getArtificialVariableOffset();
final double entry = tableau.getEntry(row, column);
if (Precision.equals(entry, 1d, maxUlps) && row.equals(tableau.getBasicRow(column))) {
return row;
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Gets the block diagonal matrix D of the decomposition.
* D is a block diagonal matrix.
* Real eigenvalues are on the diagonal while complex values are on
* 2x2 blocks { {real +imaginary}, {-imaginary, real} }.
*
* @return the D matrix.
*
* @see #getRealEigenvalues()
* @see #getImagEigenvalues()
*/
public RealMatrix getD() {
if (cachedD == null) {
// cache the matrix for subsequent calls
cachedD = MatrixUtils.createRealDiagonalMatrix(realEigenvalues);
for (int i = 0; i < imagEigenvalues.length; i++) {
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) > 0) {
cachedD.setEntry(i, i+1, imagEigenvalues[i]);
} else if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) < 0) {
cachedD.setEntry(i, i-1, imagEigenvalues[i]);
}
}
}
return cachedD;
}
代码示例来源: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
* relative difference between them is smaller or equal to the given
* tolerance. 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 relative error.
* @return {@code true} if the values are two adjacent floating point
* numbers or they are within range of each other.
*
* @see Precision#equalsWithRelativeTolerance(double,double,double)
* @since 3.3
*/
public static boolean equalsWithRelativeTolerance(Complex x, Complex y,
double eps) {
return Precision.equalsWithRelativeTolerance(x.real, y.real, eps) &&
Precision.equalsWithRelativeTolerance(x.imaginary, y.imaginary, eps);
}
代码示例来源:origin: org.apache.commons/commons-math3
final double entry = tableau.getEntry(i, col);
if (Precision.compareTo(entry, 0d, maxUlps) > 0) {
final double ratio = rhs / entry;
int column = i + tableau.getArtificialVariableOffset();
final double entry = tableau.getEntry(row, column);
if (Precision.equals(entry, 1d, maxUlps) && row.equals(tableau.getBasicRow(column))) {
return row;
代码示例来源:origin: geogebra/geogebra
/** {@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
/** {@inheritDoc} */
public int compare(final Vector2D o1, final Vector2D o2) {
final double tolerance = getTolerance();
// need to take the tolerance value into account, otherwise collinear points
// will not be handled correctly when building the upper/lower hull
final int diff = Precision.compareTo(o1.getX(), o2.getX(), tolerance);
if (diff == 0) {
return Precision.compareTo(o1.getY(), o2.getY(), tolerance);
} else {
return diff;
}
}
});
代码示例来源:origin: geogebra/geogebra
/**
* 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
* relative difference between them is smaller or equal to the given
* tolerance. 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 relative error.
* @return {@code true} if the values are two adjacent floating point
* numbers or they are within range of each other.
*
* @see Precision#equalsWithRelativeTolerance(double,double,double)
* @since 3.3
*/
public static boolean equalsWithRelativeTolerance(Complex x, Complex y,
double eps) {
return Precision.equalsWithRelativeTolerance(x.real, y.real, eps) &&
Precision.equalsWithRelativeTolerance(x.imaginary, y.imaginary, eps);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Rounds the given value to the specified number of decimal places.
* The value is rounded using the {@link BigDecimal#ROUND_HALF_UP} method.
*
* @param x Value to round.
* @param scale Number of digits to the right of the decimal point.
* @return the rounded value.
* @since 1.1 (previously in {@code MathUtils}, moved as of version 3.0)
*/
public static double round(double x, int scale) {
return round(x, scale, BigDecimal.ROUND_HALF_UP);
}
代码示例来源: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
if (Precision.equals(norm, 0.0, EPSILON)) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
if (Precision.equals(q, 0.0)) {
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) < 0) {
z = w;
s = r;
} else {
l = i;
if (Precision.equals(imagEigenvalues[i], 0.0)) {
if (w != 0.0) {
matrixT[i][idx] = -r / w;
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) < 0) {
z = w;
r = ra;
} else {
l = i;
if (Precision.equals(imagEigenvalues[i], 0.0)) {
final Complex c = cdiv(-ra, -sa, w, q);
matrixT[i][idx - 1] = c.getReal();
imagEigenvalues[i] * imagEigenvalues[i] - q * q;
final double vi = (realEigenvalues[i] - p) * 2.0 * q;
if (Precision.equals(vr, 0.0) && Precision.equals(vi, 0.0)) {
vr = Precision.EPSILON * norm *
(FastMath.abs(w) + FastMath.abs(q) + FastMath.abs(x) +
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/** {@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 {@code true} iff both arguments are {@code null} or have same
* dimensions and all their elements are equal as defined by
* {@link Precision#equalsIncludingNaN(double,double) this method}.
*
* @param x First array.
* @param y Second array.
* @return {@code true} if the values are both {@code null} or have same
* dimension and equal elements.
* @since 2.2
*/
public static boolean equalsIncludingNaN(double[] x, double[] y) {
if ((x == null) || (y == null)) {
return !((x == null) ^ (y == null));
}
if (x.length != y.length) {
return false;
}
for (int i = 0; i < x.length; ++i) {
if (!Precision.equalsIncludingNaN(x[i], y[i])) {
return false;
}
}
return true;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
for (int i = getNumObjectiveFunctions(); i < getWidth() - 1; i++) {
final double entry = tableau.getEntry(0, i);
if (Precision.compareTo(entry, 0d, epsilon) < 0) {
return false;
}
}
return true;
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* 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
* relative difference between them is smaller or equal to the given
* tolerance. 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 relative error.
* @return {@code true} if the values are two adjacent floating point
* numbers or they are within range of each other.
*
* @see Precision#equalsWithRelativeTolerance(double,double,double)
* @since 3.3
*/
public static boolean equalsWithRelativeTolerance(Complex x, Complex y,
double eps) {
return Precision.equalsWithRelativeTolerance(x.real, y.real, eps) &&
Precision.equalsWithRelativeTolerance(x.imaginary, y.imaginary, eps);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return String.format(
"index=%.0f,n=%.0f,np=%.2f,q=%.2f,dn=%.2f,prev=%d,next=%d",
(double) index, Precision.round(intMarkerPosition, 0),
Precision.round(desiredMarkerPosition, 2),
Precision.round(markerHeight, 2),
Precision.round(desiredMarkerIncrement, 2), previous.index,
next.index);
}
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!