1use std::cmp;
3
4use ndarray::ScalarOperand;
5use ndarray_linalg::Lapack;
6
7pub trait Float: Sized + num_traits::Float + Lapack + ScalarOperand {
8 fn half() -> Self;
10
11 fn two() -> Self;
13
14 fn sign(self) -> Self {
17 if self == Self::zero() {
18 Self::zero()
19 } else {
20 self.signum()
21 }
22 }
23
24 fn total_cmp(&self, other: &Self) -> cmp::Ordering;
26}
27
28impl Float for f32 {
29 fn half() -> Self {
30 0.5
31 }
32
33 fn two() -> Self {
34 2.0
35 }
36
37 fn total_cmp(&self, other: &Self) -> cmp::Ordering {
38 self.total_cmp(other)
39 }
40}
41impl Float for f64 {
42 fn half() -> Self {
43 0.5
44 }
45
46 fn two() -> Self {
47 2.0
48 }
49
50 fn total_cmp(&self, other: &Self) -> cmp::Ordering {
51 self.total_cmp(other)
52 }
53}