forked from elizakempton/Exo_Transmit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
53 lines (41 loc) · 1.3 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <rpc/types.h>
#include "include.h"
#include "nrutil.h"
/* ------------------------------------ Locate.c --------------------
Version: rh1.0
Author: Han Uitenbroek ([email protected])
Last modified: Tue Feb 16 14:40:59 1999 --
-------------------------- ----------RH-- */
/* --- Find index of value in array (cf., Num. Recipes, p 90).
Note: The Num. Recipes routine does not give the correct index
for values that are exactly equal to an array value!
-- -------------- */
/* ------- begin -------------------------- Locate.c ---------------- */
void Locate(int n, double *array, double value, int *ilow)
{
bool_t ascend;
int ihigh, index;
ascend = (array[n-1] > array[0]) ? TRUE : FALSE;
*ilow = 0; ihigh = n;
if (ascend) {
while (ihigh - *ilow > 1) {
index = (ihigh + *ilow) >> 1;
if (value >= array[index])
*ilow = index;
else
ihigh = index;
}
} else {
while (ihigh - *ilow > 1) {
index = (ihigh + *ilow) >> 1;
if (value <= array[index])
*ilow = index;
else
ihigh = index;
}
}
}
/* ------- end ---------------------------- Locate.c ---------------- */