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


Java FloatingDecimal类代码示例

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


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

示例1: testAppendToDouble

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testAppendToDouble() {
    System.out.println("  testAppendToDouble");
    int failures = 0;

    for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
        double[] d = new double[] {
            RANDOM.nextLong(),
            RANDOM.nextGaussian(),
            RANDOM.nextDouble()*Double.MAX_VALUE
        };
        for(int j = 0; j < d.length; j++) {
            OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(d[j]);
            StringBuilder sb = new StringBuilder();
            ofd.appendTo(sb);
            String oldString = sb.toString();
            sb = new StringBuilder();
            FloatingDecimal.appendTo(d[j], sb);
            String newString = sb.toString();
            failures += check("testAppendToDouble", oldString, newString);
        }
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:TestFloatingDecimal.java

示例2: testAppendToFloat

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testAppendToFloat() {
    System.out.println("  testAppendToFloat");
    int failures = 0;

    for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
        float[] f = new float[] {
            RANDOM.nextLong(),
            (float)RANDOM.nextGaussian(),
            RANDOM.nextFloat()*Float.MAX_VALUE
        };
        for(int j = 0; j < f.length; j++) {
            OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(f[j]);
            StringBuilder sb = new StringBuilder();
            ofd.appendTo(sb);
            String oldString = sb.toString();
            sb = new StringBuilder();
            FloatingDecimal.appendTo(f[j], sb);
            String newString = sb.toString();
            failures += check("testAppendToFloat", oldString, newString);
        }
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:TestFloatingDecimal.java

示例3: testParseDouble

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testParseDouble() {
    System.out.println("  testParseDouble");
    int failures = 0;

    for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
        double[] d = new double[] {
            RANDOM.nextLong(),
            RANDOM.nextGaussian(),
            RANDOM.nextDouble()*Double.MAX_VALUE
        };
        for(int j = 0; j < d.length; j++) {
            OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(d[j]);
            String javaFormatString = ofd.toJavaFormatString();
            ofd = OldFloatingDecimalForTest.readJavaFormatString(javaFormatString);
            double oldDouble = ofd.doubleValue();
            double newDouble = FloatingDecimal.parseDouble(javaFormatString);
            failures += check("testParseDouble", oldDouble, newDouble);
        }
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TestFloatingDecimal.java

示例4: testParseFloat

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testParseFloat() {
    System.out.println("  testParseFloat");
    int failures = 0;

    for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
        float[] f = new float[] {
            RANDOM.nextInt(),
            (float)RANDOM.nextGaussian(),
            RANDOM.nextFloat()*Float.MAX_VALUE
        };
        for(int j = 0; j < f.length; j++) {
            OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(f[j]);
            String javaFormatString = ofd.toJavaFormatString();
            ofd = OldFloatingDecimalForTest.readJavaFormatString(javaFormatString);
            float oldFloat = ofd.floatValue();
            float newFloat = FloatingDecimal.parseFloat(javaFormatString);
            failures += check("testParseFloat", oldFloat, newFloat);
        }
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TestFloatingDecimal.java

示例5: testToJavaFormatStringDoubleFixed

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testToJavaFormatStringDoubleFixed() {
    System.out.println("    testToJavaFormatStringDoubleFixed");
    int failures = 0;

    double[] d = new double [] {
        -5.9522650387500933e18, // dtoa() fast path
        0.872989018674569,      // dtoa() fast iterative - long
        1.1317400099603851e308  // dtoa() slow iterative
    };

    for(int i = 0; i < d.length; i++) {
        OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(d[i]);
        failures += check("testToJavaFormatStringDoubleFixed", ofd.toJavaFormatString(), FloatingDecimal.toJavaFormatString(d[i]));
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:TestFloatingDecimal.java

示例6: testToJavaFormatStringDoubleRandom

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testToJavaFormatStringDoubleRandom() {
    System.out.println("    testToJavaFormatStringDoubleRandom");
    int failures = 0;

    for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
        double[] d = new double[] {
            RANDOM.nextLong(),
            RANDOM.nextGaussian(),
            RANDOM.nextDouble()*Double.MAX_VALUE
        };
        for(int j = 0; j < d.length; j++) {
            OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(d[j]);
            failures += check("testToJavaFormatStringDoubleRandom", ofd.toJavaFormatString(), FloatingDecimal.toJavaFormatString(d[j]));
        }
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestFloatingDecimal.java

示例7: testToJavaFormatStringFloatFixed

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testToJavaFormatStringFloatFixed() {
    System.out.println("    testToJavaFormatStringFloatFixed");
    int failures = 0;

    float[] f = new float[] {
        -9.8784166e8f, // dtoa() fast path
        0.70443946f,   // dtoa() fast iterative - int
        1.8254228e37f  // dtoa() slow iterative
    };

    for(int i = 0; i < f.length; i++) {
        OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(f[i]);
        failures += check("testToJavaFormatStringFloatFixed", ofd.toJavaFormatString(), FloatingDecimal.toJavaFormatString(f[i]));
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:TestFloatingDecimal.java

示例8: testToJavaFormatStringFloatRandom

import sun.misc.FloatingDecimal; //导入依赖的package包/类
private static int testToJavaFormatStringFloatRandom() {
    System.out.println("    testToJavaFormatStringFloatRandom");
    int failures = 0;

    for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
        float[] f = new float[] {
            RANDOM.nextInt(),
            (float)RANDOM.nextGaussian(),
            RANDOM.nextFloat()*Float.MAX_VALUE
        };
        for(int j = 0; j < f.length; j++) {
            OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(f[j]);
            failures += check("testToJavaFormatStringFloatRandom", ofd.toJavaFormatString(), FloatingDecimal.toJavaFormatString(f[j]));
        }
    }

    return failures;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestFloatingDecimal.java

示例9: encodeOptimized

import sun.misc.FloatingDecimal; //导入依赖的package包/类
/**
 * Encode the given GTS instance, converting doubles to BigDecimal to get a chance to
 * store them more efficiently
 * 
 * @param gts
 */
public synchronized void encodeOptimized(GeoTimeSerie gts) throws IOException {
  StringBuilder sb = new StringBuilder();
  
  char[] chars = null;
  
  for (int i = 0; i < gts.values; i++) {
    Object value = GTSHelper.valueAtIndex(gts, i);
    
    if ((value instanceof Double) && Double.isFinite((double) value)) {
      sb.setLength(0);
      BinaryToASCIIConverter btoa = FloatingDecimal.getBinaryToASCIIConverter((double) value);
      btoa.appendTo(sb);
      if (null == chars || chars.length < sb.length()) {
        chars = new char[sb.length()];
      }
      
      sb.getChars(0, sb.length(), chars, 0);
      
      value = new BigDecimal(chars, 0, sb.length());
    }
    addValue(gts.ticks[i], null != gts.locations ? gts.locations[i] : GeoTimeSerie.NO_LOCATION, null != gts.elevations ? gts.elevations[i] : GeoTimeSerie.NO_ELEVATION, value);
  }
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:30,代码来源:GTSEncoder.java


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