rgsl/types/
result.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5use std::default::Default;
6
7/// The error handling form of the special functions always calculate an error estimate along with the value of the result.
8/// Therefore, structures are provided for amalgamating a value and error estimate.
9#[derive(Clone, Copy, Debug)]
10pub struct Result {
11    /// Contains the value.
12    pub val: f64,
13    /// Contains an estimate of the absolute error in the value.
14    pub err: f64,
15}
16
17impl Default for Result {
18    fn default() -> Result {
19        Result::new()
20    }
21}
22
23impl Result {
24    pub fn new() -> Result {
25        Result {
26            val: 0f64,
27            err: 0f64,
28        }
29    }
30}
31
32impl From<::sys::gsl_sf_result> for Result {
33    fn from(v: ::sys::gsl_sf_result) -> Self {
34        Self {
35            val: v.val,
36            err: v.err,
37        }
38    }
39}
40
41/// In some cases, an overflow or underflow can be detected and handled by a function.
42/// In this case, it may be possible to return a scaling exponent as well as an error/value pair in order to save the result from exceeding the dynamic range of the built-in types.
43#[derive(Clone, Copy, Debug)]
44pub struct ResultE10 {
45    /// Contains the value.
46    pub val: f64,
47    /// Contains an estimate of the absolute error in the value.
48    pub err: f64,
49    /// Exponent field such that the actual result is obtained as result * 10^(e10).
50    pub e10: i32,
51}
52
53impl Default for ResultE10 {
54    fn default() -> ResultE10 {
55        ResultE10::new()
56    }
57}
58
59impl ResultE10 {
60    pub fn new() -> ResultE10 {
61        ResultE10 {
62            val: 0f64,
63            err: 0f64,
64            e10: 0i32,
65        }
66    }
67}
68
69impl From<::sys::gsl_sf_result_e10> for ResultE10 {
70    fn from(v: ::sys::gsl_sf_result_e10) -> Self {
71        Self {
72            val: v.val,
73            err: v.err,
74            e10: v.e10,
75        }
76    }
77}