Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
function Adding_Will_Overflow (X, Y : Integer) return Boolean is
begin
return X > 0 and Y > 0 and X > Integer'Last - Y;
end Adding_Will_Overflow;
bool addingWillOverflow(int x, int y)
{
bool willOverflow = false;
if (x > 0 && y > 0)
if (y > (int.MaxValue - x)) willOverflow = true;
if (x < 0 && y < 0)
if (y < (int.MinValue - x)) willOverflow = true;
return willOverflow;
}
logical function adding_will_overflow (x,y) result(res)
integer, intent(in) :: x, y
res = (x > 0 .and. y > huge(x) - x) .or. (x < 0 .and. y < huge(x) - x)
end function adding_will_overflow
addingWillOverflow x y = y > maxBound - x
function addingWillOverflow(x, y) {
return x > 0 && y > 0 && x > Number.MAX_SAFE_INTEGER - y
}
public boolean addingWillOverflow(int x, int y){
boolean willOverFlow = false;
if(x > 0 && y > 0){
if(y > (Integer.MAX_VALUE - x)){
willOverFlow = true;
}
}
if(x < 0 && y < 0){
if(y < (Integer.MIN_VALUE - x)){
willOverFlow = true;
}
}
return willOverFlow;
}
local function intadding_will_overflow(x,y)
return x>0
and y>0 and x+y<x
or y<0 and x+y>x
end
function _addingWillOverflow($x, $y): bool
{
return (PHP_INT_MAX - $y) > $x;
}
function AddingWillOverFlow(x,y: Integer): Boolean;
begin
Result := ((x > 0) and (y > 0) and (x > (High(Integer)-y))) or
((x < 0) and (y < 0) and ((Low(Integer)-x) > y));
end;
function AddingWillOverFlow(x,y: Integer): Boolean;
begin
Result := (x > 0) and (y > 0) and (x > (MaxInt-y));
end;
sub adding_will_overflow {
my ($x, $y) = @_;
return 'Inf' eq $x + $y;
}
def adding_will_overflow(x,y):
return False
def addingWillOverflow(x,y)
false
end
fn adding_will_overflow(x: usize, y: usize) -> bool {
x.checked_add(y).is_none()
}