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

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

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

Math.ulp介绍

[英]Returns the argument's ulp (unit in the last place). The size of a ulp of a double value is the positive distance between this value and the double value next larger in magnitude. For non-NaN x, ulp(-x) ==.

Special cases:

  • ulp(+0.0) = Double.MIN_VALUE
  • ulp(-0.0) = Double.MIN_VALUE
  • ulp(+infinity) = infinity
  • ulp(-infinity) = infinity
  • ulp(NaN) = NaN
    [中]返回参数的ulp(最后一位的单位)。双值ulp的大小是该值与幅值稍大的双值之间的正距离。对于非NaN x,ulp(-x)=。
    特殊情况:
    *ulp(+0.0)=双倍。最小值
    *ulp(-0.0)=双倍。最小值
    *ulp(+无穷大)=无穷大
    *ulp(-无穷大)=无穷大
    *ulp(NaN)=NaN

代码示例

代码示例来源:origin: h2oai/h2o-3

  1. public static double find_maxEx(double maxIn, int isInt ) {
  2. double ulp = Math.ulp(maxIn);
  3. if( isInt > 0 && 1 > ulp ) ulp = 1;
  4. double res = maxIn+ulp;
  5. return Double.isInfinite(res) ? maxIn : res;
  6. }

代码示例来源:origin: h2oai/h2o-2

  1. static public float find_maxEx(float maxIn, int isInt ) {
  2. float ulp = Math.ulp(maxIn);
  3. if( isInt > 0 && 1 > ulp ) ulp = 1;
  4. float res = maxIn+ulp;
  5. return Float.isInfinite(res) ? maxIn : res;
  6. }

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

  1. /**
  2. * Returns the argument's ulp (unit in the last place). The size of a ulp of
  3. * a float value is the positive distance between this value and the float
  4. * value next larger in magnitude. For non-NaN {@code x},
  5. * {@code ulp(-x) == ulp(x)}.
  6. * <p>
  7. * Special cases:
  8. * <ul>
  9. * <li>{@code ulp(+0.0) = Float.MIN_VALUE}</li>
  10. * <li>{@code ulp(-0.0) = Float.MIN_VALUE}</li>
  11. * <li>{@code ulp(+infinity) = infinity}</li>
  12. * <li>{@code ulp(-infinity) = infinity}</li>
  13. * <li>{@code ulp(NaN) = NaN}</li>
  14. * </ul>
  15. *
  16. * @param f
  17. * the floating-point value to compute ulp of.
  18. * @return the size of a ulp of the argument.
  19. */
  20. public static float ulp(float f) {
  21. return Math.ulp(f);
  22. }

代码示例来源:origin: h2oai/h2o-2

  1. public static boolean equalsWithinOneSmallUlp(double a, double b) {
  2. if (Double.isInfinite(a) || Double.isInfinite(b) && (a<b || b<a)) return false;
  3. double ulp_a = Math.ulp(a);
  4. double ulp_b = Math.ulp(b);
  5. double small_ulp = Math.min(ulp_a, ulp_b);
  6. double absdiff_a_b = Math.abs(a - b); // subtraction order does not matter, due to IEEE 754 spec
  7. return absdiff_a_b <= small_ulp;
  8. }

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

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

代码示例来源:origin: h2oai/h2o-2

  1. /**
  2. * Compare two numbers to see if they are within one ulp of the smaller decade.
  3. * Order of the arguments does not matter.
  4. *
  5. * @param a First number
  6. * @param b Second number
  7. * @return true if a and b are essentially equal, false otherwise.
  8. */
  9. public static boolean equalsWithinOneSmallUlp(float a, float b) {
  10. if (Float.isInfinite(a) || Float.isInfinite(b) && (a<b || b<a)) return false;
  11. float ulp_a = Math.ulp(a);
  12. float ulp_b = Math.ulp(b);
  13. float small_ulp = Math.min(ulp_a, ulp_b);
  14. float absdiff_a_b = Math.abs(a - b); // subtraction order does not matter, due to IEEE 754 spec
  15. return absdiff_a_b <= small_ulp;
  16. }

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

  1. /**
  2. * Get the highest value that is equivalent to the given value within the histogram's resolution.
  3. * Where "equivalent" means that value samples recorded for any two
  4. * equivalent values are counted in a common total count.
  5. *
  6. * @param value The given value
  7. * @return The highest value that is equivalent to the given value within the histogram's resolution.
  8. */
  9. public double highestEquivalentValue(final double value) {
  10. double nextNonEquivalentValue = nextNonEquivalentValue(value);
  11. // Theoretically, nextNonEquivalentValue - ulp(nextNonEquivalentValue) == nextNonEquivalentValue
  12. // is possible (if the ulp size switches right at nextNonEquivalentValue), so drop by 2 ulps and
  13. // increment back up to closest within-ulp value.
  14. double highestEquivalentValue = nextNonEquivalentValue - (2 * Math.ulp(nextNonEquivalentValue));
  15. while (highestEquivalentValue + Math.ulp(highestEquivalentValue) < nextNonEquivalentValue) {
  16. highestEquivalentValue += Math.ulp(highestEquivalentValue);
  17. }
  18. return highestEquivalentValue;
  19. }

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

  1. Math.ceil((value + Math.ulp(value)) / currentHighestValueLimitInAutoRange) - 1.0);
  2. shiftCoveredRangeToTheLeft(shiftAmount);

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

  1. @GwtIncompatible // #trueLog2, Math.ulp
  2. public void testLog2Accuracy() {
  3. for (double d : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
  4. double dmLog2 = DoubleMath.log2(d);
  5. double trueLog2 = trueLog2(d);
  6. assertTrue(Math.abs(dmLog2 - trueLog2) <= Math.ulp(trueLog2));
  7. }
  8. }

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

  1. @GwtIncompatible // Math.ulp
  2. public void testFactorial() {
  3. for (int i = 0; i <= DoubleMath.MAX_FACTORIAL; i++) {
  4. double actual = BigIntegerMath.factorial(i).doubleValue();
  5. double result = DoubleMath.factorial(i);
  6. assertEquals(actual, result, Math.ulp(actual));
  7. }
  8. }

代码示例来源:origin: MovingBlocks/Terasology

  1. /**
  2. * Create a region with center point and x,y,z coordinate extents size
  3. * @param center the center point of region
  4. * @param extents the extents size of each side of region
  5. * @return a new region base on the center point and extents size
  6. */
  7. public static Region3i createFromCenterExtents(BaseVector3f center, BaseVector3f extents) {
  8. Vector3f min = new Vector3f(center.x() - extents.x(), center.y() - extents.y(), center.z() - extents.z());
  9. Vector3f max = new Vector3f(center.x() + extents.x(), center.y() + extents.y(), center.z() + extents.z());
  10. max.x = max.x - Math.ulp(max.x);
  11. max.y = max.y - Math.ulp(max.y);
  12. max.z = max.z - Math.ulp(max.z);
  13. return createFromMinMax(new Vector3i(min), new Vector3i(max));
  14. }

代码示例来源:origin: org.apache.commons/commons-math3

  1. boolean done = false;
  2. while (!done) {
  3. done = b - a <= Math.ulp(c);
  4. pmc = 1;
  5. pc = c;

代码示例来源:origin: OryxProject/oryx

  1. threshold += Math.ulp(threshold);

代码示例来源:origin: org.apache.commons/commons-math3

  1. boolean done = false;
  2. while (!done) {
  3. done = b - a <= Math.ulp(c);
  4. hmc = H0;
  5. hc = H1 * c;

代码示例来源:origin: stackoverflow.com

  1. public class Test1
  2. {
  3. public static void main(String[] args) throws Exception
  4. {
  5. long long1 = Long.MAX_VALUE - 100L;
  6. double dbl1 = long1;
  7. long long2 = long1+1;
  8. double dbl2 = dbl1+1;
  9. double dbl3 = dbl2+Math.ulp(dbl2);
  10. System.out.printf("%d %d\n%f %f %f", long1, long2, dbl1, dbl2, dbl3);
  11. }
  12. }

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. if (Math.abs(triangleSafetyFactor+ triangleSlopeFactor + triangleTimeFactor - 1) > Math.ulp(1) * 3) {
  2. throw new ParameterException(Message.TRIANGLE_NOT_AFFINE);

代码示例来源:origin: pholser/junit-quickcheck

  1. @Test public void negativeMeanProbability() {
  2. thrown.expect(IllegalArgumentException.class);
  3. distro.probabilityOfMean(-ulp(0));
  4. }

代码示例来源:origin: pholser/junit-quickcheck

  1. @Test public void negativeProbability() {
  2. thrown.expect(IllegalArgumentException.class);
  3. distro.sample(-ulp(0), random);
  4. }

代码示例来源:origin: pholser/junit-quickcheck

  1. @Test public void greaterThanOneProbability() {
  2. thrown.expect(IllegalArgumentException.class);
  3. distro.sample(1 + ulp(1), random);
  4. }

代码示例来源:origin: locationtech/spatial4j

  1. backRadius -= Math.max(Math.ulp(Math.abs(backY)+backRadius), Math.ulp(Math.abs(backX)+backRadius));
  2. if (inverseCircle != null) {
  3. inverseCircle.reset(backX, backY, backRadius);

相关文章