@@ -45,18 +45,23 @@ pub trait Orderable: Ord {
45
45
fn clamp ( & self , mn : & Self , mx : & Self ) -> Self ;
46
46
}
47
47
48
- #[ inline( always) ] pub fn min < T : Orderable > ( a : T , b : T ) -> T { a. min ( & b) }
49
- #[ inline( always) ] pub fn max < T : Orderable > ( a : T , b : T ) -> T { a. max ( & b) }
48
+ #[ inline( always) ] pub fn min < T : Orderable > ( x : T , y : T ) -> T { x. min ( & y) }
49
+ #[ inline( always) ] pub fn max < T : Orderable > ( x : T , y : T ) -> T { x. max ( & y) }
50
+ #[ inline( always) ] pub fn clamp < T : Orderable > ( value : T , mn : T , mx : T ) -> T { value. clamp ( & mn, & mx) }
50
51
51
52
pub trait Zero {
52
53
fn zero ( ) -> Self ; // FIXME (#5527): This should be an associated constant
53
54
fn is_zero ( & self ) -> bool ;
54
55
}
55
56
57
+ #[ inline( always) ] pub fn zero < T : Zero > ( ) -> T { Zero :: zero ( ) }
58
+
56
59
pub trait One {
57
60
fn one ( ) -> Self ; // FIXME (#5527): This should be an associated constant
58
61
}
59
62
63
+ #[ inline( always) ] pub fn one < T : One > ( ) -> T { One :: one ( ) }
64
+
60
65
pub trait Signed : Num
61
66
+ Neg < Self > {
62
67
fn abs ( & self ) -> Self ;
@@ -68,6 +73,7 @@ pub trait Signed: Num
68
73
}
69
74
70
75
#[ inline( always) ] pub fn abs < T : Signed > ( value : T ) -> T { value. abs ( ) }
76
+ #[ inline( always) ] pub fn abs_sub < T : Signed > ( x : T , y : T ) -> T { x. abs_sub ( & y) }
71
77
#[ inline( always) ] pub fn signum < T : Signed > ( value : T ) -> T { value. signum ( ) }
72
78
73
79
pub trait Unsigned : Num { }
@@ -90,6 +96,9 @@ pub trait Integer: Num
90
96
fn is_odd ( & self ) -> bool ;
91
97
}
92
98
99
+ #[ inline( always) ] pub fn gcd < T : Integer > ( x : T , y : T ) -> T { x. gcd ( & y) }
100
+ #[ inline( always) ] pub fn lcm < T : Integer > ( x : T , y : T ) -> T { x. lcm ( & y) }
101
+
93
102
pub trait Round {
94
103
fn floor ( & self ) -> Self ;
95
104
fn ceil ( & self ) -> Self ;
@@ -113,15 +122,21 @@ pub trait Algebraic {
113
122
fn hypot ( & self , other : & Self ) -> Self ;
114
123
}
115
124
125
+ #[ inline( always) ] pub fn pow < T : Algebraic > ( value : T , n : T ) -> T { value. pow ( & n) }
116
126
#[ inline( always) ] pub fn sqrt < T : Algebraic > ( value : T ) -> T { value. sqrt ( ) }
127
+ #[ inline( always) ] pub fn rsqrt < T : Algebraic > ( value : T ) -> T { value. rsqrt ( ) }
128
+ #[ inline( always) ] pub fn cbrt < T : Algebraic > ( value : T ) -> T { value. cbrt ( ) }
129
+ #[ inline( always) ] pub fn hypot < T : Algebraic > ( x : T , y : T ) -> T { x. hypot ( & y) }
117
130
118
131
pub trait Trigonometric {
119
132
fn sin ( & self ) -> Self ;
120
133
fn cos ( & self ) -> Self ;
121
134
fn tan ( & self ) -> Self ;
135
+
122
136
fn asin ( & self ) -> Self ;
123
137
fn acos ( & self ) -> Self ;
124
138
fn atan ( & self ) -> Self ;
139
+
125
140
fn atan2 ( & self , other : & Self ) -> Self ;
126
141
fn sin_cos ( & self ) -> ( Self , Self ) ;
127
142
}
@@ -135,10 +150,12 @@ pub trait Trigonometric {
135
150
#[ inline( always) ] pub fn atan < T : Trigonometric > ( value : T ) -> T { value. atan ( ) }
136
151
137
152
#[ inline( always) ] pub fn atan2 < T : Trigonometric > ( x : T , y : T ) -> T { x. atan2 ( & y) }
153
+ #[ inline( always) ] pub fn sin_cos < T : Trigonometric > ( value : T ) -> ( T , T ) { value. sin_cos ( ) }
138
154
139
155
pub trait Exponential {
140
156
fn exp ( & self ) -> Self ;
141
157
fn exp2 ( & self ) -> Self ;
158
+
142
159
fn ln ( & self ) -> Self ;
143
160
fn log ( & self , base : & Self ) -> Self ;
144
161
fn log2 ( & self ) -> Self ;
@@ -157,6 +174,7 @@ pub trait Hyperbolic: Exponential {
157
174
fn sinh ( & self ) -> Self ;
158
175
fn cosh ( & self ) -> Self ;
159
176
fn tanh ( & self ) -> Self ;
177
+
160
178
fn asinh ( & self ) -> Self ;
161
179
fn acosh ( & self ) -> Self ;
162
180
fn atanh ( & self ) -> Self ;
@@ -326,6 +344,10 @@ pub trait Float: Real
326
344
}
327
345
328
346
///
347
+ #[ inline( always) ] pub fn exp_m1 < T : Float > ( value : T ) -> T { value. exp_m1 ( ) }
348
+ #[ inline( always) ] pub fn ln_1p < T : Float > ( value : T ) -> T { value. ln_1p ( ) }
349
+ #[ inline( always) ] pub fn mul_add < T : Float > ( a : T , b : T , c : T ) -> T { a. mul_add ( b, c) }
350
+
329
351
/// Cast from one machine scalar to another
330
352
///
331
353
/// # Example
0 commit comments