value += (modDiv * mod + 4) / 5; final double d = Math.scalb((double) value, exp); return negative ? -d : d;
/** * Generates a number in [0, 2^numBits) with an exponential distribution. The floor of the log2 of * the absolute value of the result is chosen uniformly at random in [0, numBits), and then the * result is chosen from those possibilities uniformly at random. * * <p>Zero is treated as having log2 == 0. */ static double randomDouble(int maxExponent) { double result = RANDOM_SOURCE.nextDouble(); result = Math.scalb(result, RANDOM_SOURCE.nextInt(maxExponent + 1)); return RANDOM_SOURCE.nextBoolean() ? result : -result; }
@Override protected ExprEval eval(ExprEval x, ExprEval y) { return ExprEval.of(Math.scalb(x.asDouble(), y.asInt())); } }
@GwtIncompatible // DoubleMath.log2(double, RoundingMode) public void testRoundLog2Half() { // We don't expect perfect rounding accuracy. for (int exp : asList(-1022, -50, -1, 0, 1, 2, 3, 4, 100, 1022, 1023)) { for (RoundingMode mode : asList(HALF_EVEN, HALF_UP, HALF_DOWN)) { double x = Math.scalb(Math.sqrt(2) + 0.001, exp); double y = Math.scalb(Math.sqrt(2) - 0.001, exp); if (exp < 0) { assertEquals(exp + 1, DoubleMath.log2(x, mode)); assertEquals(exp, DoubleMath.log2(y, mode)); } else { assertEquals(exp + 1, DoubleMath.log2(x, mode)); assertEquals(exp, DoubleMath.log2(y, mode)); } } } }
for (int j = 0; j < registerSet.count; j++) { int val = registerSet.get(j); registerSum += Math.scalb(1d, -val); if (val == 0) { zeros++;
@GwtIncompatible // DoubleMath.log2(double, RoundingMode) public void testRoundLog2Exact() { for (double x : POSITIVE_FINITE_DOUBLE_CANDIDATES) { boolean isPowerOfTwo = StrictMath.pow(2.0, DoubleMath.log2(x, FLOOR)) == x; try { int log2 = DoubleMath.log2(x, UNNECESSARY); assertEquals(x, Math.scalb(1.0, log2)); assertTrue(isPowerOfTwo); } catch (ArithmeticException e) { assertFalse(isPowerOfTwo); } } }
@Override public double size(Token next) { LongToken n = (LongToken) next; long v = n.token - token; // Overflow acceptable and desired. double d = Math.scalb((double) v, -Long.SIZE); // Scale so that the full range is 1. return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1. }
@Override public double size(Token next) { LongToken n = (LongToken) next; long v = n.token - token; // Overflow acceptable and desired. double d = Math.scalb((double) v, -Long.SIZE); // Scale so that the full range is 1. return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1. }
@Override public double size(Token next) { LongToken n = (LongToken) next; long v = n.token - token; // Overflow acceptable and desired. double d = Math.scalb((double) v, -Long.SIZE); // Scale so that the full range is 1. return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1. }
/** * Returns d x 2<sup>scaleFactor</sup> rounded as if performed by a single * correctly rounded floating-point multiply to a member of the double value * set. */ public static double scalb(double d, int scaleFactor) { return java.lang.Math.scalb(d, scaleFactor); }
/** * Returns f x 2<sup>scaleFactor</sup> rounded as if performed by a single * correctly rounded floating-point multiply to a member of the float value * set. */ public static float scalb(float f, int scaleFactor) { return java.lang.Math.scalb(f, scaleFactor); }
public double size(Token next) { BigIntegerToken n = (BigIntegerToken) next; BigInteger v = n.token.subtract(token); // Overflow acceptable and desired. double d = Math.scalb(v.doubleValue(), -127); // Scale so that the full range is 1. return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1. } }
public double size(Token next) { BigIntegerToken n = (BigIntegerToken) next; BigInteger v = n.token.subtract(token); // Overflow acceptable and desired. double d = Math.scalb(v.doubleValue(), -127); // Scale so that the full range is 1. return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1. } }
/** {@inheritDoc} */ public SparseGradient scalb(final int n) { final SparseGradient out = new SparseGradient(Math.scalb(value, n), Collections.<Integer, Double> emptyMap()); for (Map.Entry<Integer, Double> entry : derivatives.entrySet()) { out.derivatives.put(entry.getKey(), Math.scalb(entry.getValue(), n)); } return out; }
/** {@inheritDoc} * @since 3.2 */ public DerivativeStructure scalb(final int n) { final DerivativeStructure ds = new DerivativeStructure(compiler); for (int i = 0; i < ds.data.length; ++i) { ds.data[i] = Math.scalb(data[i], n); } return ds; }
/** {@inheritDoc} * @since 3.2 */ public Decimal64 scalb(final int n) { return new Decimal64(Math.scalb(value, n)); }
/** * Returns {@code true} if the given floating point numbers are considered equal. * The tolerance factor used in this method is arbitrary and may change in any future version. */ static boolean epsilonEquals(final double expected, final double actual) { return Math.abs(expected - actual) <= Math.scalb(Math.ulp(expected), 4); }
public static double ldexp(double v, PyObject wObj) { long w = getLong(wObj); if (w < Integer.MIN_VALUE) { w = Integer.MIN_VALUE; } else if (w > Integer.MAX_VALUE) { w = Integer.MAX_VALUE; } return exceptInf(Math.scalb(v, (int)w), v); }
@Override protected ExprEval eval(ExprEval x, ExprEval y) { return ExprEval.of(Math.scalb(x.asDouble(), y.asInt())); } }
public void execute(Context ctx) { double a = ctx.getFloatArgument(0); long b = ctx.getIntArgument(0); int intVal = ((Long) b).intValue(); ctx.setReturnValues(new BFloat(Math.scalb(a, intVal))); } }