/** Set the current value to the maximum of the current value or the provided value. */ public void max(double v) { if (Double.isFinite(v)) { double max = get(); while (isGreaterThan(v, max) && !compareAndSet(max, v)) { max = value.get(); } } }
/** Set the current value to the maximum of the current value or the provided value. */ public void max(double v) { if (Double.isFinite(v)) { double max = get(); while (isGreaterThan(v, max) && !compareAndSet(max, v)) { max = value.get(); } } }
@Test public void compareAndSet() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertTrue(v.compareAndSet(13.0, 42.0)); Assertions.assertEquals(42.0, v.get(), 1e-12); }
@Test public void compareAndSetFail() { AtomicDouble v = new AtomicDouble(13.0); Assertions.assertFalse(v.compareAndSet(12.0, 42.0)); Assertions.assertEquals(13.0, v.get(), 1e-12); }