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


Java FpUtils.nextDown方法代码示例

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


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

示例1: main

import sun.misc.FpUtils; //导入方法依赖的package包/类
public static void main(String args[]) {
    int failures = 0;
    double twoToThe52 = FpUtils.scalb(1.0, 52); // 2^52

    double [][] testCases = {
        {0.0,                               0.0},
        {Double.MIN_VALUE,                  0.0},
        {FpUtils.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
        {DoubleConsts.MIN_NORMAL,           0.0},

        {0.2,                               0.0},

        {FpUtils.nextDown(0.5),             0.0},
        {                 0.5,              0.0},
        {  FpUtils.nextUp(0.5),             1.0},

        {0.7,                               1.0},
        {FpUtils.nextDown(1.0),             1.0},
        {                 1.0,              1.0},
        {  FpUtils.nextUp(1.0),             1.0},

        {FpUtils.nextDown(1.5),             1.0},
        {                 1.5,              2.0},
        {  FpUtils.nextUp(1.5),             2.0},

        {4.2,                               4.0},
        {4.5,                               4.0},
        {4.7,                               5.0},

        {7.5,                               8.0},
        {7.2,                               7.0},
        {7.7,                               8.0},

        {150000.75,                         150001.0},
        {300000.5,                          300000.0},
        {FpUtils.nextUp(300000.5),          300001.0},
        {FpUtils.nextDown(300000.75),       300001.0},
        {300000.75,                         300001.0},
        {FpUtils.nextUp(300000.75),         300001.0},
        {300000.99,                         300001.0},
        {262144.75,                         262145.0}, //(2^18 ) + 0.75
        {499998.75,                         499999.0},
        {524287.75,                         524288.0}, //(2^19 -1) + 0.75
        {524288.75,                         524289.0},

        {FpUtils.nextDown(twoToThe52),      twoToThe52},
        {twoToThe52,                        twoToThe52},
        {FpUtils.nextUp(twoToThe52),        FpUtils.nextUp(twoToThe52)},

        {Double.MAX_VALUE,          Double.MAX_VALUE},
        {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
        {Double.NaN,                        Double.NaN}

    };


    for(int i = 0; i < testCases.length; i++) {
        failures += testRintCase(testCases[i][0], testCases[i][1]);
    }

    // Test values throughout exponent range
    for(double d = Double.MIN_VALUE;
        d < Double.POSITIVE_INFINITY; d *= 2) {
        failures += testRintCase(d, ((d<=0.5)?0.0:d));
    }

    if (failures > 0) {
        System.err.println("Testing {Math, StrictMath}.rint incurred "
                           + failures + " failures.");
        throw new RuntimeException();
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:73,代码来源:Rint.java

示例2: significandAlignmentTests

import sun.misc.FpUtils; //导入方法依赖的package包/类
static int significandAlignmentTests() {
    int failures = 0;
            // baseSignif * 2^baseExp = nextDown(2.0)
    long [] baseSignifs = {
        0x1ffffffffffffe00L,
        0x1fffffffffffff00L
    };

    double [] answers = {
        FpUtils.nextDown(FpUtils.nextDown(2.0)),
        FpUtils.nextDown(2.0),
        2.0
    };

    int baseExp = -60;
    int count = 0;
    for(int i = 0; i < 2; i++) {
        for(long j = 0; j <= 0xfL; j++) {
            for(long k = 0; k <= 8; k+= 4) { // k = {0, 4, 8}
                long base = baseSignifs[i];
                long testValue = base | (j<<4) | k;

                int offset = 0;
                // Calculate when significand should be incremented
                // see table 4.7 in Koren book

                if ((base & 0x100L) == 0L ) { // lsb is 0
                    if ( (j >= 8L) &&         // round is 1
                         ((j & 0x7L) != 0 || k != 0 ) ) // sticky is 1
                        offset = 1;
                }
                else {                        // lsb is 1
                    if (j >= 8L)              // round is 1
                        offset = 1;
                }

                double expected = answers[i+offset];

                for(int m = -2; m <= 3; m++) {
                    count ++;

                    // Form equal value string and evaluate it
                    String s = "0x" +
                        Long.toHexString((m >=0) ?(testValue<<m):(testValue>>(-m))) +
                        "p" + (baseExp - m);

                    failures += testCase(s, expected);
                }
            }
        }
    }

    return failures;
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:55,代码来源:ParseHexFloatingPoint.java


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