当前位置: 首页>>代码示例>>Java>>正文


Java FpUtils.rawCopySign方法代码示例

本文整理汇总了Java中sun.misc.FpUtils.rawCopySign方法的典型用法代码示例。如果您正苦于以下问题:Java FpUtils.rawCopySign方法的具体用法?Java FpUtils.rawCopySign怎么用?Java FpUtils.rawCopySign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.misc.FpUtils的用法示例。


在下文中一共展示了FpUtils.rawCopySign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rint

import sun.misc.FpUtils; //导入方法依赖的package包/类
/**
    * Returns the <code>double</code> value that is closest in value
    * to the argument and is equal to a mathematical integer. If two
    * <code>double</code> values that are mathematical integers are
    * equally close to the value of the argument, the result is the
    * integer value that is even. Special cases:
    * <ul><li>If the argument value is already equal to a mathematical 
    * integer, then the result is the same as the argument. 
    * <li>If the argument is NaN or an infinity or positive zero or negative 
    * zero, then the result is the same as the argument.</ul>
    *
    * @param   a   a value.
    * @return  the closest floating-point value to <code>a</code> that is
    *          equal to a mathematical integer.
    * @author Joseph D. Darcy
    */
   public static double rint(double a) {
/*
 * If the absolute value of a is not less than 2^52, it
 * is either a finite integer (the double format does not have
 * enough significand bits for a number that large to have any
 * fractional portion), an infinity, or a NaN.  In any of
 * these cases, rint of the argument is the argument.
 *
 * Otherwise, the sum (twoToThe52 + a ) will properly round
 * away any fractional portion of a since ulp(twoToThe52) ==
 * 1.0; subtracting out twoToThe52 from this sum will then be
 * exact and leave the rounded integer portion of a.
 *
 * This method does *not* need to be declared strictfp to get
 * fully reproducible results.  Whether or not a method is
 * declared strictfp can only make a difference in the
 * returned result if some operation would overflow or
 * underflow with strictfp semantics.  The operation
 * (twoToThe52 + a ) cannot overflow since large values of a
 * are screened out; the add cannot underflow since twoToThe52
 * is too large.  The subtraction ((twoToThe52 + a ) -
 * twoToThe52) will be exact as discussed above and thus
 * cannot overflow or meaningfully underflow.  Finally, the
 * last multiply in the return statement is by plus or minus
 * 1.0, which is exact too.
 */
double twoToThe52 = (double)(1L << 52); // 2^52
double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info
a = Math.abs(a);

if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
    a = ((twoToThe52 + a ) - twoToThe52);
} 

return sign * a; // restore original sign
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:53,代码来源:StrictMath.java

示例2: rint

import sun.misc.FpUtils; //导入方法依赖的package包/类
/**
 * Returns the {@code double} value that is closest in value
 * to the argument and is equal to a mathematical integer. If two
 * {@code double} values that are mathematical integers are
 * equally close to the value of the argument, the result is the
 * integer value that is even. Special cases:
 * <ul><li>If the argument value is already equal to a mathematical
 * integer, then the result is the same as the argument.
 * <li>If the argument is NaN or an infinity or positive zero or negative
 * zero, then the result is the same as the argument.</ul>
 *
 * @param   a   a value.
 * @return  the closest floating-point value to {@code a} that is
 *          equal to a mathematical integer.
 * @author Joseph D. Darcy
 */
public static double rint(double a) {
    /*
     * If the absolute value of a is not less than 2^52, it
     * is either a finite integer (the double format does not have
     * enough significand bits for a number that large to have any
     * fractional portion), an infinity, or a NaN.  In any of
     * these cases, rint of the argument is the argument.
     *
     * Otherwise, the sum (twoToThe52 + a ) will properly round
     * away any fractional portion of a since ulp(twoToThe52) ==
     * 1.0; subtracting out twoToThe52 from this sum will then be
     * exact and leave the rounded integer portion of a.
     *
     * This method does *not* need to be declared strictfp to get
     * fully reproducible results.  Whether or not a method is
     * declared strictfp can only make a difference in the
     * returned result if some operation would overflow or
     * underflow with strictfp semantics.  The operation
     * (twoToThe52 + a ) cannot overflow since large values of a
     * are screened out; the add cannot underflow since twoToThe52
     * is too large.  The subtraction ((twoToThe52 + a ) -
     * twoToThe52) will be exact as discussed above and thus
     * cannot overflow or meaningfully underflow.  Finally, the
     * last multiply in the return statement is by plus or minus
     * 1.0, which is exact too.
     */
    double twoToThe52 = (double)(1L << 52); // 2^52
    double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info
    a = Math.abs(a);

    if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
        a = ((twoToThe52 + a ) - twoToThe52);
    }

    return sign * a; // restore original sign
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:53,代码来源:StrictMath.java


注:本文中的sun.misc.FpUtils.rawCopySign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。