Skip to content

Commit 891559e

Browse files
committed
Clean up core::num doc comments
1 parent 878bebf commit 891559e

File tree

1 file changed

+45
-50
lines changed

1 file changed

+45
-50
lines changed

src/libcore/num/mod.rs

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
// ignore-lexer-test FIXME #15679
1212

13-
//! Numeric traits and functions for generic mathematics
13+
//! Numeric traits and functions for the built-in numeric types.
1414
1515
#![allow(missing_docs)]
1616

@@ -33,45 +33,36 @@ pub fn div_rem<T: Div<T, T> + Rem<T, T>>(x: T, y: T) -> (T, T) {
3333
(x / y, x % y)
3434
}
3535

36-
/// Useful functions for signed numbers (i.e. numbers that can be negative).
36+
/// A built-in signed number.
3737
pub trait Signed: Neg<Self> {
38-
/// Computes the absolute value.
39-
///
40-
/// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`.
41-
///
42-
/// For signed integers, `::MIN` will be returned if the number is `::MIN`.
38+
/// Computes the absolute value of `self`.
4339
fn abs(self) -> Self;
4440

45-
/// Returns the sign of the number.
46-
///
47-
/// For `f32` and `f64`:
48-
///
49-
/// * `1.0` if the number is positive, `+0.0` or `INFINITY`
50-
/// * `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
51-
/// * `NaN` if the number is `NaN`
52-
///
53-
/// For signed integers:
54-
///
55-
/// * `0` if the number is zero
56-
/// * `1` if the number is positive
57-
/// * `-1` if the number is negative
41+
/// Returns a number (either `-1`, `0` or `1`) representing sign of `self`.
5842
fn signum(self) -> Self;
5943

60-
/// Returns true if the number is positive and false if the number is zero or negative.
44+
/// Returns `true` if `self` is a positive value.
6145
fn is_positive(self) -> bool;
6246

63-
/// Returns true if the number is negative and false if the number is zero or positive.
47+
/// Returns `true` if `self` is a negative value.
6448
fn is_negative(self) -> bool;
6549
}
6650

6751
macro_rules! signed_int_impl {
6852
($T:ty) => {
6953
impl Signed for $T {
54+
/// Computes the absolute value. `Int::min_value()` will be returned
55+
/// if the number is `Int::min_value()`.
7056
#[inline]
7157
fn abs(self) -> $T {
7258
if self.is_negative() { -self } else { self }
7359
}
7460

61+
/// # Returns
62+
///
63+
/// - `0` if the number is zero
64+
/// - `1` if the number is positive
65+
/// - `-1` if the number is negative
7566
#[inline]
7667
fn signum(self) -> $T {
7768
match self {
@@ -81,9 +72,13 @@ macro_rules! signed_int_impl {
8172
}
8273
}
8374

75+
/// Returns `true` if `self` is positive and `false` if the number
76+
/// is zero or negative.
8477
#[inline]
8578
fn is_positive(self) -> bool { self > 0 }
8679

80+
/// Returns `true` if `self` is negative and `false` if the number
81+
/// is zero or positive.
8782
#[inline]
8883
fn is_negative(self) -> bool { self < 0 }
8984
}
@@ -99,7 +94,8 @@ signed_int_impl!(int)
9994
macro_rules! signed_float_impl {
10095
($T:ty, $fabs:path, $fcopysign:path) => {
10196
impl Signed for $T {
102-
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
97+
/// Computes the absolute value. Returns `Float::nan()` if the
98+
/// number is `Float::nan()`.
10399
#[inline]
104100
fn abs(self) -> $T {
105101
unsafe { $fabs(self) }
@@ -144,7 +140,7 @@ signed_float_impl!(f64,
144140
intrinsics::fabsf64,
145141
intrinsics::copysignf64)
146142

147-
/// Raises a value to the power of exp, using exponentiation by squaring.
143+
/// Raises a `base` to the power of `exp`, using exponentiation by squaring.
148144
///
149145
/// # Example
150146
///
@@ -169,8 +165,7 @@ pub fn pow<T: Int>(mut base: T, mut exp: uint) -> T {
169165
}
170166
}
171167

172-
/// A primitive signed or unsigned integer equipped with various bitwise
173-
/// operators, bit counting methods, and endian conversion functions.
168+
/// A built-in signed or unsigned integer.
174169
pub trait Int
175170
: Copy + Clone
176171
+ NumCast
@@ -188,23 +183,23 @@ pub trait Int
188183
+ Shl<uint,Self>
189184
+ Shr<uint,Self>
190185
{
191-
/// Returns the `0` value of this integer.
186+
/// Returns the `0` value of this integer type.
192187
// FIXME (#5527): Should be an associated constant
193188
fn zero() -> Self;
194189

195-
/// Returns the `1` value of this integer.
190+
/// Returns the `1` value of this integer type.
196191
// FIXME (#5527): Should be an associated constant
197192
fn one() -> Self;
198193

199-
/// Returns the smallest value that can be represented by this integer.
194+
/// Returns the smallest value that can be represented by this integer type.
200195
// FIXME (#5527): Should be and associated constant
201196
fn min_value() -> Self;
202197

203-
/// Returns the largest value that can be represented by this integer.
198+
/// Returns the largest value that can be represented by this integer type.
204199
// FIXME (#5527): Should be and associated constant
205200
fn max_value() -> Self;
206201

207-
/// Returns the number of ones in the binary representation of the integer.
202+
/// Returns the number of ones in the binary representation of `self`.
208203
///
209204
/// # Example
210205
///
@@ -215,7 +210,7 @@ pub trait Int
215210
/// ```
216211
fn count_ones(self) -> uint;
217212

218-
/// Returns the number of zeros in the binary representation of the integer.
213+
/// Returns the number of zeros in the binary representation of `self`.
219214
///
220215
/// # Example
221216
///
@@ -230,7 +225,7 @@ pub trait Int
230225
}
231226

232227
/// Returns the number of leading zeros in the binary representation
233-
/// of the integer.
228+
/// of `self`.
234229
///
235230
/// # Example
236231
///
@@ -242,7 +237,7 @@ pub trait Int
242237
fn leading_zeros(self) -> uint;
243238

244239
/// Returns the number of trailing zeros in the binary representation
245-
/// of the integer.
240+
/// of `self`.
246241
///
247242
/// # Example
248243
///
@@ -331,7 +326,7 @@ pub trait Int
331326
if cfg!(target_endian = "little") { x } else { x.swap_bytes() }
332327
}
333328

334-
/// Convert the integer to big endian from the target's endianness.
329+
/// Convert `self` to big endian from the target's endianness.
335330
///
336331
/// On big endian this is a no-op. On little endian the bytes are swapped.
337332
///
@@ -351,7 +346,7 @@ pub trait Int
351346
if cfg!(target_endian = "big") { self } else { self.swap_bytes() }
352347
}
353348

354-
/// Convert the integer to little endian from the target's endianness.
349+
/// Convert `self` to little endian from the target's endianness.
355350
///
356351
/// On little endian this is a no-op. On big endian the bytes are swapped.
357352
///
@@ -371,8 +366,8 @@ pub trait Int
371366
if cfg!(target_endian = "little") { self } else { self.swap_bytes() }
372367
}
373368

374-
/// Adds two numbers, checking for overflow. If overflow occurs, `None` is
375-
/// returned.
369+
/// Checked integer addition. Computes `self + other`, returning `None` if
370+
/// overflow occurred.
376371
///
377372
/// # Example
378373
///
@@ -384,8 +379,8 @@ pub trait Int
384379
/// ```
385380
fn checked_add(self, other: Self) -> Option<Self>;
386381

387-
/// Subtracts two numbers, checking for underflow. If underflow occurs,
388-
/// `None` is returned.
382+
/// Checked integer subtraction. Computes `self + other`, returning `None`
383+
/// if underflow occurred.
389384
///
390385
/// # Example
391386
///
@@ -397,8 +392,8 @@ pub trait Int
397392
/// ```
398393
fn checked_sub(self, other: Self) -> Option<Self>;
399394

400-
/// Multiplies two numbers, checking for underflow or overflow. If underflow
401-
/// or overflow occurs, `None` is returned.
395+
/// Checked integer multiplication. Computes `self + other`, returning
396+
/// `None` if underflow or overflow occurred.
402397
///
403398
/// # Example
404399
///
@@ -410,8 +405,8 @@ pub trait Int
410405
/// ```
411406
fn checked_mul(self, other: Self) -> Option<Self>;
412407

413-
/// Divides two numbers, checking for underflow, overflow and division by
414-
/// zero. If underflow occurs, `None` is returned.
408+
/// Checked integer division. Computes `self + other` returning `None` if
409+
/// `self == 0` or the operation results in underflow or overflow.
415410
///
416411
/// # Example
417412
///
@@ -425,8 +420,8 @@ pub trait Int
425420
#[inline]
426421
fn checked_div(self, other: Self) -> Option<Self>;
427422

428-
/// Saturating addition. Returns `self + other`, saturating at the
429-
/// numeric bounds instead of overflowing.
423+
/// Saturating integer addition. Computes `self + other`, saturating at
424+
/// the numeric bounds instead of overflowing.
430425
#[inline]
431426
fn saturating_add(self, other: Self) -> Self {
432427
match self.checked_add(other) {
@@ -436,8 +431,8 @@ pub trait Int
436431
}
437432
}
438433

439-
/// Saturating subtraction. Returns `self - other`, saturating at the
440-
/// numeric bounds instead of overflowing.
434+
/// Saturating integer subtraction. Computes `self - other`, saturating at
435+
/// the numeric bounds instead of overflowing.
441436
#[inline]
442437
fn saturating_sub(self, other: Self) -> Self {
443438
match self.checked_sub(other) {
@@ -685,7 +680,7 @@ int_impl!(int = i64, u64, 64,
685680
intrinsics::i64_sub_with_overflow,
686681
intrinsics::i64_mul_with_overflow)
687682

688-
/// Unsigned integers
683+
/// A built-in unsigned integer.
689684
pub trait UnsignedInt: Int {
690685
/// Returns `true` iff `self == 2^k` for some `k`.
691686
fn is_power_of_two(self) -> bool {
@@ -1229,7 +1224,7 @@ pub enum FPCategory {
12291224
FPNormal,
12301225
}
12311226

1232-
/// Operations on the built-in floating point numbers.
1227+
/// A built-in floating point number.
12331228
// FIXME(#5527): In a future version of Rust, many of these functions will
12341229
// become constants.
12351230
//

0 commit comments

Comments
 (0)