# HG changeset patch # User hauberg # Date 1307390668 0 # Node ID e4fb177509b9ad409a97c2efcb7776654c912833 # Parent d9b3c55e9b6c08efc25e288ed49c56e238885528 Avoid integer overflow (from Alexander Sherikov) diff --git a/inst/medfilt2.m b/inst/medfilt2.m --- a/inst/medfilt2.m +++ b/inst/medfilt2.m @@ -58,7 +58,7 @@ nth = floor(n/2); a = ordfilt2(A, nth, domain, padding); b = ordfilt2(A, nth + 1, domain, padding); - retval = (a + b)./2; + retval = a./2 + b./2; # split into two divisions to avoid overflow on integer data else nth = floor(n/2) + 1; retval = ordfilt2(A, nth, domain, padding);