1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! # traits::floating
//!
//! Types that implement this trait can be considered as floating-point numbers.
use crate::number::traits::fractional::Fractional;
/// Concepts of Floating.
pub trait Floating: Fractional {
/// Zero of the floating-point type.
const ZERO: Self;
/// Floating-point constant pi, approximately `3.141592653589793`.
const PI: Self;
/// Exponential function with base of the Euler's number, exp(x).
fn exponential(self) -> Self;
/// Logarithmic function with base of the Euler's number, ln(x).
fn logarithmic(self) -> Self;
/// Square root function.
fn square_root(self) -> Self { self.power(Self::half()) }
/// Sine function, sin(x).
fn sine(self) -> Self;
/// Cosine function, cos(x).
fn cosine(self) -> Self;
/// Tangent function, tan(x).
fn tangent(self) -> Self { self.clone().sine() / self.cosine() }
/// Arcsine function, asin(x).
fn arc_sine(self) -> Self;
/// Arccosine function, acos(x).
fn arc_cosine(self) -> Self;
/// Arctangent function, atan(x).
fn arc_tangent(self) -> Self;
/// Hyperbolic sine function, sinh(x).
fn hyperbolic_sine(self) -> Self;
/// Hyperbolic cosine function, cosh(x).
fn hyperbolic_cosine(self) -> Self;
/// Hyperbolic tangent function, tanh(x).
fn hyperbolic_tangent(self) -> Self;
/// Inverse hyperbolic sine function, asinh(x).
fn arc_hyperbolic_sine(self) -> Self;
/// Inverse hyperbolic cosine function, acosh(x).
fn arc_hyperbolic_cosine(self) -> Self;
/// Inverse hyperbolic tangent function, atanh(x).
fn arc_hyperbolic_tangent(self) -> Self;
/// Power function, pow(x, a).
fn power(self, exponents: Self) -> Self { (self.logarithmic() * exponents).exponential() }
/// Logarithm function with base a, log(a, x).
fn logarithmic_base(self, base: Self) -> Self { self.logarithmic() / base.logarithmic() }
/// Logarithm function with base Euler's number plus one, ln(1 + x).
fn logarithmic_1p(self) -> Self { (Self::one() + self).logarithmic() }
/// Exponential function with base Euler's number minus one, exp(x) - 1.
fn exponential_1m(self) -> Self { self.exponential() - Self::one() }
/// Logarithm function plus one of the exponential function
/// with base Euler's number, ln(1 + exp(x)).
fn logarithmic_1p_exponential(self) -> Self { self.exponential().logarithmic_1p() }
/// Logarithm function minus one of the exponential function
/// with base Euler's number, ln(1 - exp(x)).
fn logarithmic_1m_exponential(self) -> Self { (-self.exponential()).logarithmic_1p() }
}