@@ -75,43 +75,73 @@ pub fn regular_sum(xs: &[f64]) -> f64 {
75
75
macro_rules! impl_op {
76
76
( $( $name: ident, $method: ident, $intrins: ident; ) * ) => {
77
77
$(
78
- impl $name for Fast <f64 > {
78
+ // Fast<F> + F
79
+ impl $name<f64 > for Fast <f64 > {
79
80
type Output = Self ;
80
81
#[ inline( always) ]
81
- fn $method( self , rhs: Self ) -> Self :: Output {
82
+ fn $method( self , rhs: f64 ) -> Self :: Output {
82
83
unsafe {
83
- Fast ( $intrins( self . 0 , rhs. 0 ) )
84
+ Fast ( $intrins( self . 0 , rhs) )
84
85
}
85
86
}
86
87
}
87
88
88
- impl $name for Fast <f32 > {
89
+ impl $name< f32 > for Fast <f32 > {
89
90
type Output = Self ;
90
91
#[ inline( always) ]
91
- fn $method( self , rhs: Self ) -> Self :: Output {
92
+ fn $method( self , rhs: f32 ) -> Self :: Output {
92
93
unsafe {
93
- Fast ( $intrins( self . 0 , rhs. 0 ) )
94
+ Fast ( $intrins( self . 0 , rhs) )
94
95
}
95
96
}
96
97
}
97
- ) *
98
98
99
- }
100
- }
99
+ // F + Fast<F>
100
+ impl $name<Fast <f64 >> for f64 {
101
+ type Output = Fast <f64 >;
102
+ #[ inline( always) ]
103
+ fn $method( self , rhs: Fast <f64 >) -> Self :: Output {
104
+ Fast ( self ) . $method( rhs. 0 )
105
+ }
106
+ }
101
107
102
- macro_rules! impl_assignop {
103
- ( $( $name: ident, $method: ident, $intrins: ident; ) * ) => {
104
- $(
108
+ impl $name<Fast <f32 >> for f32 {
109
+ type Output = Fast <f32 >;
110
+ #[ inline( always) ]
111
+ fn $method( self , rhs: Fast <f32 >) -> Self :: Output {
112
+ Fast ( self ) . $method( rhs. 0 )
113
+ }
114
+ }
115
+
116
+ // Fast<F> + Fast<F>
105
117
impl $name for Fast <f64 > {
118
+ type Output = Self ;
106
119
#[ inline( always) ]
107
- fn $method( & mut self , rhs: Self ) {
108
- * self = * self + rhs
120
+ fn $method( self , rhs: Self ) -> Self :: Output {
121
+ self . $method ( rhs. 0 )
109
122
}
110
123
}
111
124
112
125
impl $name for Fast <f32 > {
126
+ type Output = Self ;
127
+ #[ inline( always) ]
128
+ fn $method( self , rhs: Self ) -> Self :: Output {
129
+ self . $method( rhs. 0 )
130
+ }
131
+ }
132
+ ) *
133
+
134
+ }
135
+ }
136
+
137
+ macro_rules! impl_assignop {
138
+ ( $( $name: ident, $method: ident, $intrins: ident; ) * ) => {
139
+ $(
140
+ impl <F , Rhs > $name<Rhs > for Fast <F >
141
+ where Self : Add <Rhs , Output =Self > + Copy ,
142
+ {
113
143
#[ inline( always) ]
114
- fn $method( & mut self , rhs: Self ) {
144
+ fn $method( & mut self , rhs: Rhs ) {
115
145
* self = * self + rhs
116
146
}
117
147
}
0 commit comments