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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use num::complex::ComplexFloat;
use std::fmt;
use std::ops;

/// An integration method.
pub use peroxide::numerical::integral::Integral;

/// A real number.
pub type R = f64;

/// A complex number.
pub type C = num::Complex<R>;

/// An integer type for the number of colors.
///
/// Used by [`set_number_of_colors`](crate::consts::set_number_of_colors).
pub type NCTYPE = u32;

/// An integer type for the number of fermions.
///
/// Used by [`set_number_of_fermions`](crate::consts::set_number_of_fermions).
pub type NFTYPE = u32;

/// A number.
pub trait Num:
    Copy
    + num::Num
    + fmt::Debug
    + fmt::Display
    + ops::Add<R, Output = Self>
    + ops::Mul<R, Output = Self>
    + ops::Div<R, Output = Self>
    + ops::Sub<R, Output = Self>
    + ops::Neg<Output = Self>
    + ops::Add<C, Output = C>
    + ops::Sub<C, Output = C>
    + ops::Mul<C, Output = C>
    + ops::Div<C, Output = C>
    + From<R>
    + Into<C>
{
    fn abs(&self) -> R;
    fn exp(&self) -> Self;
    fn im(&self) -> R;
    fn inv(&self) -> Self;
    fn ln(&self) -> Self;
    fn re(&self) -> R;
    fn sqrt(&self) -> Self;
}

impl Num for R {
    #[inline(always)]
    fn abs(&self) -> R {
        (*self as Self).abs()
    }

    #[inline(always)]
    fn exp(&self) -> Self {
        (*self as Self).exp()
    }

    #[inline(always)]
    fn im(&self) -> R {
        0.
    }

    #[inline(always)]
    fn inv(&self) -> Self {
        1. / self
    }

    #[inline(always)]
    fn ln(&self) -> Self {
        (*self as Self).ln()
    }

    #[inline(always)]
    fn re(&self) -> R {
        *self
    }

    #[inline(always)]
    fn sqrt(&self) -> Self {
        (*self as Self).sqrt()
    }
}

impl Num for C {
    #[inline(always)]
    fn abs(&self) -> R {
        (*self as Self).abs()
    }

    #[inline(always)]
    fn exp(&self) -> Self {
        (*self as Self).exp()
    }

    #[inline(always)]
    fn im(&self) -> R {
        self.im
    }

    #[inline(always)]
    fn inv(&self) -> Self {
        1. / self
    }

    #[inline(always)]
    fn ln(&self) -> Self {
        (*self as Self).ln()
    }

    #[inline(always)]
    fn re(&self) -> R {
        self.re
    }

    #[inline(always)]
    fn sqrt(&self) -> Self {
        (*self as Self).sqrt()
    }
}