public DurationValue sub( DurationValue that ) { try { return duration( Math.subtractExact( this.months, that.months ), Math.subtractExact( this.days, that.days ), Math.subtractExact( this.seconds, that.seconds ), Math.subtractExact( this.nanos, that.nanos ) ); } catch ( ArithmeticException e ) { throw invalidDurationSubtract( this, that, e ); } }
/** * Returns the time left between the deadline and now. The result is negative if the deadline * has passed. */ public Duration timeLeft() { return Duration.ofNanos(Math.subtractExact(timeNanos, System.nanoTime())); }
/** * Overflow safe subtraction of two longs * * @param a left-hand operand * @param b right-hand operand * @return a - b */ public static LongValue subtract( long a, long b ) { return longValue( Math.subtractExact( a, b ) ); }
public static boolean willAdditionOverflow(int left, int right) { try { Math.addExact(left, right); return false; } catch (ArithmeticException e) { return true; } } public static boolean willSubtractionOverflow(int left, int right) { try { Math.subtractExact(left, right); return false; } catch (ArithmeticException e) { return true; } }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.INTEGER) public static long subtract(@SqlType(StandardTypes.INTEGER) long left, @SqlType(StandardTypes.INTEGER) long right) { try { return Math.subtractExact((int) left, (int) right); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("integer subtraction overflow: %s - %s", left, right), e); } }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.BIGINT) public static long subtract(@SqlType(StandardTypes.BIGINT) long left, @SqlType(StandardTypes.BIGINT) long right) { try { return Math.subtractExact(left, right); } catch (ArithmeticException e) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("bigint subtraction overflow: %s - %s", left, right), e); } }
lhs instanceof Byte || rhs instanceof Byte ) return Math.subtractExact( ((Number) lhs).longValue(), ((Number) rhs).longValue() );
/** * Subtracts the value of the supplied accumulator from this one, * throwing an exception in the case of integer overflow. */ public LongAccumulator subtract(LongAccumulator that) { this.value = Math.subtractExact(this.value, that.value); return this; }
/** * Subtracts the supplied value from this accumulator, throwing an * exception in the case of integer overflow. */ public LongAccumulator subtract(long value) { this.value = Math.subtractExact(this.value, value); return this; }
/** * Returns the time left between the deadline and now. The result is negative if the deadline * has passed. */ public Duration timeLeft() { return Duration.ofNanos(Math.subtractExact(timeNanos, System.nanoTime())); }
/** * Return the <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place">ULP</a> * distance of the given two double values. * * @param a first double. * @param b second double. * @return the ULP distance. * @throws ArithmeticException if the distance doesn't fit in a long value. */ public static long ulpDistance(final double a, final double b) { return Math.subtractExact(ulpPosition(a), ulpPosition(b)); }
/** * @param context * @return RubyInteger */ public IRubyObject op_minus_one(ThreadContext context) { try { return newFixnum(context.runtime, Math.subtractExact(value, 1)); } catch (ArithmeticException ae) { return subtractAsBignum(context, 1); } }
private RubyInteger subtractFixnum(ThreadContext context, RubyFixnum other) { try { return newFixnum(context.runtime, Math.subtractExact(value, other.value)); } catch (ArithmeticException ae) { return subtractAsBignum(context, other.value); } }
@Override public MediumInteger subtract(final GenericInteger subtractedVal) { final int result = Math.subtractExact(value, subtractedVal.intValueExact()); return result == value ? this : MediumInteger.valueOf(result); }
@Override public IRubyObject op_minus(ThreadContext context, long otherValue) { try { return newFixnum(context.runtime, Math.subtractExact(value, otherValue)); } catch (ArithmeticException ae) { return subtractAsBignum(context, otherValue); } }
/** * @param context * @return RubyInteger */ public IRubyObject op_minus_one(ThreadContext context) { try { return newFixnum(context.runtime, Math.subtractExact(value, 1)); } catch (ArithmeticException ae) { return subtractAsBignum(context, 1); } }
/** * @param context * @return RubyInteger */ public IRubyObject op_minus_two(ThreadContext context) { try { return newFixnum(context.runtime, Math.subtractExact(value, 2)); } catch (ArithmeticException ae) { return subtractAsBignum(context, 2); } }
private RubyInteger subtractFixnum(ThreadContext context, RubyFixnum other) { try { return newFixnum(context.runtime, Math.subtractExact(value, other.value)); } catch (ArithmeticException ae) { return subtractAsBignum(context, other.value); } }
void checkForOverflow() { int sumMin = 0, sumMax = 0; for (int i = 0; i < list.length; i++) { int n1 = list[i].min(); int n2 = list[i].max(); sumMin = Math.addExact(sumMin, n1); sumMax = Math.addExact(sumMax, n2); } Math.subtractExact(sumMin, sum.max()); Math.subtractExact(sumMax, sum.min()); }
@Override public FastMoney subtract(MonetaryAmount subtrahend) { checkAmountParameter(subtrahend); if (subtrahend.isZero()) { return this; } return new FastMoney(Math.subtractExact(this.number, getInternalNumber(subtrahend.getNumber(), false)), getCurrency()); }