changeset 461:e4fb177509b9

Avoid integer overflow (from Alexander Sherikov)
author hauberg
date Mon, 06 Jun 2011 20:04:28 +0000
parents d9b3c55e9b6c
children dd9a66134527
files inst/medfilt2.m
diffstat 1 files changed, 1 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);