gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 956a7f3: Proper sanity checks before mode symm


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 956a7f3: Proper sanity checks before mode symmetricity calculation
Date: Sun, 29 Jul 2018 17:49:24 -0400 (EDT)

branch: master
commit 956a7f3e72582b0f5dc2cda7d220763620c73452
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Proper sanity checks before mode symmetricity calculation
    
    When measuring the symmetricity, we weren't checking if the mode is
    actually larger than the `a' (0.05 quantile) point (which is a hidden
    assumption). So a check has been added.
    
    Also, since the `MODE_SYM' function works on any type, we were doing
    integer division the final step of this function. To be safe, we now cast
    the two subtractions to `double' before division.
    
    This fixes bug #54406.
---
 NEWS             | 1 +
 lib/statistics.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 4705876..8f4f3c9 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,7 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   bug #54312: Crash when CFITSIO doesn't have fits_is_reentrant function.
   bug #54346: Non '-I' or non '-L' strings in CPPFLAGS or LDFLAGS cause crash.
   bug #54358: Arithmetic's where, not ignoring blank values in condition.
+  bug #54406: Insufficient sanity checks in mode symmetricity calculation.
 
 
 
diff --git a/lib/statistics.c b/lib/statistics.c
index 7d6e2f4..ce77950 100644
--- a/lib/statistics.c
+++ b/lib/statistics.c
@@ -846,6 +846,7 @@ mode_golden_section(struct statistics_mode_params *p)
     /* Set the values at the mirror and at `a' (see above). */          \
     mf=a[m];                                                            \
     af=a[ gal_statistics_quantile_index(2*m+1, MODE_SYM_LOW_Q) ];       \
+    if(mf<=af) return 0;                                                \
                                                                         \
     /* This loop is very similar to that of */                          \
     /* `mode_mirror_max_index_diff'. It will find the index where the */\
@@ -883,7 +884,7 @@ mode_golden_section(struct statistics_mode_params *p)
     /*printf("%zu: %f,%f,%f\n", m, (double)af, (double)mf, (double)bf);*/ \
                                                                         \
     /* For a bad result, return 0 (which will not output any mode). */  \
-    return bf==af ? 0 : (bf-mf)/(mf-af);                                \
+    return bf==af ? 0 : (double)(bf-mf)/(double)(mf-af);                \
   }
 static double
 mode_symmetricity(struct statistics_mode_params *p, size_t m, void *b_val)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]