java.lang.Math.rint()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中java.lang.Math.rint()方法的一些代码示例,展示了Math.rint()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.rint()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:rint

Math.rint介绍

[英]Returns the double conversion of the result of rounding the argument to an integer. Tie breaks are rounded towards even.

Special cases:

  • rint(+0.0) = +0.0
  • rint(-0.0) = -0.0
  • rint(+infinity) = +infinity
  • rint(-infinity) = -infinity
  • rint(NaN) = NaN
    [中]返回将参数舍入为整数的结果的双重转换。打成平局的人都是四舍五入的。
    特殊情况:
    *印刷(+0.0)=+0.0
    *rint(-0.0)=-0.0
    *rint(+无穷大)=+无穷大
    *rint(-无穷大)=-无穷大
    *rint(NaN)=NaN

代码示例

代码示例来源:origin: chewiebug/GCViewer

  1. private int toKiloBytes(long bytes) {
  2. return (int)Math.rint(bytes / (double)1024);
  3. }
  4. }

代码示例来源:origin: apache/mahout

  1. @Override
  2. public double apply(double a) {
  3. return Math.rint(a);
  4. }
  5. };

代码示例来源:origin: apache/mahout

  1. @Override
  2. public double apply(double a) {
  3. return Math.rint(a / precision) * precision;
  4. }
  5. };

代码示例来源:origin: pmd/pmd

  1. public int getComplexityAverage() {
  2. return (double) methodCount == 0 ? 1 : (int) Math.rint((double) decisionPoints / (double) methodCount);
  3. }
  4. }

代码示例来源:origin: pmd/pmd

  1. public int getComplexityAverage() {
  2. return (double) methodCount == 0 ? 1 : (int) Math.rint((double) decisionPoints / (double) methodCount);
  3. }
  4. }

代码示例来源:origin: pmd/pmd

  1. public int getComplexityAverage() {
  2. return (double) methodCount == 0 ? 1 : (int) Math.rint((double) decisionPoints / (double) methodCount);
  3. }
  4. }

代码示例来源:origin: org.apache.poi/poi

  1. public static int pointsToPixel(double points) {
  2. points *= PIXEL_DPI;
  3. points /= POINT_DPI;
  4. return (int)Math.rint(points);
  5. }

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * Converts points to EMUs
  3. * @param points points
  4. * @return EMUs
  5. */
  6. public static int toEMU(double points){
  7. return (int)Math.rint(EMU_PER_POINT*points);
  8. }

代码示例来源:origin: org.apache.poi/poi

  1. public static int pointsToMaster(double points) {
  2. points *= MASTER_DPI;
  3. points /= POINT_DPI;
  4. return (int)Math.rint(points);
  5. }

代码示例来源:origin: org.apache.poi/poi

  1. /**
  2. * Convert sRGB float component [0..1] from sRGB to linear RGB [0..100000]
  3. *
  4. * @see Color#getRGBColorComponents(float[])
  5. */
  6. public static int srgb2lin(float sRGB) {
  7. // scRGB has a linear gamma of 1.0, scale the AWT-Color which is in sRGB to linear RGB
  8. // see https://en.wikipedia.org/wiki/SRGB (the reverse transformation)
  9. if (sRGB <= 0.04045d) {
  10. return (int)Math.rint(100000d * sRGB / 12.92d);
  11. } else {
  12. return (int)Math.rint(100000d * Math.pow((sRGB + 0.055d) / 1.055d, 2.4d));
  13. }
  14. }

代码示例来源:origin: org.apache.poi/poi-ooxml

  1. /**
  2. * @return true, if this is an integer color value
  3. */
  4. private static boolean isInt(float f) {
  5. return Math.abs((f*255d) - Math.rint(f*255d)) < 0.00001;
  6. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * Returns bucket id for feature value.
  3. *
  4. * @param val Value.
  5. * @return bucket id.
  6. */
  7. public int getBucketId(Double val) {
  8. if(featureMeta.isCategoricalFeature())
  9. return (int) Math.rint(val);
  10. return (int) Math.rint((val - minVal) / bucketSize);
  11. }

代码示例来源:origin: xtuhcy/gecco

  1. /**
  2. * 间隔时间在左右1s的范围内随机
  3. *
  4. * @param interval
  5. * @return
  6. */
  7. private int randomInterval(int interval) {
  8. int min = interval - 1000;
  9. if(min < 1) {
  10. min = 1;
  11. }
  12. int max = interval + 1000;
  13. return (int)Math.rint(Math.random()*(max-min)+min);
  14. }

代码示例来源:origin: apache/incubator-druid

  1. @Override
  2. protected ExprEval eval(double param)
  3. {
  4. return ExprEval.of(Math.rint(param));
  5. }
  6. }

代码示例来源:origin: EngineHub/WorldEdit

  1. public static double rint(RValue x) throws EvaluationException {
  2. return Math.rint(x.getValue());
  3. }

代码示例来源:origin: addthis/stream-lib

  1. @Override
  2. public double nextDouble() {
  3. return Math.rint(gen.nextDouble() * 10) / 10.0;
  4. }
  5. };

代码示例来源:origin: google/guava

  1. return rint(x);
  2. double z = rint(x);
  3. if (abs(x - z) == 0.5) {
  4. return x + copySign(0.5, x);
  5. double z = rint(x);
  6. if (abs(x - z) == 0.5) {
  7. return x;

代码示例来源:origin: SpongePowered/SpongeAPI

  1. /**
  2. * Returns a new transform from the given transformation matrix, if the
  3. * resulting transform would be discrete.
  4. *
  5. * @param matrix The matrix to use for the transform
  6. * @return The new transform, or {@link Optional#empty()}
  7. */
  8. public static Optional<DiscreteTransform2> of(Matrix3d matrix) {
  9. if (Arrays.stream(matrix.toArray())
  10. .anyMatch(value -> Math.rint(value) != value)) {
  11. return Optional.empty();
  12. }
  13. return Optional.of(new DiscreteTransform2(matrix));
  14. }

代码示例来源:origin: alibaba/jstorm

  1. protected List<AsyncLoopThread> setSerializeThreads() {
  2. WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
  3. int tasksNum = shutdownTasks.size();
  4. double workerRatio = ConfigExtension.getWorkerSerializeThreadRatio(stormConf);
  5. int workerSerialThreadNum = Utils.getInt(Math.ceil(workerRatio * tasksNum));
  6. if (workerSerialThreadNum > 0 && tasksNum > 0) {
  7. double average = tasksNum / (double) workerSerialThreadNum;
  8. for (int i = 0; i < workerSerialThreadNum; i++) {
  9. int startRunTaskIndex = Utils.getInt(Math.rint(average * i));
  10. serializeThreads.add(new AsyncLoopThread(new WorkerSerializeRunnable(
  11. shutdownTasks, stormConf, workerTopologyContext, startRunTaskIndex, i)));
  12. }
  13. }
  14. return serializeThreads;
  15. }

代码示例来源:origin: alibaba/jstorm

  1. protected List<AsyncLoopThread> setDeserializeThreads() {
  2. WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
  3. int tasksNum = shutdownTasks.size();
  4. double workerRatio = ConfigExtension.getWorkerDeserializeThreadRatio(stormConf);
  5. int workerDeserThreadNum = Utils.getInt(Math.ceil(workerRatio * tasksNum));
  6. if (workerDeserThreadNum > 0 && tasksNum > 0) {
  7. double average = tasksNum / (double) workerDeserThreadNum;
  8. for (int i = 0; i < workerDeserThreadNum; i++) {
  9. int startRunTaskIndex = Utils.getInt(Math.rint(average * i));
  10. deserializeThreads.add(new AsyncLoopThread(new WorkerDeserializeRunnable(
  11. shutdownTasks, stormConf, workerTopologyContext, startRunTaskIndex, i)));
  12. }
  13. }
  14. return deserializeThreads;
  15. }

相关文章