From: Michael Orlitzky Date: Sat, 7 May 2011 17:16:01 +0000 (-0400) Subject: Catch out-of-bounds calls to value_at. X-Git-Tag: 0.0.1~327 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=d8bb807e89fbb193b373be111217813d5a4222e9;p=spline3.git Catch out-of-bounds calls to value_at. --- diff --git a/src/FunctionValues.hs b/src/FunctionValues.hs index 9fd3c78..e8bdcb8 100644 --- a/src/FunctionValues.hs +++ b/src/FunctionValues.hs @@ -74,8 +74,14 @@ eval f (Product x y) = (eval f x) * (eval f y) eval f (Quotient x y) = (eval f x) / (eval f y) value_at :: [[[Double]]] -> Int -> Int -> Int -> Double -value_at values i j k = - ((values !! k) !! j) !! i +value_at values i j k + | i < 0 = 0 + | j < 0 = 0 + | k < 0 = 0 + | length values <= k = 0 + | length (values !! k) <= j = 0 + | length ((values !! k) !! j) <= i = 0 + | otherwise = ((values !! k) !! j) !! i make_values :: [[[Double]]] -> Int -> Int -> Int -> FunctionValues make_values values i j k =