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; }
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; }
/** * 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); }
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; }
@Override protected ExprEval eval(double param) { return ExprEval.of(Math.ulp(param)); } }
/** * 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; }
/** * 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; }
Math.ceil((value + Math.ulp(value)) / currentHighestValueLimitInAutoRange) - 1.0); shiftCoveredRangeToTheLeft(shiftAmount);
@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)); } }
@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)); } }
/** * 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)); }
boolean done = false; while (!done) { done = b - a <= Math.ulp(c); pmc = 1; pc = c;
threshold += Math.ulp(threshold);
boolean done = false; while (!done) { done = b - a <= Math.ulp(c); hmc = H0; hc = H1 * c;
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); } }
if (Math.abs(triangleSafetyFactor+ triangleSlopeFactor + triangleTimeFactor - 1) > Math.ulp(1) * 3) { throw new ParameterException(Message.TRIANGLE_NOT_AFFINE);
@Test public void negativeMeanProbability() { thrown.expect(IllegalArgumentException.class); distro.probabilityOfMean(-ulp(0)); }
@Test public void negativeProbability() { thrown.expect(IllegalArgumentException.class); distro.sample(-ulp(0), random); }
@Test public void greaterThanOneProbability() { thrown.expect(IllegalArgumentException.class); distro.sample(1 + ulp(1), random); }