public void testLog2ZeroAlwaysThrows() { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { LongMath.log2(0L, mode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } } }
public void testLog2NegativeAlwaysThrows() { for (long x : NEGATIVE_LONG_CANDIDATES) { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { LongMath.log2(x, mode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } } } }
long denominatorAccum = 1; int bits = LongMath.log2(n, RoundingMode.CEILING);
public void testLog2MatchesBigInteger() { for (long x : POSITIVE_LONG_CANDIDATES) { for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) { // The BigInteger implementation is tested separately, use it as the reference. assertEquals(BigIntegerMath.log2(valueOf(x), mode), LongMath.log2(x, mode)); } } }
long denominatorAccum = 1; int bits = LongMath.log2(n, RoundingMode.CEILING);
long denominatorAccum = 1; int bits = LongMath.log2(n, RoundingMode.CEILING);
int nBits = LongMath.log2(n, RoundingMode.CEILING);
int nBits = LongMath.log2(n, RoundingMode.CEILING);
public void testLog2Exact() { for (long x : POSITIVE_LONG_CANDIDATES) { // We only expect an exception if x was not a power of 2. boolean isPowerOf2 = LongMath.isPowerOfTwo(x); try { assertEquals(x, 1L << LongMath.log2(x, UNNECESSARY)); assertTrue(isPowerOf2); } catch (ArithmeticException e) { assertFalse(isPowerOf2); } } }
int nBits = LongMath.log2(n, RoundingMode.CEILING);
/** Return floor(log2(n)) for positive integer n. Returns -1 iff n == 0. */ @VisibleForTesting int log2Floor(long n) { checkArgument(n >= 0); return n == 0 ? -1 : LongMath.log2(n, RoundingMode.FLOOR); }
public IngressLocationInstrumentation(Map<IngressLocation, BooleanExpr> srcIpConstraints) { _srcIpConstraints = ImmutableMap.copyOf(srcIpConstraints); _fieldBits = max(LongMath.log2(_srcIpConstraints.size(), RoundingMode.CEILING), 1); _ingressLocationField = new Field(INGRESS_LOCATION_FIELD_NAME, _fieldBits); _ingressLocations = ImmutableList.copyOf(srcIpConstraints.keySet()); }
public void testLog2NegativeAlwaysThrows() { for (long x : NEGATIVE_LONG_CANDIDATES) { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { LongMath.log2(x, mode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) {} } } }
@Benchmark int log2(int reps) { int tmp = 0; for (int i = 0; i < reps; i++) { int j = i & ARRAY_MASK; tmp += LongMath.log2(positive[j], mode); } return tmp; }
/** Allocates a variable for the sources and initializes SANE. */ private static BDDSourceManager forSourcesInternal( BDDPacket pkt, Set<String> activeAndReferenced, Set<String> activeButNotReferenced) { if (activeAndReferenced.isEmpty()) { return forNoReferencedSources(pkt, activeButNotReferenced); } int bitsRequired = LongMath.log2( valuesRequired(activeAndReferenced, activeButNotReferenced), RoundingMode.CEILING); BDDInteger sourceVar = pkt.allocateBDDInteger(VAR_NAME, bitsRequired, false); return forSourcesInternal(pkt, sourceVar, activeAndReferenced, activeButNotReferenced); }
public void testLog2ZeroAlwaysThrows() { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { LongMath.log2(0L, mode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) {} } }
public void testLog2Exact() { for (long x : POSITIVE_LONG_CANDIDATES) { // We only expect an exception if x was not a power of 2. boolean isPowerOf2 = LongMath.isPowerOfTwo(x); try { assertEquals(x, 1L << LongMath.log2(x, UNNECESSARY)); assertTrue(isPowerOf2); } catch (ArithmeticException e) { assertFalse(isPowerOf2); } } }