static double nextDown(double d) { return -Math.nextUp(-d); }
static double nextDown(double d) { return -Math.nextUp(-d); }
static double nextDown(double d) { return -Math.nextUp(-d); }
/** * Returns the next float larger than {@code f}. * @since 1.6 */ public static float nextUp(float f) { return Math.nextUp(f); }
/** * Returns the next double larger than {@code d}. * @since 1.6 */ public static double nextUp(double d) { return Math.nextUp(d); }
static double nextDown(double d) { return -Math.nextUp(-d); }
@Override protected ExprEval eval(double param) { return ExprEval.of(Math.nextUp(param)); } }
@Override Float nextNumber(Number actual) { float number = actual.floatValue(); return Math.min(Math.nextUp(number) - number, number - Math.nextDown(number)); }
@Override Double nextNumber(Number actual) { double number = actual.doubleValue(); return Math.min(Math.nextUp(number) - number, number - Math.nextDown(number)); }
@GwtIncompatible("Math::nextUp is not implemented") static BigDecimal asDecimal(double number) { if (number == NEGATIVE_INFINITY) { final BigDecimal result = BigDecimal.valueOf(Math.nextUp(NEGATIVE_INFINITY)); return result.subtract(INFINITY_DISTANCE.get()); } else if (number == POSITIVE_INFINITY) { final BigDecimal result = BigDecimal.valueOf(Math.nextDown(POSITIVE_INFINITY)); return result.add(INFINITY_DISTANCE.get()); } else { return BigDecimal.valueOf(number); } } }
double warmingQps = Math.nextUp(1.0 / (aboveToken * slope + 1.0 / count)); costTime = Math.round(1.0 * (acquireCount) / warmingQps * 1000); } else {
@Override public boolean canPass(Node node, int acquireCount, boolean prioritized) { long passQps = node.passQps(); long previousQps = node.previousPassQps(); syncToken(previousQps); // 开始计算它的斜率 // 如果进入了警戒线,开始调整他的qps long restToken = storedTokens.get(); if (restToken >= warningToken) { long aboveToken = restToken - warningToken; // 消耗的速度要比warning快,但是要比慢 // current interval = restToken*slope+1/count double warningQps = Math.nextUp(1.0 / (aboveToken * slope + 1.0 / count)); if (passQps + acquireCount <= warningQps) { return true; } } else { if (passQps + acquireCount <= count) { return true; } } return false; }
@GwtIncompatible static Iterator<Double> rangeClosedBy(double from, double toInclusive, double step) { if (from == toInclusive) { return of(from); } final double toExclusive = (step > 0) ? Math.nextUp(toInclusive) : Math.nextDown(toInclusive); return rangeBy(from, toExclusive, step); }
@OutputFunction(StandardTypes.VARCHAR) public static void output(SpatialPartitioningState state, BlockBuilder out) { if (state.getCount() == 0) { out.appendNull(); return; } List<Rectangle> samples = state.getSamples(); int partitionCount = state.getPartitionCount(); int maxItemsPerNode = (samples.size() + partitionCount - 1) / partitionCount; Rectangle envelope = state.getExtent(); // Add a small buffer on the right and upper sides Rectangle paddedExtent = new Rectangle(envelope.getXMin(), envelope.getYMin(), Math.nextUp(envelope.getXMax()), Math.nextUp(envelope.getYMax())); VARCHAR.writeString(out, KdbTreeUtils.toJson(buildKdbTree(maxItemsPerNode, paddedExtent, samples))); } }
@Test(dataProvider = "partitionCount") public void test(int partitionCount) { InternalAggregationFunction function = getFunction(); List<OGCGeometry> geometries = makeGeometries(); Block geometryBlock = makeGeometryBlock(geometries); Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size()); Rectangle expectedExtent = new Rectangle(-10, -10, Math.nextUp(10.0), Math.nextUp(10.0)); String expectedValue = getSpatialPartitioning(expectedExtent, geometries, partitionCount); AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1, 2), Optional.empty()); Page page = new Page(geometryBlock, partitionCountBlock); Accumulator accumulator = accumulatorFactory.createAccumulator(); accumulator.addInput(page); String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator)); assertEquals(aggregation, expectedValue); GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator(); groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); String groupValue = (String) getGroupValue(groupedAggregation, 0); assertEquals(groupValue, expectedValue); }
@Test public void testCastToBigint() { assertFunction("cast(37.7E0 as bigint)", BIGINT, 38L); assertFunction("cast(-37.7E0 as bigint)", BIGINT, -38L); assertFunction("cast(17.1E0 as bigint)", BIGINT, 17L); assertFunction("cast(-17.1E0 as bigint)", BIGINT, -17L); assertFunction("cast(9.2E18 as bigint)", BIGINT, 9200000000000000000L); assertFunction("cast(-9.2E18 as bigint)", BIGINT, -9200000000000000000L); assertFunction("cast(2.21E9 as bigint)", BIGINT, 2210000000L); assertFunction("cast(-2.21E9 as bigint)", BIGINT, -2210000000L); assertFunction("cast(17.5E0 as bigint)", BIGINT, 18L); assertFunction("cast(-17.5E0 as bigint)", BIGINT, -18L); assertFunction("cast(" + Math.nextDown(0x1.0p63) + " as bigint)", BIGINT, (long) Math.nextDown(0x1.0p63)); assertInvalidFunction("cast(" + 0x1.0p63 + " as bigint)", INVALID_CAST_ARGUMENT); assertInvalidFunction("cast(" + Math.nextUp(0x1.0p63) + " as bigint)", INVALID_CAST_ARGUMENT); assertInvalidFunction("cast(" + Math.nextDown(-0x1.0p63) + " as bigint)", INVALID_CAST_ARGUMENT); assertFunction("cast(" + -0x1.0p63 + " as bigint)", BIGINT, (long) -0x1.0p63); assertFunction("cast(" + Math.nextUp(-0x1.0p63) + " as bigint)", BIGINT, (long) Math.nextUp(-0x1.0p63)); assertInvalidFunction("cast(9.3E18 as bigint)", INVALID_CAST_ARGUMENT); assertInvalidFunction("cast(-9.3E18 as bigint)", INVALID_CAST_ARGUMENT); assertInvalidFunction("cast(infinity() as bigint)", INVALID_CAST_ARGUMENT); assertInvalidFunction("cast(-infinity() as bigint)", INVALID_CAST_ARGUMENT); assertInvalidFunction("cast(nan() as bigint)", INVALID_CAST_ARGUMENT); }
@Override public Query withinQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) { return FloatRange.newWithinQuery(field, new float[] {includeFrom ? (Float)from : Math.nextUp((Float)from)}, new float[] {includeTo ? (Float)to : Math.nextDown((Float)to)}); } @Override
@Override public Query intersectsQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) { return FloatRange.newIntersectsQuery(field, new float[] {includeFrom ? (Float)from : Math.nextUp((Float)from)}, new float[] {includeTo ? (Float)to : Math.nextDown((Float)to)}); } },
@Override public Query containsQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) { return FloatRange.newContainsQuery(field, new float[] {includeFrom ? (Float)from : Math.nextUp((Float)from)}, new float[] {includeTo ? (Float)to : Math.nextDown((Float)to)}); } @Override
@Override public Query toRangeQuery(final String name, final String lower, final String upper, final boolean lowerInclusive, final boolean upperInclusive) { return FloatPoint.newRangeQuery(name, lowerInclusive ? toFloat(lower) : Math.nextUp(toFloat(lower)), upperInclusive ? toFloat(upper) : Math.nextDown(toFloat(upper))); }