JSAbstractOperations { static Double ToUInt32(Object arg) { Double number = ToNumber(arg); if (number.isNaN() || number.isInfinite() || number == 0.0) { return 0.0; } Double posInt = ToInteger(number); BigInteger posIntBig = new BigInteger(PLAIN_INTEGER_FORMAT.format(posInt)); BigInteger int32bit = posIntBig.mod(UINT_MAX_VALUE); return int32bit.doubleValue(); }   static final BigInteger UINT_MAX_VALUE; static final Double UINT_MAX_VALUE_D; static final BigInteger SINT_MAX_VALUE; static final BigInteger USHORT_MAX_VALUE; }
@Test public void testToUInt3201() { assertEquals(0.0, ToUInt32(NaN), 0.0); assertEquals(0.0, ToUInt32("abc"), 0.0); assertEquals(+0.0, ToUInt32(+0.0), 0.0); assertEquals(+0.0, ToUInt32(-0.0), 0.0); assertEquals(0.0, ToUInt32(Double.POSITIVE_INFINITY), 0.0); assertEquals(0.0, ToUInt32(Double.NEGATIVE_INFINITY), 0.0); }
@Test public void testToUInt3202() { assertEquals(1.0, ToUInt32(1.2345), 0.0); assertEquals(4294967291.0, ToUInt32(-5.4321), 0.0); assertEquals(0.0, ToUInt32(0.0), 0.0); assertEquals(1.0, ToUInt32(1), 0.0); assertEquals(4294967295.0, ToUInt32(-1), 0.0); assertEquals(4294967295.0, ToUInt32(4294967295.0), 0.0); assertEquals(4294967294.0, ToUInt32(4294967294.0), 0.0); assertEquals(0.0, ToUInt32(4294967296.0), 0.0); assertEquals(2147483649.0, ToUInt32(-2147483647.0), 0.0); assertEquals(2147483648.0, ToUInt32(-2147483648.0), 0.0); assertEquals(2147483647.0, ToUInt32(-2147483649.0), 0.0); assertEquals(1.0, ToUInt32(-4294967295.0), 0.0); assertEquals(0.0, ToUInt32(-4294967296.0), 0.0); assertEquals(4294967295.0, ToUInt32(-4294967297.0), 0.0); assertEquals(4294967295.0, ToUInt32(4294967295.0), 0.0); assertEquals(0.0, ToUInt32(4294967296.0), 0.0); assertEquals(1.0, ToUInt32(4294967297.0), 0.0); assertEquals(4294967295.0, ToUInt32(8589934591.0), 0.0); assertEquals(0.0, ToUInt32(8589934592.0), 0.0); assertEquals(1.0, ToUInt32(8589934593.0), 0.0); }
@Test public void testToUInt3203() { assertEquals(1.0, ToUInt32(true), 0.0); assertEquals(0.0, ToUInt32(false), 0.0); assertEquals(1.0, ToUInt32("1"), 0.0); assertEquals(4294967295.0, ToUInt32("-1.234"), 0.0); }
@Test public void testUInt3204() { Object o; o = new Object() { @SuppressWarnings("unused") public int valueOf() { return 1; } }; assertEquals(1.0, ToUInt32(o), 0.0); o = new Object() { @SuppressWarnings("unused") public int valueOf() { return 1; } public String toString() { return "0"; } }; assertEquals(1.0, ToUInt32(o), 0.0); o = new Object() { @SuppressWarnings("unused") public int valueOf() { return 1; } public String toString() { throw new RuntimeException("error"); } }; assertEquals(1.0, ToUInt32(o), 0.0); o = new Object() { public String toString() { return "1"; } }; assertEquals(1.0, ToUInt32(o), 0.0); o = new Object() { @SuppressWarnings("unused") public Object valueOf() { return new Object(); } public String toString() { return "1"; } }; assertEquals(1.0, ToUInt32(o), 0.0); try { o = new Object() { @SuppressWarnings("unused") public Object valueOf() { throw new RuntimeException("error"); } public String toString() { return "1"; } }; ToUInt32(o); throw new RuntimeException("Expected an exception, but got nothing"); } catch (RuntimeException e) { assertEquals("error", e.getMessage()); } try { o = new Object() { public String toString() { throw new RuntimeException("error"); } }; ToUInt32(o); throw new RuntimeException("Expected an exception, but got nothing"); } catch (RuntimeException e) { assertEquals("error", e.getMessage()); } }