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

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

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

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

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

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

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

/**
 * Returns the argument's ulp (unit in the last place). The size of a ulp of
 * a float value is the positive distance between this value and the float
 * value next larger in magnitude. For non-NaN {@code x},
 * {@code ulp(-x) == ulp(x)}.
 * <p>
 * Special cases:
 * <ul>
 * <li>{@code ulp(+0.0) = Float.MIN_VALUE}</li>
 * <li>{@code ulp(-0.0) = Float.MIN_VALUE}</li>
 * <li>{@code ulp(+infinity) = infinity}</li>
 * <li>{@code ulp(-infinity) = infinity}</li>
 * <li>{@code ulp(NaN) = NaN}</li>
 * </ul>
 *
 * @param f
 *            the floating-point value to compute ulp of.
 * @return the size of a ulp of the argument.
 */
public static float ulp(float f) {
  return Math.ulp(f);
}

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

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

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

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

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

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

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

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

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

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

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

@GwtIncompatible // #trueLog2, Math.ulp
public void testLog2Accuracy() {
 for (double d : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
  double dmLog2 = DoubleMath.log2(d);
  double trueLog2 = trueLog2(d);
  assertTrue(Math.abs(dmLog2 - trueLog2) <= Math.ulp(trueLog2));
 }
}

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

@GwtIncompatible // Math.ulp
public void testFactorial() {
 for (int i = 0; i <= DoubleMath.MAX_FACTORIAL; i++) {
  double actual = BigIntegerMath.factorial(i).doubleValue();
  double result = DoubleMath.factorial(i);
  assertEquals(actual, result, Math.ulp(actual));
 }
}

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

/**
 * Create a region with center point and x,y,z coordinate extents size
 * @param center the center point of region
 * @param extents the extents size of each side of region
 * @return a new region base on the center point and extents size
 */
public static Region3i createFromCenterExtents(BaseVector3f center, BaseVector3f extents) {
  Vector3f min = new Vector3f(center.x() - extents.x(), center.y() - extents.y(), center.z() - extents.z());
  Vector3f max = new Vector3f(center.x() + extents.x(), center.y() + extents.y(), center.z() + extents.z());
  max.x = max.x - Math.ulp(max.x);
  max.y = max.y - Math.ulp(max.y);
  max.z = max.z - Math.ulp(max.z);
  return createFromMinMax(new Vector3i(min), new Vector3i(max));
}

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

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

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

threshold += Math.ulp(threshold);

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

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

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

public class Test1  
{

  public static void main(String[] args) throws Exception 
  {
    long   long1 = Long.MAX_VALUE - 100L;
    double dbl1  = long1;
    long   long2 = long1+1;
    double dbl2  = dbl1+1;
    double dbl3  = dbl2+Math.ulp(dbl2);

    System.out.printf("%d %d\n%f %f %f", long1, long2, dbl1, dbl2, dbl3);
  }

}

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

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

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

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

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

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

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

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

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

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

相关文章