From ef3fac58f9342d98b1f86e00c4dcb1dbbbe9f1a8 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Mon, 17 Sep 2018 08:56:18 -0500 Subject: fix a bug in interp1d() This commit fixes a bug in interp1d() which would cause the function to read past the end of the arrays if the interpolation point was equal to the last point in the xp array. --- src/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/misc.c b/src/misc.c index 823bc78..f0e37e3 100644 --- a/src/misc.c +++ b/src/misc.c @@ -269,8 +269,8 @@ double interp1d(double x, double *xp, double *yp, size_t n) * If x < xp[0] returns yp[0] and if x > xp[n-1] returns yp[n-1]. */ size_t i; - if (x < xp[0]) return yp[0]; - if (x > xp[n-1]) return yp[n-1]; + if (x <= xp[0]) return yp[0]; + if (x >= xp[n-1]) return yp[n-1]; i = (x-xp[0])/(xp[1]-xp[0]); -- cgit