@Override int maxEncodedSize(int bytes) { return alphabet.charsPerChunk * divide(bytes, alphabet.bytesPerChunk, CEILING); }
@Override public int size() { return IntMath.divide(list.size(), size, RoundingMode.CEILING); }
/** * 能控制rounding方向的int相除. * * jdk的'/'运算符,直接向下取整 */ public static int divide(int p, int q, RoundingMode mode) { return IntMath.divide(p, q, mode); }
@Override int maxEncodedSize(int bytes) { return alphabet.charsPerChunk * divide(bytes, alphabet.bytesPerChunk, CEILING); }
@Override int maxEncodedSize(int bytes) { return alphabet.charsPerChunk * divide(bytes, alphabet.bytesPerChunk, CEILING); }
@Override int maxEncodedSize(int bytes) { int unseparatedSize = delegate.maxEncodedSize(bytes); return unseparatedSize + separator.length() * divide(Math.max(0, unseparatedSize - 1), afterEveryChars, FLOOR); }
@Override public int size() { return IntMath.divide(list.size(), size, RoundingMode.CEILING); }
@Override int maxEncodedSize(int bytes) { int unseparatedSize = delegate.maxEncodedSize(bytes); return unseparatedSize + separator.length() * divide(Math.max(0, unseparatedSize - 1), afterEveryChars, FLOOR); }
@Override public int size() { return IntMath.divide(list.size(), size, RoundingMode.CEILING); }
private static double expectedLargeDatasetPercentile(int index) { // We have q=100, k=index, and N=9951. Therefore k*(N-1)/q is 99.5*index. If index is even, that // is an integer 199*index/2. If index is odd, that is halfway between floor(199*index/2) and // ceil(199*index/2). if (index % 2 == 0) { int position = IntMath.divide(199 * index, 2, UNNECESSARY); return PSEUDORANDOM_DATASET_SORTED.get(position); } else { int positionFloor = IntMath.divide(199 * index, 2, FLOOR); int positionCeil = IntMath.divide(199 * index, 2, CEILING); double lowerValue = PSEUDORANDOM_DATASET_SORTED.get(positionFloor); double upperValue = PSEUDORANDOM_DATASET_SORTED.get(positionCeil); return (lowerValue + upperValue) / 2.0; } }
private void createPartitions(String tableName, int partitionsToCreate) { // This is done in tests rather than as a requirement, because TableRequirements.immutableTable cannot be partitioned // and mutable table is recreated before every test (and this takes a lot of time). // TODO convert to immutableTable + TableDefinition once immutableTable supports partitioned tables requireNonNull(tableName, "tableName is null"); int maxPartitionsAtOnce = 100; IntStream.range(0, IntMath.divide(partitionsToCreate, maxPartitionsAtOnce, RoundingMode.UP)) .forEach(batch -> { int rangeStart = batch * maxPartitionsAtOnce; int rangeEndInclusive = min((batch + 1) * maxPartitionsAtOnce, partitionsToCreate) - 1; query(format( "INSERT INTO %s (part_col, col) " + "SELECT CAST(id AS integer), 42 FROM UNNEST (sequence(%s, %s)) AS u(id)", tableName, rangeStart, rangeEndInclusive)); }); }
@Override int maxEncodedSize(int bytes) { int unseparatedSize = delegate.maxEncodedSize(bytes); return unseparatedSize + separator.length() * divide(Math.max(0, unseparatedSize - 1), afterEveryChars, FLOOR); }
validPadding[divide(i * 8, bitsPerChar, CEILING)] = true;
private static Rect2i worldToTileArea(Rect2i area) { int chunkMinX = IntMath.divide(area.minX(), TILE_SIZE_X, RoundingMode.FLOOR); int chunkMinZ = IntMath.divide(area.minY(), TILE_SIZE_Y, RoundingMode.FLOOR); int chunkMaxX = IntMath.divide(area.maxX(), TILE_SIZE_X, RoundingMode.CEILING); int chunkMaxZ = IntMath.divide(area.maxY(), TILE_SIZE_Y, RoundingMode.CEILING); return Rect2i.createFromMinAndMax(chunkMinX, chunkMinZ, chunkMaxX, chunkMaxZ); }
public void testZeroDivIsAlwaysZero() { for (int q : NONZERO_INTEGER_CANDIDATES) { for (RoundingMode mode : ALL_ROUNDING_MODES) { assertEquals(0, IntMath.divide(0, q, mode)); } } }
public void testDivByZeroAlwaysFails() { for (int p : ALL_INTEGER_CANDIDATES) { for (RoundingMode mode : ALL_ROUNDING_MODES) { try { IntMath.divide(p, 0, mode); fail("Expected ArithmeticException"); } catch (ArithmeticException expected) { } } } }
int approxSize = IntMath.divide(n * IntMath.log2(n, CEILING), Long.SIZE, CEILING); ArrayList<BigInteger> bignums = new ArrayList<>(approxSize);
@Override public LongStream events() throws IOException { return lines().flatMapToLong(line -> { String[] array = line.split(",", 5); if (array.length <= 4) { return LongStream.empty(); } long startBlock = Long.parseLong(array[1]); int size = Integer.parseInt(array[2]); int sequence = IntMath.divide(size, BLOCK_SIZE, RoundingMode.UP); char readWrite = Character.toLowerCase(array[3].charAt(0)); return (readWrite == 'w') ? LongStream.empty() : LongStream.range(startBlock, startBlock + sequence); }); } }
@AndroidIncompatible // slow public void testDivNonZero() { for (int p : NONZERO_INTEGER_CANDIDATES) { for (int q : NONZERO_INTEGER_CANDIDATES) { for (RoundingMode mode : ALL_SAFE_ROUNDING_MODES) { // Skip some tests that fail due to GWT's non-compliant int implementation. // TODO(cpovirk): does this test fail for only some rounding modes or for all? if (p == -2147483648 && q == -1 && intsCanGoOutOfRange()) { continue; } int expected = new BigDecimal(valueOf(p)).divide(new BigDecimal(valueOf(q)), 0, mode).intValue(); assertEquals(p + "/" + q, force32(expected), IntMath.divide(p, q, mode)); } } } }
@AndroidIncompatible // presumably slow public void testDivNonZeroExact() { for (int p : NONZERO_INTEGER_CANDIDATES) { for (int q : NONZERO_INTEGER_CANDIDATES) { // Skip some tests that fail due to GWT's non-compliant int implementation. if (p == -2147483648 && q == -1 && intsCanGoOutOfRange()) { continue; } boolean dividesEvenly = (p % q) == 0; try { assertEquals(p + "/" + q, p, IntMath.divide(p, q, UNNECESSARY) * q); assertTrue(p + "/" + q + " not expected to divide evenly", dividesEvenly); } catch (ArithmeticException e) { assertFalse(p + "/" + q + " expected to divide evenly", dividesEvenly); } } } }