From d9b52eb3e121ee52a72fc27ff69f843954c4af85 Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Tue, 21 Feb 2023 16:04:39 +0000 Subject: [PATCH] Fix a bug reported by Thomas Hoffmann in ngspice-users discussion, 2023-02-18. Incorrect tests were used to detect a crossing in the first two data samples. --- src/frontend/com_measure2.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/frontend/com_measure2.c b/src/frontend/com_measure2.c index 9db0c14da..5b947eacf 100644 --- a/src/frontend/com_measure2.c +++ b/src/frontend/com_measure2.c @@ -491,14 +491,13 @@ com_measure_when( crossCnt = 0; if (value < value2) { section = S_BELOW_VAL; - if ((prevValue <= value2) && (value >= value2)) { + if (prevValue >= prevValue2) { fallCnt = 1; crossCnt = 1; } - } else { section = S_ABOVE_VAL; - if ((prevValue <= value2) && (value >= value2)) { + if (prevValue < prevValue2) { riseCnt = 1; crossCnt = 1; } @@ -509,14 +508,13 @@ com_measure_when( crossCnt = 0; if (value < meas->m_val) { section = S_BELOW_VAL; - if ((prevValue <= meas->m_val) && (value >= meas->m_val)) { + if (prevValue >= meas->m_val) { fallCnt = 1; crossCnt = 1; } - } else { section = S_ABOVE_VAL; - if ((prevValue <= meas->m_val) && (value >= meas->m_val)) { + if (prevValue < meas->m_val) { riseCnt = 1; crossCnt = 1; }