rgsl/
exponential.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5use crate::{types, Value};
6use std::mem::MaybeUninit;
7
8/// This routine provides an exponential function \exp(x) using GSL semantics and error checking.
9#[doc(alias = "gsl_sf_exp")]
10pub fn exp(x: f64) -> f64 {
11    unsafe { sys::gsl_sf_exp(x) }
12}
13
14/// This routine provides an exponential function \exp(x) using GSL semantics and error checking.
15#[doc(alias = "gsl_sf_exp_e")]
16pub fn exp_e(x: f64) -> Result<types::Result, Value> {
17    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
18    let ret = unsafe { sys::gsl_sf_exp_e(x, result.as_mut_ptr()) };
19
20    result_handler!(ret, unsafe { result.assume_init() }.into())
21}
22
23/// This function computes the exponential \exp(x) using the gsl_sf_result_e10 type to return a
24/// result with extended range.
25///
26/// This function may be useful if the value of \exp(x) would overflow the numeric range of double.
27#[doc(alias = "gsl_sf_exp_e10_e")]
28pub fn exp_e10_e(x: f64) -> Result<types::ResultE10, Value> {
29    let mut result = MaybeUninit::<sys::gsl_sf_result_e10>::uninit();
30    let ret = unsafe { sys::gsl_sf_exp_e10_e(x, result.as_mut_ptr()) };
31
32    result_handler!(ret, unsafe { result.assume_init() }.into())
33}
34
35/// This routine exponentiates x and multiply by the factor y to return the product y \exp(x).
36#[doc(alias = "gsl_sf_exp_mult")]
37pub fn exp_mult(x: f64, y: f64) -> f64 {
38    unsafe { sys::gsl_sf_exp_mult(x, y) }
39}
40
41/// This routine exponentiates x and multiply by the factor y to return the product y \exp(x).
42#[doc(alias = "gsl_sf_exp_mult_e")]
43pub fn exp_mult_e(x: f64, y: f64) -> Result<types::Result, Value> {
44    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
45    let ret = unsafe { sys::gsl_sf_exp_mult_e(x, y, result.as_mut_ptr()) };
46
47    result_handler!(ret, unsafe { result.assume_init() }.into())
48}
49
50/// This function computes the exponential \exp(x) using the gsl_sf_result_e10 type to return a
51/// result with extended range.
52///
53/// This function may be useful if the value of \exp(x) would overflow the numeric range of double.
54#[doc(alias = "gsl_sf_exp_mult_e10_e")]
55pub fn exp_mult_e10_e(x: f64, y: f64) -> Result<types::ResultE10, Value> {
56    let mut result = MaybeUninit::<sys::gsl_sf_result_e10>::uninit();
57    let ret = unsafe { sys::gsl_sf_exp_mult_e10_e(x, y, result.as_mut_ptr()) };
58
59    result_handler!(ret, unsafe { result.assume_init() }.into())
60}
61
62/// This routine computes the quantity \exp(x)-1 using an algorithm that is accurate for small x.
63#[doc(alias = "gsl_sf_expm1")]
64pub fn expm1(x: f64) -> f64 {
65    unsafe { sys::gsl_sf_expm1(x) }
66}
67
68/// This routine computes the quantity \exp(x)-1 using an algorithm that is accurate for small x.
69#[doc(alias = "gsl_sf_expm1_e")]
70pub fn expm1_e(x: f64) -> Result<types::Result, Value> {
71    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
72    let ret = unsafe { sys::gsl_sf_expm1_e(x, result.as_mut_ptr()) };
73
74    result_handler!(ret, unsafe { result.assume_init() }.into())
75}
76
77/// This routine computes the quantity (\exp(x)-1)/x using an algorithm that is accurate for small
78/// x. For small x the algorithm is based on the expansion
79/// `(\exp(x)-1)/x = 1 + x/2 + x^2/(2*3) + x^3/(2*3*4) + \dots`.
80#[doc(alias = "gsl_sf_exprel")]
81pub fn exprel(x: f64) -> f64 {
82    unsafe { sys::gsl_sf_exprel(x) }
83}
84
85/// This routine computes the quantity (\exp(x)-1)/x using an algorithm that is accurate for small
86/// x. For small x the algorithm is based on the expansion
87/// `(\exp(x)-1)/x = 1 + x/2 + x^2/(2*3) + x^3/(2*3*4) + \dots`.
88#[doc(alias = "gsl_sf_exprel_e")]
89pub fn exprel_e(x: f64) -> Result<types::Result, Value> {
90    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
91    let ret = unsafe { sys::gsl_sf_exprel_e(x, result.as_mut_ptr()) };
92
93    result_handler!(ret, unsafe { result.assume_init() }.into())
94}
95
96/// This routine computes the quantity 2(\exp(x)-1-x)/x^2 using an algorithm that is accurate for
97/// small x. For small x the algorithm is based on the expansion
98/// `2(\exp(x)-1-x)/x^2 = 1 + x/3 + x^2/(3*4) + x^3/(3*4*5) + \dots`.
99#[doc(alias = "gsl_sf_exprel_2")]
100pub fn exprel_2(x: f64) -> f64 {
101    unsafe { sys::gsl_sf_exprel_2(x) }
102}
103
104/// This routine computes the quantity 2(\exp(x)-1-x)/x^2 using an algorithm that is accurate for
105/// small x. For small x the algorithm is based on the expansion
106/// `2(\exp(x)-1-x)/x^2 = 1 + x/3 + x^2/(3*4) + x^3/(3*4*5) + \dots`.
107#[doc(alias = "gsl_sf_exprel_2_e")]
108pub fn exprel_2_e(x: f64) -> Result<types::Result, Value> {
109    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
110    let ret = unsafe { sys::gsl_sf_exprel_2_e(x, result.as_mut_ptr()) };
111
112    result_handler!(ret, unsafe { result.assume_init() }.into())
113}
114
115/// This routine computes the N-relative exponential, which is the n-th generalization of the
116/// functions gsl_sf_exprel and gsl_sf_exprel_2.
117/// The N-relative exponential is given by:
118///
119/// ```latex
120/// exprel_N(x) = N!/x^N (\exp(x) - \sum_{k=0}^{N-1} x^k/k!)
121///
122///             = 1 + x/(N+1) + x^2/((N+1)(N+2)) + ...
123///
124///             = 1F1 (1,1+N,x)
125/// ```
126#[doc(alias = "gsl_sf_exprel_n")]
127pub fn exprel_n(n: i32, x: f64) -> f64 {
128    unsafe { sys::gsl_sf_exprel_n(n, x) }
129}
130
131/// This routine computes the N-relative exponential, which is the n-th generalization of the
132/// functions gsl_sf_exprel and gsl_sf_exprel_2.
133/// The N-relative exponential is given by:
134///
135/// ```latex
136/// exprel_N(x) = N!/x^N (\exp(x) - \sum_{k=0}^{N-1} x^k/k!)
137///
138///             = 1 + x/(N+1) + x^2/((N+1)(N+2)) + ...
139///
140///             = 1F1 (1,1+N,x)
141/// ```
142#[doc(alias = "gsl_sf_exprel_n_e")]
143pub fn exprel_n_e(n: i32, x: f64) -> Result<types::Result, Value> {
144    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
145    let ret = unsafe { sys::gsl_sf_exprel_n_e(n, x, result.as_mut_ptr()) };
146
147    result_handler!(ret, unsafe { result.assume_init() }.into())
148}
149
150/// This function exponentiates x with an associated absolute error dx.
151#[doc(alias = "gsl_sf_exp_err_e")]
152pub fn exp_err_e(x: f64, dx: f64) -> Result<types::Result, Value> {
153    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
154    let ret = unsafe { sys::gsl_sf_exp_err_e(x, dx, result.as_mut_ptr()) };
155
156    result_handler!(ret, unsafe { result.assume_init() }.into())
157}
158
159/// This function exponentiates a quantity x with an associated absolute error dx using the
160/// [`ResultE10`][crate::ResultE10] type to return a result with extended range.
161#[doc(alias = "gsl_sf_exp_err_e10_e")]
162pub fn exp_err_e10_e(x: f64, dx: f64) -> Result<types::ResultE10, Value> {
163    let mut result = MaybeUninit::<sys::gsl_sf_result_e10>::uninit();
164    let ret = unsafe { sys::gsl_sf_exp_err_e10_e(x, dx, result.as_mut_ptr()) };
165
166    result_handler!(ret, unsafe { result.assume_init() }.into())
167}
168
169/// This routine computes the product y \exp(x) for the quantities x, y with associated absolute
170/// errors dx, dy.
171#[doc(alias = "gsl_sf_exp_mult_err_e")]
172pub fn exp_mult_err_e(x: f64, dx: f64, y: f64, dy: f64) -> Result<types::Result, Value> {
173    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
174    let ret = unsafe { sys::gsl_sf_exp_mult_err_e(x, dx, y, dy, result.as_mut_ptr()) };
175
176    result_handler!(ret, unsafe { result.assume_init() }.into())
177}
178
179/// This routine computes the product y \exp(x) for the quantities x, y with associated absolute
180/// errors dx, dy using the gsl_sf_result_e10 type to return a result with extended range.
181#[doc(alias = "gsl_sf_exp_mult_err_e10_e")]
182pub fn exp_mult_err_e10_e(x: f64, dx: f64, y: f64, dy: f64) -> Result<types::ResultE10, Value> {
183    let mut result = MaybeUninit::<sys::gsl_sf_result_e10>::uninit();
184    let ret = unsafe { sys::gsl_sf_exp_mult_err_e10_e(x, dx, y, dy, result.as_mut_ptr()) };
185
186    result_handler!(ret, unsafe { result.assume_init() }.into())
187}