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

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

本文整理了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

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

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

@Override
 public double apply(double a) {
  return Math.rint(a);
 }
};

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

@Override
 public double apply(double a) {
  return Math.rint(a / precision) * precision;
 }
};

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

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

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

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

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

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

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

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

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

/**
 * Converts points to EMUs
 * @param points points
 * @return EMUs
 */
public static int toEMU(double points){
  return (int)Math.rint(EMU_PER_POINT*points);
}

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

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

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

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

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

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

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

/**
 * Returns bucket id for feature value.
 *
 * @param val Value.
 * @return bucket id.
 */
public int getBucketId(Double val) {
  if(featureMeta.isCategoricalFeature())
    return (int) Math.rint(val);
  return (int) Math.rint((val - minVal) / bucketSize);
}

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

/**
 * 间隔时间在左右1s的范围内随机
 * 
 * @param interval
 * @return
 */
private int randomInterval(int interval) {
  int min = interval - 1000;
  if(min < 1) {
    min = 1;
  }
  int max = interval + 1000;
  return (int)Math.rint(Math.random()*(max-min)+min);
}

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

@Override
 protected ExprEval eval(double param)
 {
  return ExprEval.of(Math.rint(param));
 }
}

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

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

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

@Override
  public double nextDouble() {
    return Math.rint(gen.nextDouble() * 10) / 10.0;
  }
};

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

return rint(x);
 double z = rint(x);
 if (abs(x - z) == 0.5) {
  return x + copySign(0.5, x);
 double z = rint(x);
 if (abs(x - z) == 0.5) {
  return x;

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

/**
 * Returns a new transform from the given transformation matrix, if the
 * resulting transform would be discrete.
 *
 * @param matrix The matrix to use for the transform
 * @return The new transform, or {@link Optional#empty()}
 */
public static Optional<DiscreteTransform2> of(Matrix3d matrix) {
  if (Arrays.stream(matrix.toArray())
    .anyMatch(value -> Math.rint(value) != value)) {
    return Optional.empty();
  }
  return Optional.of(new DiscreteTransform2(matrix));
}

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

protected List<AsyncLoopThread> setSerializeThreads() {
  WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
  int tasksNum = shutdownTasks.size();
  double workerRatio = ConfigExtension.getWorkerSerializeThreadRatio(stormConf);
  int workerSerialThreadNum = Utils.getInt(Math.ceil(workerRatio * tasksNum));
  if (workerSerialThreadNum > 0 && tasksNum > 0) {
    double average = tasksNum / (double) workerSerialThreadNum;
    for (int i = 0; i < workerSerialThreadNum; i++) {
      int startRunTaskIndex = Utils.getInt(Math.rint(average * i));
      serializeThreads.add(new AsyncLoopThread(new WorkerSerializeRunnable(
          shutdownTasks, stormConf, workerTopologyContext, startRunTaskIndex, i)));
    }
  }
  return serializeThreads;
}

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

protected List<AsyncLoopThread> setDeserializeThreads() {
  WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
  int tasksNum = shutdownTasks.size();
  double workerRatio = ConfigExtension.getWorkerDeserializeThreadRatio(stormConf);
  int workerDeserThreadNum = Utils.getInt(Math.ceil(workerRatio * tasksNum));
  if (workerDeserThreadNum > 0 && tasksNum > 0) {
    double average = tasksNum / (double) workerDeserThreadNum;
    for (int i = 0; i < workerDeserThreadNum; i++) {
      int startRunTaskIndex = Utils.getInt(Math.rint(average * i));
      deserializeThreads.add(new AsyncLoopThread(new WorkerDeserializeRunnable(
          shutdownTasks, stormConf, workerTopologyContext, startRunTaskIndex, i)));
    }
  }
  return deserializeThreads;
}

相关文章