rgsl/
hypergeometric.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5//! Hypergeometric functions are described in Abramowitz & Stegun, Chapters 13 and 15.
6
7use crate::{types, Value};
8use std::mem::MaybeUninit;
9
10/// This routine computes the hypergeometric function 0F1(c,x).
11#[doc(alias = "gsl_sf_hyperg_0F1")]
12pub fn hyperg_0F1(c: f64, x: f64) -> f64 {
13    unsafe { sys::gsl_sf_hyperg_0F1(c, x) }
14}
15
16/// This routine computes the hypergeometric function 0F1(c,x).
17#[doc(alias = "gsl_sf_hyperg_0F1_e")]
18pub fn hyperg_0F1_e(c: f64, x: f64) -> Result<types::Result, Value> {
19    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
20    let ret = unsafe { ::sys::gsl_sf_hyperg_0F1_e(c, x, result.as_mut_ptr()) };
21
22    result_handler!(ret, unsafe { result.assume_init() }.into())
23}
24
25/// This routine computes the confluent hypergeometric function 1F1(m,n,x) = M(m,n,x) for integer parameters m, n.
26#[doc(alias = "gsl_sf_hyperg_1F1_int")]
27pub fn hyperg_1F1_int(m: i32, n: i32, x: f64) -> f64 {
28    unsafe { sys::gsl_sf_hyperg_1F1_int(m, n, x) }
29}
30
31/// This routine computes the confluent hypergeometric function 1F1(m,n,x) = M(m,n,x) for integer parameters m, n.
32#[doc(alias = "gsl_sf_hyperg_1F1_int_e")]
33pub fn hyperg_1F1_int_e(m: i32, n: i32, x: f64) -> Result<types::Result, Value> {
34    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
35    let ret = unsafe { ::sys::gsl_sf_hyperg_1F1_int_e(m, n, x, result.as_mut_ptr()) };
36
37    result_handler!(ret, unsafe { result.assume_init() }.into())
38}
39
40/// This routine computes the confluent hypergeometric function 1F1(a,b,x) = M(a,b,x) for general parameters a, b.
41#[doc(alias = "gsl_sf_hyperg_1F1")]
42pub fn hyperg_1F1(a: f64, b: f64, x: f64) -> f64 {
43    unsafe { sys::gsl_sf_hyperg_1F1(a, b, x) }
44}
45
46/// This routine computes the confluent hypergeometric function 1F1(a,b,x) = M(a,b,x) for general parameters a, b.
47#[doc(alias = "gsl_sf_hyperg_1F1_e")]
48pub fn hyperg_1F1_e(a: f64, b: f64, x: f64) -> Result<types::Result, Value> {
49    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
50    let ret = unsafe { ::sys::gsl_sf_hyperg_1F1_e(a, b, x, result.as_mut_ptr()) };
51
52    result_handler!(ret, unsafe { result.assume_init() }.into())
53}
54
55/// This routine computes the confluent hypergeometric function U(m,n,x) for integer parameters m, n.
56#[doc(alias = "gsl_sf_hyperg_U_int")]
57pub fn hyperg_U_int(m: i32, n: i32, x: f64) -> f64 {
58    unsafe { sys::gsl_sf_hyperg_U_int(m, n, x) }
59}
60
61/// This routine computes the confluent hypergeometric function U(m,n,x) for integer parameters m, n.
62#[doc(alias = "gsl_sf_hyperg_U_int_e")]
63pub fn hyperg_U_int_e(m: i32, n: i32, x: f64) -> Result<types::Result, Value> {
64    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
65    let ret = unsafe { ::sys::gsl_sf_hyperg_U_int_e(m, n, x, result.as_mut_ptr()) };
66
67    result_handler!(ret, unsafe { result.assume_init() }.into())
68}
69
70/// This routine computes the confluent hypergeometric function U(m,n,x) for integer parameters m, n using the
71/// [`ResultE10]`(types/result/struct.ResultE10.html) type to return a result with extended range.
72#[doc(alias = "gsl_sf_hyperg_U_int_e10_e")]
73pub fn hyperg_U_int_e10_e(m: i32, n: i32, x: f64) -> Result<types::ResultE10, Value> {
74    let mut result = MaybeUninit::<sys::gsl_sf_result_e10>::uninit();
75    let ret = unsafe { ::sys::gsl_sf_hyperg_U_int_e10_e(m, n, x, result.as_mut_ptr()) };
76
77    result_handler!(ret, unsafe { result.assume_init() }.into())
78}
79
80/// This routine computes the confluent hypergeometric function U(a,b,x).
81#[doc(alias = "gsl_sf_hyperg_U")]
82pub fn hyperg_U(a: f64, b: f64, x: f64) -> f64 {
83    unsafe { sys::gsl_sf_hyperg_U(a, b, x) }
84}
85
86/// This routine computes the confluent hypergeometric function U(a,b,x).
87#[doc(alias = "gsl_sf_hyperg_U_e")]
88pub fn hyperg_U_e(a: f64, b: f64, x: f64) -> Result<types::Result, Value> {
89    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
90    let ret = unsafe { ::sys::gsl_sf_hyperg_U_e(a, b, x, result.as_mut_ptr()) };
91
92    result_handler!(ret, unsafe { result.assume_init() }.into())
93}
94
95/// This routine computes the confluent hypergeometric function U(a,b,x) using the
96/// [`ResultE10]`(types/result/struct.ResultE10.html) type to return a result with extended range.
97#[doc(alias = "gsl_sf_hyperg_U_e10_e")]
98pub fn hyperg_U_e10_e(a: f64, b: f64, x: f64) -> Result<types::ResultE10, Value> {
99    let mut result = MaybeUninit::<sys::gsl_sf_result_e10>::uninit();
100    let ret = unsafe { ::sys::gsl_sf_hyperg_U_e10_e(a, b, x, result.as_mut_ptr()) };
101
102    result_handler!(ret, unsafe { result.assume_init() }.into())
103}
104
105/// This routine computes the Gauss hypergeometric function 2F1(a,b,c,x) = F(a,b,c,x) for |x| < 1.
106///
107/// If the arguments (a,b,c,x) are too close to a singularity then the function can return the error code
108/// [`MaxIter`](enums/type.Value.html) when the series approximation converges too slowly.
109/// This occurs in the region of x=1, c - a - b = m for integer m.
110#[doc(alias = "gsl_sf_hyperg_2F1")]
111pub fn hyperg_2F1(a: f64, b: f64, c: f64, x: f64) -> f64 {
112    unsafe { sys::gsl_sf_hyperg_2F1(a, b, c, x) }
113}
114
115/// This routine computes the Gauss hypergeometric function 2F1(a,b,c,x) = F(a,b,c,x) for |x| < 1.
116///
117/// If the arguments (a,b,c,x) are too close to a singularity then the function can return the error code
118/// [`MaxIter`](enums/type.Value.html) when the series approximation converges too slowly.
119/// This occurs in the region of x=1, c - a - b = m for integer m.
120#[doc(alias = "gsl_sf_hyperg_2F1_e")]
121pub fn hyperg_2F1_e(a: f64, b: f64, c: f64, x: f64) -> Result<types::Result, Value> {
122    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
123    let ret = unsafe { ::sys::gsl_sf_hyperg_2F1_e(a, b, c, x, result.as_mut_ptr()) };
124
125    result_handler!(ret, unsafe { result.assume_init() }.into())
126}
127
128/// This routine computes the Gauss hypergeometric function 2F1(a_R + i a_I, a_R - i a_I, c, x) with complex parameters for |x| < 1.
129#[doc(alias = "gsl_sf_hyperg_2F1_conj")]
130pub fn hyperg_2F1_conj(aR: f64, aI: f64, c: f64, x: f64) -> f64 {
131    unsafe { sys::gsl_sf_hyperg_2F1_conj(aR, aI, c, x) }
132}
133
134/// This routine computes the Gauss hypergeometric function 2F1(a_R + i a_I, a_R - i a_I, c, x) with complex parameters for |x| < 1.
135#[doc(alias = "gsl_sf_hyperg_2F1_conj_e")]
136pub fn hyperg_2F1_conj_e(aR: f64, aI: f64, c: f64, x: f64) -> Result<types::Result, Value> {
137    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
138    let ret = unsafe { ::sys::gsl_sf_hyperg_2F1_conj_e(aR, aI, c, x, result.as_mut_ptr()) };
139
140    result_handler!(ret, unsafe { result.assume_init() }.into())
141}
142
143/// This routine computes the renormalized Gauss hypergeometric function 2F1(a,b,c,x) / \Gamma(c) for |x| < 1.
144#[doc(alias = "gsl_sf_hyperg_2F1_renorm")]
145pub fn hyperg_2F1_renorm(a: f64, b: f64, c: f64, x: f64) -> f64 {
146    unsafe { sys::gsl_sf_hyperg_2F1_renorm(a, b, c, x) }
147}
148
149/// This routine computes the renormalized Gauss hypergeometric function 2F1(a,b,c,x) / \Gamma(c) for |x| < 1.
150#[doc(alias = "gsl_sf_hyperg_2F1_renorm_e")]
151pub fn hyperg_2F1_renorm_e(a: f64, b: f64, c: f64, x: f64) -> Result<types::Result, Value> {
152    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
153    let ret = unsafe { ::sys::gsl_sf_hyperg_2F1_renorm_e(a, b, c, x, result.as_mut_ptr()) };
154
155    result_handler!(ret, unsafe { result.assume_init() }.into())
156}
157
158/// This routine computes the renormalized Gauss hypergeometric function 2F1(a_R + i a_I, a_R - i a_I, c, x) / \Gamma(c) for |x| < 1.
159#[doc(alias = "gsl_sf_hyperg_2F1_conj_renorm")]
160pub fn hyperg_2F1_conj_renorm(aR: f64, aI: f64, c: f64, x: f64) -> f64 {
161    unsafe { sys::gsl_sf_hyperg_2F1_conj_renorm(aR, aI, c, x) }
162}
163
164/// This routine computes the renormalized Gauss hypergeometric function 2F1(a_R + i a_I, a_R - i a_I, c, x) / \Gamma(c) for |x| < 1.
165#[doc(alias = "gsl_sf_hyperg_2F1_conj_renorm_e")]
166pub fn hyperg_2F1_conj_renorm_e(aR: f64, aI: f64, c: f64, x: f64) -> Result<types::Result, Value> {
167    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
168    let ret = unsafe { ::sys::gsl_sf_hyperg_2F1_conj_renorm_e(aR, aI, c, x, result.as_mut_ptr()) };
169
170    result_handler!(ret, unsafe { result.assume_init() }.into())
171}
172
173/// This routine computes the hypergeometric function 2F0(a,b,x). The series representation is a divergent hypergeometric series.
174/// However, for x < 0 we have 2F0(a,b,x) = (-1/x)^a U(a,1+a-b,-1/x)
175#[doc(alias = "gsl_sf_hyperg_2F0")]
176pub fn hyperg_2F0(a: f64, b: f64, x: f64) -> f64 {
177    unsafe { sys::gsl_sf_hyperg_2F0(a, b, x) }
178}
179
180/// This routine computes the hypergeometric function 2F0(a,b,x). The series representation is a divergent hypergeometric series.
181/// However, for x < 0 we have 2F0(a,b,x) = (-1/x)^a U(a,1+a-b,-1/x)
182#[doc(alias = "gsl_sf_hyperg_2F0_e")]
183pub fn hyperg_2F0_e(a: f64, b: f64, x: f64) -> Result<types::Result, Value> {
184    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
185    let ret = unsafe { ::sys::gsl_sf_hyperg_2F0_e(a, b, x, result.as_mut_ptr()) };
186
187    result_handler!(ret, unsafe { result.assume_init() }.into())
188}