Changeset 40176
- Timestamp:
- Oct 19, 2017, 2:04:55 PM (9 years ago)
- Location:
- branches/eam_branches/ohana.20170822/src/libohana
- Files:
-
- 2 edited
-
include/ohana.h (modified) (1 diff)
-
src/bisection.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20170822/src/libohana/include/ohana.h
r39457 r40176 485 485 /* in bisection.c */ 486 486 int ohana_bisection_double (double *values, int Nvalues, double threshold); 487 int ohana_bisection_int (int *values, int Nvalues, int threshold); 487 488 488 489 unsigned int sprintf_float (char *output, float value); -
branches/eam_branches/ohana.20170822/src/libohana/src/bisection.c
r38459 r40176 32 32 return (N); 33 33 } 34 35 // return the index of the last value < threshold 36 int ohana_bisection_int (int *values, int Nvalues, int threshold) { 37 38 int Nlo = 0; 39 int Nhi = Nvalues - 1; 40 41 if (Nvalues < 1) return (-1); 42 if (values[Nlo] > threshold) return (-1); 43 44 if (Nvalues < 2) return (0); 45 if (values[Nhi] < threshold) return (Nhi); 46 47 int N; 48 while (Nhi - Nlo > 4) { 49 N = 0.5*(Nlo + Nhi); 50 if (values[N] < threshold) { 51 Nlo = MAX(N, 0); 52 } else { 53 Nhi = MIN(N + 1, Nvalues - 1); 54 } 55 } 56 // values[Nlo] < threshold 57 // values[Nhi] >= threshold 58 59 for (N = Nlo; N < Nhi; N++) { 60 if (values[N] >= threshold) { 61 return (N-1); 62 } 63 } 64 return (N); 65 }
Note:
See TracChangeset
for help on using the changeset viewer.
