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
80
81
82
83
84
85
86
use crate::numeric::num::Num;
use crate::numeric::sign::Signed;
use crate::numeric::trig::Trig;
use std::num::FpCategory;

pub trait Float: Num + Signed + Trig + PartialOrd + Copy {
    fn is_finite(self) -> bool;
    fn is_infinite(self) -> bool;
    fn is_nan(self) -> bool;
    fn is_normal(self) -> bool;
    fn is_sign_positive(self) -> bool;
    fn is_sing_negative(self) -> bool;
    fn classify(self) -> FpCategory;
    fn recip(self) -> Self;
    fn floor(self) -> Self;
    fn ceil(self) -> Self;
    fn round(self) -> Self;
    fn trunc(self) -> Self;
    fn fract(self) -> Self;
    fn copysign(self, sign: Self) -> Self;
    fn mul_add(self, a: Self, b: Self) -> Self;
    fn div_euclid(self, rhs: Self) -> Self;
    fn rem_euclid(self, rhs: Self) -> Self;
    fn powi(self, n: i32) -> Self;
    fn powf(self, n: Self) -> Self;
    fn sqrt(self) -> Self;
    fn exp(self) -> Self;
    fn exp2(self) -> Self;
    fn ln(self) -> Self;
    fn log(self, base: Self) -> Self;
    fn log2(self) -> Self;
    fn log10(self) -> Self;
    fn cbrt(self) -> Self;
    fn hypot(self, rhs: Self) -> Self;
    fn exp_m1(self) -> Self;
    fn ln_1p(self) -> Self;
}

macro_rules! impl_float {
    ($($t:ty)*) => {
        $(
            impl Float for $t {

                fn is_sign_positive(self) -> bool {
                    <$t>::is_sign_positive(self)
                }
                fn is_sing_negative(self) -> bool{
                    <$t>::is_sign_negative(self)
                }

                forward! {
                    fn is_finite(self) -> bool;
                    fn is_infinite(self) -> bool;
                    fn is_nan(self) -> bool;
                    fn is_normal(self) -> bool;
                    fn classify(self) -> FpCategory;
                    fn recip(self) -> Self;
                    fn floor(self) -> Self;
                    fn ceil(self) -> Self;
                    fn round(self) -> Self;
                    fn trunc(self) -> Self;
                    fn fract(self) -> Self;
                    fn copysign(self, sign: Self) -> Self;
                    fn mul_add(self, a: Self, b: Self) -> Self;
                    fn div_euclid(self, rhs: Self) -> Self;
                    fn rem_euclid(self, rhs: Self) -> Self;
                    fn powi(self, n: i32) -> Self;
                    fn powf(self, n: Self) -> Self;
                    fn sqrt(self) -> Self;
                    fn exp(self) -> Self;
                    fn exp2(self) -> Self;
                    fn ln(self) -> Self;
                    fn log(self, base: Self) -> Self;
                    fn log2(self) -> Self;
                    fn log10(self) -> Self;
                    fn cbrt(self) -> Self;
                    fn hypot(self, rhs: Self) -> Self;
                    fn exp_m1(self) -> Self;
                    fn ln_1p(self) -> Self;
                }
            }
        )*
    }
}

impl_float!(f32 f64);