當前位置: 首頁>>代碼示例>>Java>>正文


Java FastMath.round方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.util.FastMath.round方法的典型用法代碼示例。如果您正苦於以下問題:Java FastMath.round方法的具體用法?Java FastMath.round怎麽用?Java FastMath.round使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.util.FastMath的用法示例。


在下文中一共展示了FastMath.round方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: project

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Projects 3D points.
 */
public void project(Point p, double x, double y, double z)
{
    // rotates
    tmpValue = x;
    x = x * sx_cos + y * sy_sin;
    y = tmpValue * sx_sin + y * sy_cos;

    // elevates and projects
    tmpValue = factor / (y * cos_elevation - z * sz_sin + distance);
    p.x = FastMath.round((float) (x * tmpValue)) + trans_x;
    p.y = FastMath.round((float) ((y * sin_elevation + z * sz_cos) * -tmpValue)) + trans_y;
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:16,代碼來源:SurfacePlotProjector.java

示例2: roundToNumberOfSignificantDigits

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Procedure rounds the given value to the given number of significant digits see
 * http://stackoverflow.com/questions/202302
 *
 * Note: The maximum double value in Java is on the order of 10^308, while the minimum value is on the order of
 * 10^-324. Therefore, you can run into trouble when applying the function roundToSignificantFigures to something
 * that's within a few powers of ten of Double.MIN_VALUE.
 *
 * Consequently, the variable magnitude may become Infinity, and it's all garbage from then on out. Fortunately,
 * this is not an insurmountable problem: it is only the factor magnitude that's overflowing. What really matters is
 * the product num * magnitude, and that does not overflow. One way of resolving this is by breaking up the
 * multiplication by the factor magintude into two steps.
 */
public static double roundToNumberOfSignificantDigits(double num, int n)
{
    final double maxPowerOfTen = FastMath.floor(FastMath.log10(Double.MAX_VALUE));

    if (num == 0)
    {
        return 0;
    }

    try
    {
        return new BigDecimal(num).round(new MathContext(n, RoundingMode.HALF_EVEN)).doubleValue();
    }
    catch (ArithmeticException ex)
    {
        // nothing to do
    }

    final double d = FastMath.ceil(FastMath.log10(num < 0 ? -num : num));
    final int power = n - (int) d;

    double firstMagnitudeFactor = 1.0;
    double secondMagnitudeFactor = 1.0;
    if (power > maxPowerOfTen)
    {
        firstMagnitudeFactor = FastMath.pow(10.0, maxPowerOfTen);
        secondMagnitudeFactor = FastMath.pow(10.0, (double) power - maxPowerOfTen);
    }
    else
    {
        firstMagnitudeFactor = FastMath.pow(10.0, (double) power);
    }

    double toBeRounded = num * firstMagnitudeFactor;
    toBeRounded *= secondMagnitudeFactor;

    final long shifted = FastMath.round(toBeRounded);
    double rounded = ((double) shifted) / firstMagnitudeFactor;
    rounded /= secondMagnitudeFactor;
    return rounded;
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:55,代碼來源:ViewUtils.java

示例3: resolveTie

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Resolve a sequence of ties, using the configured {@link TiesStrategy}.
 * The input <code>ranks</code> array is expected to take the same value
 * for all indices in <code>tiesTrace</code>.  The common value is recoded
 * according to the tiesStrategy. For example, if ranks = <5,8,2,6,2,7,1,2>,
 * tiesTrace = <2,4,7> and tiesStrategy is MINIMUM, ranks will be unchanged.
 * The same array and trace with tiesStrategy AVERAGE will come out
 * <5,8,3,6,3,7,1,3>.
 *
 * @param ranks array of ranks
 * @param tiesTrace list of indices where <code>ranks</code> is constant
 * -- that is, for any i and j in TiesTrace, <code> ranks[i] == ranks[j]
 * </code>
 */
private void resolveTie(double[] ranks, List<Integer> tiesTrace) {

    // constant value of ranks over tiesTrace
    final double c = ranks[tiesTrace.get(0)];

    // length of sequence of tied ranks
    final int length = tiesTrace.size();

    switch (tiesStrategy) {
        case  AVERAGE:  // Replace ranks with average
            fill(ranks, tiesTrace, (2 * c + length - 1) / 2d);
            break;
        case MAXIMUM:   // Replace ranks with maximum values
            fill(ranks, tiesTrace, c + length - 1);
            break;
        case MINIMUM:   // Replace ties with minimum
            fill(ranks, tiesTrace, c);
            break;
        case RANDOM:    // Fill with random integral values in [c, c + length - 1]
            Iterator<Integer> iterator = tiesTrace.iterator();
            long f = FastMath.round(c);
            while (iterator.hasNext()) {
                // No advertised exception because args are guaranteed valid
                ranks[iterator.next()] =
                    randomData.nextLong(f, f + length - 1);
            }
            break;
        case SEQUENTIAL:  // Fill sequentially from c to c + length - 1
            // walk and fill
            iterator = tiesTrace.iterator();
            f = FastMath.round(c);
            int i = 0;
            while (iterator.hasNext()) {
                ranks[iterator.next()] = f + i++;
            }
            break;
        default: // this should not happen unless TiesStrategy enum is changed
            throw new MathInternalError();
    }
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:55,代碼來源:NaturalRanking.java

示例4: round

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
public long round() {
    return FastMath.round(value);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:5,代碼來源:SparseGradient.java

示例5: round

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
public long round() {
    return FastMath.round(data[0]);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:5,代碼來源:DerivativeStructure.java

示例6: round

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc}
 * @since 3.2
 */
public long round() {
    return FastMath.round(toDouble());
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:7,代碼來源:Dfp.java


注:本文中的org.apache.commons.math3.util.FastMath.round方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。