8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- //! An interface for numeric types
11
+ //! Numeric traits and functions for generic mathematics.
12
+ //!
13
+ //! These are implemented for the primitive numeric types in `std::{u8, u16,
14
+ //! u32, u64, uint, i8, i16, i32, i64, int, f32, f64, float}`.
12
15
13
16
#[ allow( missing_doc) ] ;
14
17
@@ -19,9 +22,7 @@ use option::Option;
19
22
20
23
pub mod strconv;
21
24
22
- ///
23
25
/// The base trait for numeric types
24
- ///
25
26
pub trait Num : Eq + Zero + One
26
27
+ Neg < Self >
27
28
+ Add < Self , Self >
@@ -188,9 +189,7 @@ pub trait Hyperbolic: Exponential {
188
189
#[ inline( always) ] pub fn acosh < T : Hyperbolic > ( value : T ) -> T { value. acosh ( ) }
189
190
#[ inline( always) ] pub fn atanh < T : Hyperbolic > ( value : T ) -> T { value. atanh ( ) }
190
191
191
- ///
192
192
/// Defines constants and methods common to real numbers
193
- ///
194
193
pub trait Real : Signed
195
194
+ Fractional
196
195
+ Algebraic
@@ -221,9 +220,7 @@ pub trait Real: Signed
221
220
fn to_radians ( & self ) -> Self ;
222
221
}
223
222
224
- ///
225
223
/// Methods that are harder to implement and not commonly used.
226
- ///
227
224
pub trait RealExt : Real {
228
225
// FIXME (#5527): usages of `int` should be replaced with an associated
229
226
// integer type once these are implemented
@@ -241,9 +238,7 @@ pub trait RealExt: Real {
241
238
fn yn ( & self , n : int ) -> Self ;
242
239
}
243
240
244
- ///
245
241
/// Collects the bitwise operators under one trait.
246
- ///
247
242
pub trait Bitwise : Not < Self >
248
243
+ BitAnd < Self , Self >
249
244
+ BitOr < Self , Self >
@@ -263,11 +258,9 @@ pub trait Bounded {
263
258
fn max_value ( ) -> Self ;
264
259
}
265
260
266
- ///
267
261
/// Specifies the available operations common to all of Rust's core numeric primitives.
268
262
/// These may not always make sense from a purely mathematical point of view, but
269
263
/// may be useful for systems programming.
270
- ///
271
264
pub trait Primitive : Num
272
265
+ NumCast
273
266
+ Bounded
@@ -282,17 +275,13 @@ pub trait Primitive: Num
282
275
fn bytes ( ) -> uint ;
283
276
}
284
277
285
- ///
286
278
/// A collection of traits relevant to primitive signed and unsigned integers
287
- ///
288
279
pub trait Int : Integer
289
280
+ Primitive
290
281
+ Bitwise
291
282
+ BitCount { }
292
283
293
- ///
294
284
/// Used for representing the classification of floating point numbers
295
- ///
296
285
#[ deriving( Eq ) ]
297
286
pub enum FPCategory {
298
287
/// "Not a Number", often obtained by dividing by zero
@@ -307,9 +296,7 @@ pub enum FPCategory {
307
296
FPNormal ,
308
297
}
309
298
310
- ///
311
299
/// Primitive floating point numbers
312
- ///
313
300
pub trait Float : Real
314
301
+ Signed
315
302
+ Primitive
@@ -343,7 +330,6 @@ pub trait Float: Real
343
330
fn next_after ( & self , other : Self ) -> Self ;
344
331
}
345
332
346
- ///
347
333
#[ inline( always) ] pub fn exp_m1 < T : Float > ( value : T ) -> T { value. exp_m1 ( ) }
348
334
#[ inline( always) ] pub fn ln_1p < T : Float > ( value : T ) -> T { value. ln_1p ( ) }
349
335
#[ inline( always) ] pub fn mul_add < T : Float > ( a : T , b : T , c : T ) -> T { a. mul_add ( b, c) }
@@ -362,9 +348,7 @@ pub fn cast<T:NumCast,U:NumCast>(n: T) -> U {
362
348
NumCast :: from ( n)
363
349
}
364
350
365
- ///
366
351
/// An interface for casting between machine scalars
367
- ///
368
352
pub trait NumCast {
369
353
fn from < T : NumCast > ( n : T ) -> Self ;
370
354
@@ -436,7 +420,6 @@ pub trait FromStrRadix {
436
420
pub fn from_str_radix ( str : & str , radix : uint ) -> Option < Self > ;
437
421
}
438
422
439
- ///
440
423
/// Calculates a power to a given radix, optimized for uint `pow` and `radix`.
441
424
///
442
425
/// Returns `radix^pow` as `T`.
0 commit comments