@@ -42,26 +42,21 @@ pub trait Orderable: Ord {
42
42
fn clamp ( & self , mn : & Self , mx : & Self ) -> Self ;
43
43
}
44
44
45
- /// Return the smaller number.
46
45
#[ inline( always) ] pub fn min < T : Orderable > ( x : T , y : T ) -> T { x. min ( & y) }
47
- /// Return the larger number.
48
46
#[ inline( always) ] pub fn max < T : Orderable > ( x : T , y : T ) -> T { x. max ( & y) }
49
- /// Returns the number constrained within the range `mn <= self <= mx`.
50
47
#[ inline( always) ] pub fn clamp < T : Orderable > ( value : T , mn : T , mx : T ) -> T { value. clamp ( & mn, & mx) }
51
48
52
49
pub trait Zero {
53
50
fn zero ( ) -> Self ; // FIXME (#5527): This should be an associated constant
54
51
fn is_zero ( & self ) -> bool ;
55
52
}
56
53
57
- /// Returns `0` of appropriate type.
58
54
#[ inline( always) ] pub fn zero < T : Zero > ( ) -> T { Zero :: zero ( ) }
59
55
60
56
pub trait One {
61
57
fn one ( ) -> Self ; // FIXME (#5527): This should be an associated constant
62
58
}
63
59
64
- /// Returns `1` of appropriate type.
65
60
#[ inline( always) ] pub fn one < T : One > ( ) -> T { One :: one ( ) }
66
61
67
62
pub trait Signed : Num
@@ -74,26 +69,8 @@ pub trait Signed: Num
74
69
fn is_negative ( & self ) -> bool ;
75
70
}
76
71
77
- /// Computes the absolute value.
78
- ///
79
- /// For float, f32, and f64, `NaN` will be returned if the number is `NaN`
80
72
#[ inline( always) ] pub fn abs < T : Signed > ( value : T ) -> T { value. abs ( ) }
81
- /// The positive difference of two numbers.
82
- ///
83
- /// Returns `zero` if the number is less than or equal to `other`,
84
- /// otherwise the difference between `self` and `other` is returned.
85
73
#[ inline( always) ] pub fn abs_sub < T : Signed > ( x : T , y : T ) -> T { x. abs_sub ( & y) }
86
- /// Returns the sign of the number.
87
- ///
88
- /// For float, f32, f64:
89
- /// - `1.0` if the number is positive, `+0.0` or `infinity`
90
- /// - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
91
- /// - `NaN` if the number is `NaN`
92
- ///
93
- /// For int:
94
- /// - `0` if the number is zero
95
- /// - `1` if the number is positive
96
- /// - `-1` if the number is negative
97
74
#[ inline( always) ] pub fn signum < T : Signed > ( value : T ) -> T { value. signum ( ) }
98
75
99
76
pub trait Unsigned : Num { }
@@ -129,11 +106,7 @@ pub trait Integer: Num
129
106
fn is_odd ( & self ) -> bool ;
130
107
}
131
108
132
- /// Calculates the Greatest Common Divisor (GCD) of the number and `other`.
133
- ///
134
- /// The result is always positive.
135
109
#[ inline( always) ] pub fn gcd < T : Integer > ( x : T , y : T ) -> T { x. gcd ( & y) }
136
- /// Calculates the Lowest Common Multiple (LCM) of the number and `other`.
137
110
#[ inline( always) ] pub fn lcm < T : Integer > ( x : T , y : T ) -> T { x. lcm ( & y) }
138
111
139
112
pub trait Round {
@@ -159,23 +132,10 @@ pub trait Algebraic {
159
132
fn hypot ( & self , other : & Self ) -> Self ;
160
133
}
161
134
162
- /// Raise a number to a power.
163
- ///
164
- /// # Example
165
- ///
166
- /// ```rust
167
- /// let sixteen: float = num::pow(2.0, 4.0);
168
- /// assert_eq!(sixteen, 16.0);
169
- /// ```
170
135
#[ inline( always) ] pub fn pow < T : Algebraic > ( value : T , n : T ) -> T { value. pow ( & n) }
171
- /// Take the squre root of a number.
172
136
#[ inline( always) ] pub fn sqrt < T : Algebraic > ( value : T ) -> T { value. sqrt ( ) }
173
- /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`.
174
137
#[ inline( always) ] pub fn rsqrt < T : Algebraic > ( value : T ) -> T { value. rsqrt ( ) }
175
- /// Take the cubic root of a number.
176
138
#[ inline( always) ] pub fn cbrt < T : Algebraic > ( value : T ) -> T { value. cbrt ( ) }
177
- /// Calculate the length of the hypotenuse of a right-angle triangle given legs of length `x` and
178
- /// `y`.
179
139
#[ inline( always) ] pub fn hypot < T : Algebraic > ( x : T , y : T ) -> T { x. hypot ( & y) }
180
140
181
141
pub trait Trigonometric {
@@ -191,23 +151,15 @@ pub trait Trigonometric {
191
151
fn sin_cos ( & self ) -> ( Self , Self ) ;
192
152
}
193
153
194
- /// Sine function.
195
154
#[ inline( always) ] pub fn sin < T : Trigonometric > ( value : T ) -> T { value. sin ( ) }
196
- /// Cosine function.
197
155
#[ inline( always) ] pub fn cos < T : Trigonometric > ( value : T ) -> T { value. cos ( ) }
198
- /// Tangent function.
199
156
#[ inline( always) ] pub fn tan < T : Trigonometric > ( value : T ) -> T { value. tan ( ) }
200
157
201
- /// Compute the arcsine of the number.
202
158
#[ inline( always) ] pub fn asin < T : Trigonometric > ( value : T ) -> T { value. asin ( ) }
203
- /// Compute the arccosine of the number.
204
159
#[ inline( always) ] pub fn acos < T : Trigonometric > ( value : T ) -> T { value. acos ( ) }
205
- /// Compute the arctangent of the number.
206
160
#[ inline( always) ] pub fn atan < T : Trigonometric > ( value : T ) -> T { value. atan ( ) }
207
161
208
- /// Compute the arctangent with 2 arguments.
209
162
#[ inline( always) ] pub fn atan2 < T : Trigonometric > ( x : T , y : T ) -> T { x. atan2 ( & y) }
210
- /// Simultaneously computes the sine and cosine of the number.
211
163
#[ inline( always) ] pub fn sin_cos < T : Trigonometric > ( value : T ) -> ( T , T ) { value. sin_cos ( ) }
212
164
213
165
pub trait Exponential {
@@ -220,18 +172,12 @@ pub trait Exponential {
220
172
fn log10 ( & self ) -> Self ;
221
173
}
222
174
223
- /// Returns `e^(value)`, (the exponential function).
224
175
#[ inline( always) ] pub fn exp < T : Exponential > ( value : T ) -> T { value. exp ( ) }
225
- /// Returns 2 raised to the power of the number, `2^(value)`.
226
176
#[ inline( always) ] pub fn exp2 < T : Exponential > ( value : T ) -> T { value. exp2 ( ) }
227
177
228
- /// Returns the natural logarithm of the number.
229
178
#[ inline( always) ] pub fn ln < T : Exponential > ( value : T ) -> T { value. ln ( ) }
230
- /// Returns the logarithm of the number with respect to an arbitrary base.
231
179
#[ inline( always) ] pub fn log < T : Exponential > ( value : T , base : T ) -> T { value. log ( & base) }
232
- /// Returns the base 2 logarithm of the number.
233
180
#[ inline( always) ] pub fn log2 < T : Exponential > ( value : T ) -> T { value. log2 ( ) }
234
- /// Returns the base 10 logarithm of the number.
235
181
#[ inline( always) ] pub fn log10 < T : Exponential > ( value : T ) -> T { value. log10 ( ) }
236
182
237
183
pub trait Hyperbolic : Exponential {
@@ -244,18 +190,12 @@ pub trait Hyperbolic: Exponential {
244
190
fn atanh ( & self ) -> Self ;
245
191
}
246
192
247
- /// Hyperbolic cosine function.
248
193
#[ inline( always) ] pub fn sinh < T : Hyperbolic > ( value : T ) -> T { value. sinh ( ) }
249
- /// Hyperbolic sine function.
250
194
#[ inline( always) ] pub fn cosh < T : Hyperbolic > ( value : T ) -> T { value. cosh ( ) }
251
- /// Hyperbolic tangent function.
252
195
#[ inline( always) ] pub fn tanh < T : Hyperbolic > ( value : T ) -> T { value. tanh ( ) }
253
196
254
- /// Inverse hyperbolic sine function.
255
197
#[ inline( always) ] pub fn asinh < T : Hyperbolic > ( value : T ) -> T { value. asinh ( ) }
256
- /// Inverse hyperbolic cosine function.
257
198
#[ inline( always) ] pub fn acosh < T : Hyperbolic > ( value : T ) -> T { value. acosh ( ) }
258
- /// Inverse hyperbolic tangent function.
259
199
#[ inline( always) ] pub fn atanh < T : Hyperbolic > ( value : T ) -> T { value. atanh ( ) }
260
200
261
201
/// Defines constants and methods common to real numbers
@@ -405,16 +345,8 @@ pub trait Float: Real
405
345
fn next_after ( & self , other : Self ) -> Self ;
406
346
}
407
347
408
- /// Returns the exponential of the number, minus `1`, `exp(n) - 1`, in a way
409
- /// that is accurate even if the number is close to zero.
410
348
#[ inline( always) ] pub fn exp_m1 < T : Float > ( value : T ) -> T { value. exp_m1 ( ) }
411
- /// Returns the natural logarithm of the number plus `1`, `ln(n + 1)`, more
412
- /// accurately than if the operations were performed separately.
413
349
#[ inline( always) ] pub fn ln_1p < T : Float > ( value : T ) -> T { value. ln_1p ( ) }
414
- /// Fused multiply-add. Computes `(a * b) + c` with only one rounding error.
415
- ///
416
- /// This produces a more accurate result with better performance (on some
417
- /// architectures) than a separate multiplication operation followed by an add.
418
350
#[ inline( always) ] pub fn mul_add < T : Float > ( a : T , b : T , c : T ) -> T { a. mul_add ( b, c) }
419
351
420
352
/// A generic trait for converting a value to a number.
@@ -856,7 +788,7 @@ impl_from_primitive!(u64, n.to_u64())
856
788
impl_from_primitive ! ( f32 , n. to_f32( ) )
857
789
impl_from_primitive ! ( f64 , n. to_f64( ) )
858
790
859
- /// Cast from one machine scalar to another.
791
+ /// Cast from one machine scalar to another
860
792
///
861
793
/// # Example
862
794
///
@@ -909,7 +841,7 @@ pub trait FromStrRadix {
909
841
fn from_str_radix ( str : & str , radix : uint ) -> Option < Self > ;
910
842
}
911
843
912
- /// A utility function that just calls FromStrRadix::from_str_radix.
844
+ /// A utility function that just calls FromStrRadix::from_str_radix
913
845
pub fn from_str_radix < T : FromStrRadix > ( str : & str , radix : uint ) -> Option < T > {
914
846
FromStrRadix :: from_str_radix ( str, radix)
915
847
}
0 commit comments