gsl_cdf__gamma.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* cdf/cdf_gamma.c
  2. *
  3. * Copyright (C) 2003 Jason Stover.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. * Author: J. Stover
  21. */
  22. #include "gsl__config.h"
  23. #include <math.h>
  24. #include "gsl_cdf.h"
  25. #include "gsl_math.h"
  26. #include "gsl_sf_gamma.h"
  27. double
  28. gsl_cdf_gamma_P (const double x, const double a, const double b)
  29. {
  30. double P;
  31. double y = x / b;
  32. if (x <= 0.0)
  33. {
  34. return 0.0;
  35. }
  36. if (y > a)
  37. {
  38. P = 1 - gsl_sf_gamma_inc_Q (a, y);
  39. }
  40. else
  41. {
  42. P = gsl_sf_gamma_inc_P (a, y);
  43. }
  44. return P;
  45. }
  46. double
  47. gsl_cdf_gamma_Q (const double x, const double a, const double b)
  48. {
  49. double Q;
  50. double y = x / b;
  51. if (x <= 0.0)
  52. {
  53. return 1.0;
  54. }
  55. if (y < a)
  56. {
  57. Q = 1 - gsl_sf_gamma_inc_P (a, y);
  58. }
  59. else
  60. {
  61. Q = gsl_sf_gamma_inc_Q (a, y);
  62. }
  63. return Q;
  64. }