rgsl/elementary.rs
1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5pub trait Elementary {
6 /// This function computes the value of __log(1+x)__ in a way that is accurate for small x. It provides an alternative to the BSD math function log1p(x).
7 fn log1p(&self) -> Self;
8 /// This function computes the value of __exp(x)-1__ in a way that is accurate for small x. It provides an alternative to the BSD math function expm1(x).
9 fn expm1(&self) -> Self;
10 /// This function computes the value of __sqrt{x^2 + y^2}__ in a way that avoids overflow. It provides an alternative to the BSD math function hypot(x,y).
11 fn hypot(&self, y: f64) -> Self;
12 /// This function computes the value of __sqrt{x^2 + y^2 + z^2}__ in a way that avoids overflow.
13 fn hypot3(&self, y: f64, z: f64) -> Self;
14 /// This function computes the value of __arccosh(x)__. It provides an alternative to the standard math function acosh(x).
15 fn acosh(&self) -> Self;
16 /// This function computes the value of __arcsinh(x)__. It provides an alternative to the standard math function asinh(x).
17 fn asinh(&self) -> Self;
18 /// This function computes the value of __arctanh(x)__. It provides an alternative to the standard math function atanh(x).
19 fn atanh(&self) -> Self;
20 /// This function computes the value of __x * 2^e__. It provides an alternative to the standard math function ldexp(x,e).
21 fn ldexp(&self, e: i32) -> Self;
22 /// This function splits the number x into its normalized fraction f and exponent e, such that x = f * 2^e and 0.5 <= f < 1. The function returns f and stores the exponent in e.
23 /// If x is zero, both f and e are set to zero. This function provides an alternative to the standard math function frexp(x, e).
24 fn frexp(&self, e: &mut i32) -> Self;
25}
26
27impl Elementary for f64 {
28 #[doc(alias = "gsl_log1p")]
29 fn log1p(&self) -> f64 {
30 unsafe { sys::gsl_log1p(*self) }
31 }
32
33 #[doc(alias = "gsl_expm1")]
34 fn expm1(&self) -> f64 {
35 unsafe { sys::gsl_expm1(*self) }
36 }
37
38 #[doc(alias = "gsl_hypot")]
39 fn hypot(&self, y: f64) -> f64 {
40 unsafe { sys::gsl_hypot(*self, y) }
41 }
42
43 #[doc(alias = "gsl_hypot3")]
44 fn hypot3(&self, y: f64, z: f64) -> f64 {
45 unsafe { sys::gsl_hypot3(*self, y, z) }
46 }
47
48 #[doc(alias = "gsl_acosh")]
49 fn acosh(&self) -> f64 {
50 unsafe { sys::gsl_acosh(*self) }
51 }
52
53 #[doc(alias = "gsl_asinh")]
54 fn asinh(&self) -> f64 {
55 unsafe { sys::gsl_asinh(*self) }
56 }
57
58 #[doc(alias = "gsl_atanh")]
59 fn atanh(&self) -> f64 {
60 unsafe { sys::gsl_atanh(*self) }
61 }
62
63 #[doc(alias = "gsl_ldexp")]
64 fn ldexp(&self, e: i32) -> f64 {
65 unsafe { sys::gsl_ldexp(*self, e) }
66 }
67
68 #[doc(alias = "gsl_frexp")]
69 fn frexp(&self, e: &mut i32) -> f64 {
70 unsafe { sys::gsl_frexp(*self, e) }
71 }
72}