From b1597d6f485650eb4da45b25d5e7e3a954f68d5e Mon Sep 17 00:00:00 2001 From: Mohan Yelugoti Date: Fri, 11 Oct 2024 18:44:05 -0400 Subject: [PATCH] i.smap: fix possible pole error with log in extract function Using logarithm function call with zero argument will lead to a pole error, which occurs if the mathematical function has an exact infinite result. Check if the argument value is zero before passing that to the log function to avoid such errors. I also added check for negative numbers just to make sure the argument is in the right domain for the log function as well. Signed-off-by: Mohan Yelugoti --- imagery/i.smap/model.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imagery/i.smap/model.c b/imagery/i.smap/model.c index dd567cfe5bb..a92c396026e 100644 --- a/imagery/i.smap/model.c +++ b/imagery/i.smap/model.c @@ -155,7 +155,8 @@ void extract(DCELL ***img, /* multispectral image, img[band][i][j] */ for (k = 0; k < C->nsubclasses; k++) subsum += exp(subll[k] - maxlike) * C->SubSig[k].pi; - ll[i][j][m] = log(subsum) + maxlike; + if (subsum > 0) + ll[i][j][m] = log(subsum) + maxlike; } } }