comparison src/scalar.c @ 192:bb60691d9570

Make xtract_lowest_value() return XTRACT_NO_RESULT if all values in the input data are below or equal to threshold value. Fixes #46 If XTRACT_NO_RESULT is returned, *result will be set to DBL_MAX
author Jamie Bullock <jamie@jamiebullock.com>
date Tue, 11 Feb 2014 16:39:41 +0000
parents 95af6c8dc7f2
children e63fa5ad1902
comparison
equal deleted inserted replaced
191:e1d65ec5fde3 192:bb60691d9570
25 25
26 #include <stdlib.h> 26 #include <stdlib.h>
27 #include <string.h> 27 #include <string.h>
28 #include <stdio.h> 28 #include <stdio.h>
29 #include <math.h> 29 #include <math.h>
30 #include <limits.h>
30 31
31 #include "dywapitchtrack/dywapitchtrack.h" 32 #include "dywapitchtrack/dywapitchtrack.h"
32 33
33 #include "../xtract/libxtract.h" 34 #include "../xtract/libxtract.h"
34 #include "../xtract/xtract_helper.h" 35 #include "../xtract/xtract_helper.h"
744 745
745 int xtract_lowest_value(const double *data, const int N, const void *argv, double *result) 746 int xtract_lowest_value(const double *data, const int N, const void *argv, double *result)
746 { 747 {
747 748
748 int n = N; 749 int n = N;
749 double temp; 750
750 751 *result = DBL_MAX;
751 *result = data[--n]; 752
752 753 while(n--)
753 while(n--) 754 {
754 { 755 if(data[n] > *(double *)argv)
755 if((temp = data[n]) > *(double *)argv)
756 *result = XTRACT_MIN(*result, data[n]); 756 *result = XTRACT_MIN(*result, data[n]);
757 } 757 }
758 758
759 if (*result == DBL_MAX)
760 return XTRACT_NO_RESULT;
761
759 return XTRACT_SUCCESS; 762 return XTRACT_SUCCESS;
760 } 763 }
761 764
762 int xtract_highest_value(const double *data, const int N, const void *argv, double *result) 765 int xtract_highest_value(const double *data, const int N, const void *argv, double *result)
763 { 766 {