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