kmath.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef AC_KMATH_H
  2. #define AC_KMATH_H
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /**********************************
  8. * Pseudo-random number generator *
  9. **********************************/
  10. typedef uint64_t krint64_t;
  11. struct _krand_t;
  12. typedef struct _krand_t krand_t;
  13. #define kr_drand(_kr) ((kr_rand(_kr) >> 11) * (1.0/9007199254740992.0))
  14. #define kr_sample(_kr, _k, _cnt) ((*(_cnt))++ < (_k)? *(_cnt) - 1 : kr_rand(_kr) % *(_cnt))
  15. krand_t *kr_srand(krint64_t seed);
  16. krint64_t kr_rand(krand_t *kr);
  17. /**************************
  18. * Non-linear programming *
  19. **************************/
  20. #define KMIN_RADIUS 0.5
  21. #define KMIN_EPS 1e-7
  22. #define KMIN_MAXCALL 50000
  23. typedef double (*kmin_f)(int, double*, void*);
  24. typedef double (*kmin1_f)(double, void*);
  25. double kmin_hj(kmin_f func, int n, double *x, void *data, double r, double eps, int max_calls); // Hooke-Jeeves'
  26. double kmin_brent(kmin1_f func, double a, double b, void *data, double tol, double *xmin); // Brent's 1-dimenssion
  27. /*********************
  28. * Special functions *
  29. *********************/
  30. double kf_lgamma(double z); // log gamma function
  31. double kf_erfc(double x); // complementary error function
  32. double kf_gammap(double s, double z); // regularized lower incomplete gamma function
  33. double kf_gammaq(double s, double z); // regularized upper incomplete gamma function
  34. double kf_betai(double a, double b, double x); // regularized incomplete beta function
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif