/** * Creates a new {@code AtomicDouble} with the given initial value. * * @param initialValue the initial value */ public AtomicDouble(double initialValue) { value = doubleToRawLongBits(initialValue); }
/** * Sets to the given value. * * @param newValue the new value */ public final void set(double newValue) { long next = doubleToRawLongBits(newValue); value = next; }
static double scaleNormalize(double x) { long significand = doubleToRawLongBits(x) & SIGNIFICAND_MASK; return longBitsToDouble(significand | ONE_BITS); }
/** * Atomically sets the value to the given updated value if the current value is <a * href="#bitEquals">bitwise equal</a> to the expected value. * * @param expect the expected value * @param update the new value * @return {@code true} if successful. False return indicates that the actual value was not * bitwise equal to the expected value. */ public final boolean compareAndSet(double expect, double update) { return updater.compareAndSet(this, doubleToRawLongBits(expect), doubleToRawLongBits(update)); }
/** * Atomically sets the element at position {@code i} to the given updated value if the current * value is <a href="#bitEquals">bitwise equal</a> to the expected value. * * @param i the index * @param expect the expected value * @param update the new value * @return true if successful. False return indicates that the actual value was not equal to the * expected value. */ public final boolean compareAndSet(int i, double expect, double update) { return longs.compareAndSet(i, doubleToRawLongBits(expect), doubleToRawLongBits(update)); }
/** * Sets the element at position {@code i} to the given value. * * @param i the index * @param newValue the new value */ public final void set(int i, double newValue) { long next = doubleToRawLongBits(newValue); longs.set(i, next); }
/** * Eventually sets the element at position {@code i} to the given value. * * @param i the index * @param newValue the new value */ public final void lazySet(int i, double newValue) { long next = doubleToRawLongBits(newValue); longs.lazySet(i, next); }
/** * Eventually sets to the given value. * * @param newValue the new value */ public final void lazySet(double newValue) { long next = doubleToRawLongBits(newValue); updater.lazySet(this, next); }
/** * Atomically sets to the given value and returns the old value. * * @param newValue the new value * @return the previous value */ public final double getAndSet(double newValue) { long next = doubleToRawLongBits(newValue); return longBitsToDouble(updater.getAndSet(this, next)); }
/** * Atomically sets the element at position {@code i} to the given value and returns the old value. * * @param i the index * @param newValue the new value * @return the previous value */ public final double getAndSet(int i, double newValue) { long next = doubleToRawLongBits(newValue); return longBitsToDouble(longs.getAndSet(i, next)); }
/** * Adds a CONSTANT_Double_info to the constant pool of this symbol table. Does nothing if the * constant pool already contains a similar item. * * @param value a double. * @return a new or already existing Symbol with the given value. */ Symbol addConstantDouble(final double value) { return addConstantLongOrDouble(Symbol.CONSTANT_DOUBLE_TAG, Double.doubleToRawLongBits(value)); }
/** The notion of equality used by AtomicDoubleArray */ static boolean bitEquals(double x, double y) { return Double.doubleToRawLongBits(x) == Double.doubleToRawLongBits(y); }
@Override public final Hasher putDouble(double d) { return putLong(Double.doubleToRawLongBits(d)); }
/** The notion of equality used by AtomicDouble */ static boolean bitEquals(double x, double y) { return Double.doubleToRawLongBits(x) == Double.doubleToRawLongBits(y); }
@Override public ByteBuf writeDouble(double value) { writeLong(Double.doubleToRawLongBits(value)); return this; }
static long getSignificand(double d) { checkArgument(isFinite(d), "not a normal value"); int exponent = getExponent(d); long bits = doubleToRawLongBits(d); bits &= SIGNIFICAND_MASK; return (exponent == MIN_EXPONENT - 1) ? bits << 1 : bits | IMPLICIT_BIT; }
static void assertBitEquals(double x, double y) { assertEquals(Double.doubleToRawLongBits(x), Double.doubleToRawLongBits(y)); }
static void assertBitEquals(double x, double y) { assertEquals(Double.doubleToRawLongBits(x), Double.doubleToRawLongBits(y)); }
public void testOneBits() { assertEquals(DoubleUtils.ONE_BITS, Double.doubleToRawLongBits(1.0)); }
/** Reconstitutes the instance from a stream (that is, deserializes it). */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); int length = s.readInt(); ImmutableLongArray.Builder builder = ImmutableLongArray.builder(); for (int i = 0; i < length; i++) { builder.add(doubleToRawLongBits(s.readDouble())); } this.longs = new AtomicLongArray(builder.build().toArray()); } }