add numerical recipes library

This commit is contained in:
2025-09-12 18:55:25 +09:00
parent d4dff245bd
commit 2c75620ec9
1344 changed files with 63869 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
void hunt(float xx[], unsigned long n, float x, unsigned long *jlo)
{
unsigned long jm,jhi,inc;
int ascnd;
ascnd=(xx[n] >= xx[1]);
if (*jlo <= 0 || *jlo > n) {
*jlo=0;
jhi=n+1;
} else {
inc=1;
if (x >= xx[*jlo] == ascnd) {
if (*jlo == n) return;
jhi=(*jlo)+1;
while (x >= xx[jhi] == ascnd) {
*jlo=jhi;
inc += inc;
jhi=(*jlo)+inc;
if (jhi > n) {
jhi=n+1;
break;
}
}
} else {
if (*jlo == 1) {
*jlo=0;
return;
}
jhi=(*jlo)--;
while (x < xx[*jlo] == ascnd) {
jhi=(*jlo);
inc <<= 1;
if (inc >= jhi) {
*jlo=0;
break;
}
else *jlo=jhi-inc;
}
}
}
while (jhi-(*jlo) != 1) {
jm=(jhi+(*jlo)) >> 1;
if (x >= xx[jm] == ascnd)
*jlo=jm;
else
jhi=jm;
}
if (x == xx[n]) *jlo=n-1;
if (x == xx[1]) *jlo=1;
}