@Override public Value subtract(Value v) { ValueLong other = (ValueLong) v; int sv = Long.signum(value); int so = Long.signum(other.value); // if the operands have the same sign, then overflow can not occur // if the second operand is 0, then overflow can not occur if (sv == so || so == 0) { return ValueLong.get(value - other.value); } // now, if the other value is Long.MIN_VALUE, it must be an overflow // x - Long.MIN_VALUE overflows for x>=0 return add(other.negate()); }
@Override public Value subtract(Value v) { ValueLong other = (ValueLong) v; int sv = Long.signum(value); int so = Long.signum(other.value); // if the operands have the same sign, then overflow can not occur // if the second operand is 0, then overflow can not occur if (sv == so || so == 0) { return ValueLong.get(value - other.value); } // now, if the other value is Long.MIN_VALUE, it must be an overflow // x - Long.MIN_VALUE overflows for x>=0 return add(other.negate()); }
@Override public Value subtract(Value v) { ValueLong other = (ValueLong) v; int sv = Long.signum(value); int so = Long.signum(other.value); // if the operands have the same sign, then overflow can not occur // if the second operand is 0, then overflow can not occur if (sv == so || so == 0) { return ValueLong.get(value - other.value); } // now, if the other value is Long.MIN_VALUE, it must be an overflow // x - Long.MIN_VALUE overflows for x>=0 return add(other.negate()); }
public Value subtract(Value v) throws SQLException { ValueLong other = (ValueLong) v; if (SysProperties.OVERFLOW_EXCEPTIONS) { int sv = value == 0 ? 0 : (value < 0 ? -1 : 1); int so = other.value == 0 ? 0 : (other.value < 0 ? -1 : 1); // if the operands have the same sign, then overflow can not occur // if the second operand is 0, then overflow can not occur if (sv == so || so == 0) { return ValueLong.get(value - other.value); } // now, if the other value is Long.MIN_VALUE, it must be an overflow // x - Long.MIN_VALUE overflows for x>=0 return add(other.negate()); } return ValueLong.get(value - other.value); }