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 sign(self) -> Self {
14 if self == Self::zero() {
15 Self::zero()
16 } else {
17 self.signum()
18 }
19 }
20
21 fn total_cmp(&self, other: &Self) -> cmp::Ordering;
23}
24
25impl Float for f32 {
26 fn half() -> Self {
27 0.5
28 }
29
30 fn total_cmp(&self, other: &Self) -> cmp::Ordering {
31 self.total_cmp(other)
32 }
33}
34impl Float for f64 {
35 fn half() -> Self {
36 0.5
37 }
38
39 fn total_cmp(&self, other: &Self) -> cmp::Ordering {
40 self.total_cmp(other)
41 }
42}