本文整理汇总了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;
}
示例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;
}
示例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();
}
}
示例4: round
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public long round() {
return FastMath.round(value);
}
示例5: round
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public long round() {
return FastMath.round(data[0]);
}
示例6: round
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc}
* @since 3.2
*/
public long round() {
return FastMath.round(toDouble());
}