rgsl/pow.rs
1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5pub trait Pow {
6 /// This routine computes the power x^n for integer n. The power is computed efficiently—for example, x^8 is computed as ((x^2)^2)^2, requiring only 3 multiplications.
7 /// A version of this function which also computes the numerical error in the result is available as gsl_sf_pow_int_e.
8 fn pow_int(&self, n: i32) -> Self;
9 /// This routine computes the power x^n for integer n. The power is computed efficiently—for example, x^8 is computed as ((x^2)^2)^2, requiring only 3 multiplications.
10 /// A version of this function which also computes the numerical error in the result is available as gsl_sf_pow_int_e.
11 fn pow_uint(&self, n: u32) -> Self;
12 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
13 fn pow_2(&self) -> Self;
14 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
15 fn pow_3(&self) -> Self;
16 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
17 fn pow_4(&self) -> Self;
18 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
19 fn pow_5(&self) -> Self;
20 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
21 fn pow_6(&self) -> Self;
22 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
23 fn pow_7(&self) -> Self;
24 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
25 fn pow_8(&self) -> Self;
26 /// This function can be used to compute small integer powers x^2, x^3, etc. efficiently.
27 fn pow_9(&self) -> Self;
28}
29
30impl Pow for f64 {
31 #[doc(alias = "gsl_pow_int")]
32 fn pow_int(&self, n: i32) -> f64 {
33 unsafe { ::sys::gsl_pow_int(*self, n) }
34 }
35
36 #[doc(alias = "gsl_pow_uint")]
37 fn pow_uint(&self, n: u32) -> f64 {
38 unsafe { ::sys::gsl_pow_uint(*self, n) }
39 }
40
41 #[doc(alias = "gsl_pow_2")]
42 fn pow_2(&self) -> f64 {
43 unsafe { ::sys::gsl_pow_2(*self) }
44 }
45
46 #[doc(alias = "gsl_pow_3")]
47 fn pow_3(&self) -> f64 {
48 unsafe { ::sys::gsl_pow_3(*self) }
49 }
50
51 #[doc(alias = "gsl_pow_4")]
52 fn pow_4(&self) -> f64 {
53 unsafe { ::sys::gsl_pow_4(*self) }
54 }
55
56 #[doc(alias = "gsl_pow_5")]
57 fn pow_5(&self) -> f64 {
58 unsafe { ::sys::gsl_pow_5(*self) }
59 }
60
61 #[doc(alias = "gsl_pow_6")]
62 fn pow_6(&self) -> f64 {
63 unsafe { ::sys::gsl_pow_6(*self) }
64 }
65
66 #[doc(alias = "gsl_pow_7")]
67 fn pow_7(&self) -> f64 {
68 unsafe { ::sys::gsl_pow_7(*self) }
69 }
70
71 #[doc(alias = "gsl_pow_8")]
72 fn pow_8(&self) -> f64 {
73 unsafe { ::sys::gsl_pow_8(*self) }
74 }
75
76 #[doc(alias = "gsl_pow_9")]
77 fn pow_9(&self) -> f64 {
78 unsafe { ::sys::gsl_pow_9(*self) }
79 }
80}