From e78d51c7941a26eef71d69260b49eeb1db954428 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 14 Apr 2004 02:26:37 +0000 Subject: [PATCH] Adjust calculation of kurtosis to avoid subtracting huge numbers from huge numbers, on Michael Kiefte's advice. --- src/ChangeLog | 6 ++++++ src/moments.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1fdf0d54..6db983d6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +Tue Apr 13 19:24:15 2004 Ben Pfaff + + * moments.c (calc_moments): Adjust calculation of kurtosis to + avoid subtracting huge numbers from huge numbers, on Michael + Kiefte's advice. + Sun Apr 11 14:22:12 2004 Ben Pfaff Rework moments routines for improved numerical stability based on diff --git a/src/moments.c b/src/moments.c index c993f7ae..c4f3fe18 100644 --- a/src/moments.c +++ b/src/moments.c @@ -62,9 +62,9 @@ calc_moments (enum moment max_moment, } if (max_moment >= MOMENT_KURTOSIS && kurtosis != NULL && w > 3.) { - double g2 = ((w * (w + 1.) * d4 - - 3. * pow2 (d2) * (w - 1.)) - / ((w - 1.) * (w - 2.) * (w - 3.) * pow2 (s2))); + double den = (w - 2.) * (w - 3.) * pow2 (s2); + double g2 = (w * (w + 1) * d4 / (w - 1.) / den + - 3. * pow2 (d2) / den); if (finite (g2)) *kurtosis = g2; } -- 2.30.2