Skip to content

Commit c953b6c

Browse files
committed
doc: expand description for f32 and f64 associated constants
This explains the meaning of some of the floating-point associated constants.
1 parent ddfe1e8 commit c953b6c

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

library/core/src/num/f32.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -357,38 +357,76 @@ impl f32 {
357357
pub const MANTISSA_DIGITS: u32 = 24;
358358

359359
/// Approximate number of significant digits in base 10.
360+
///
361+
/// This is the maximum <i>x</i> such that any decimal number with <i>x</i>
362+
/// significant digits can be converted to `f32` and back without loss.
363+
///
364+
/// Equal to floor(log<sub>10</sub>&nbsp;2<sup>[`MANTISSA_DIGITS`]&nbsp;&minus;&nbsp;1</sup>).
365+
///
366+
/// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS
360367
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
361368
pub const DIGITS: u32 = 6;
362369

363370
/// [Machine epsilon] value for `f32`.
364371
///
365372
/// This is the difference between `1.0` and the next larger representable number.
366373
///
374+
/// Equal to 2<sup>1&nbsp;&minus;&nbsp;[`MANTISSA_DIGITS`]</sup>.
375+
///
367376
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
377+
/// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS
368378
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
369379
pub const EPSILON: f32 = 1.19209290e-07_f32;
370380

371381
/// Smallest finite `f32` value.
382+
///
383+
/// Equal to &minus;[`MAX`].
384+
///
385+
/// [`MAX`]: f32::MAX
372386
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
373387
pub const MIN: f32 = -3.40282347e+38_f32;
374388
/// Smallest positive normal `f32` value.
389+
///
390+
/// Equal to 2<sup>[`MIN_EXP`]&nbsp;&minus;&nbsp;1</sup>.
391+
///
392+
/// [`MIN_EXP`]: f32::MIN_EXP
375393
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
376394
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
377395
/// Largest finite `f32` value.
396+
///
397+
/// Equal to
398+
/// (1&nbsp;&minus;&nbsp;2<sup>&minus;[`MANTISSA_DIGITS`]</sup>)&nbsp;2<sup>[`MAX_EXP`]</sup>.
399+
///
400+
/// [`MANTISSA_DIGITS`]: f32::MANTISSA_DIGITS
401+
/// [`MAX_EXP`]: f32::MAX_EXP
378402
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
379403
pub const MAX: f32 = 3.40282347e+38_f32;
380404

381405
/// One greater than the minimum possible normal power of 2 exponent.
406+
///
407+
/// If <i>x</i>&nbsp;=&nbsp;`MIN_EXP`, then normal numbers
408+
/// ≥&nbsp;0.5&nbsp;×&nbsp;2<sup><i>x</i></sup>.
382409
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
383410
pub const MIN_EXP: i32 = -125;
384411
/// Maximum possible power of 2 exponent.
412+
///
413+
/// If <i>x</i>&nbsp;=&nbsp;`MAX_EXP`, then normal numbers
414+
/// &lt;&nbsp;1&nbsp;×&nbsp;2<sup><i>x</i></sup>.
385415
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
386416
pub const MAX_EXP: i32 = 128;
387417

388-
/// Minimum possible normal power of 10 exponent.
418+
/// Minimum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
419+
///
420+
/// Equal to ceil(log<sub>10</sub>&nbsp;[`MIN_POSITIVE`]).
421+
///
422+
/// [`MIN_POSITIVE`]: f32::MIN_POSITIVE
389423
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
390424
pub const MIN_10_EXP: i32 = -37;
391-
/// Maximum possible power of 10 exponent.
425+
/// Maximum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
426+
///
427+
/// Equal to floor(log<sub>10</sub>&nbsp;[`MAX`]).
428+
///
429+
/// [`MAX`]: f32::MAX
392430
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
393431
pub const MAX_10_EXP: i32 = 38;
394432

library/core/src/num/f64.rs

+40-2
Original file line numberDiff line numberDiff line change
@@ -356,38 +356,76 @@ impl f64 {
356356
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
357357
pub const MANTISSA_DIGITS: u32 = 53;
358358
/// Approximate number of significant digits in base 10.
359+
///
360+
/// This is the maximum <i>x</i> such that any decimal number with <i>x</i>
361+
/// significant digits can be converted to `f64` and back without loss.
362+
///
363+
/// Equal to floor(log<sub>10</sub>&nbsp;2<sup>[`MANTISSA_DIGITS`]&nbsp;&minus;&nbsp;1</sup>).
364+
///
365+
/// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS
359366
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
360367
pub const DIGITS: u32 = 15;
361368

362369
/// [Machine epsilon] value for `f64`.
363370
///
364371
/// This is the difference between `1.0` and the next larger representable number.
365372
///
373+
/// Equal to 2<sup>1&nbsp;&minus;&nbsp;[`MANTISSA_DIGITS`]</sup>.
374+
///
366375
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
376+
/// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS
367377
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
368378
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
369379

370380
/// Smallest finite `f64` value.
381+
///
382+
/// Equal to &minus;[`MAX`].
383+
///
384+
/// [`MAX`]: f64::MAX
371385
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
372386
pub const MIN: f64 = -1.7976931348623157e+308_f64;
373387
/// Smallest positive normal `f64` value.
388+
///
389+
/// Equal to 2<sup>[`MIN_EXP`]&nbsp;&minus;&nbsp;1</sup>.
390+
///
391+
/// [`MIN_EXP`]: f64::MIN_EXP
374392
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
375393
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
376394
/// Largest finite `f64` value.
395+
///
396+
/// Equal to
397+
/// (1&nbsp;&minus;&nbsp;2<sup>&minus;[`MANTISSA_DIGITS`]</sup>)&nbsp;2<sup>[`MAX_EXP`]</sup>.
398+
///
399+
/// [`MANTISSA_DIGITS`]: f64::MANTISSA_DIGITS
400+
/// [`MAX_EXP`]: f64::MAX_EXP
377401
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
378402
pub const MAX: f64 = 1.7976931348623157e+308_f64;
379403

380404
/// One greater than the minimum possible normal power of 2 exponent.
405+
///
406+
/// If <i>x</i>&nbsp;=&nbsp;`MIN_EXP`, then normal numbers
407+
/// ≥&nbsp;0.5&nbsp;×&nbsp;2<sup><i>x</i></sup>.
381408
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
382409
pub const MIN_EXP: i32 = -1021;
383410
/// Maximum possible power of 2 exponent.
411+
///
412+
/// If <i>x</i>&nbsp;=&nbsp;`MAX_EXP`, then normal numbers
413+
/// &lt;&nbsp;1&nbsp;×&nbsp;2<sup><i>x</i></sup>.
384414
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
385415
pub const MAX_EXP: i32 = 1024;
386416

387-
/// Minimum possible normal power of 10 exponent.
417+
/// Minimum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
418+
///
419+
/// Equal to ceil(log<sub>10</sub>&nbsp;[`MIN_POSITIVE`]).
420+
///
421+
/// [`MIN_POSITIVE`]: f64::MIN_POSITIVE
388422
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
389423
pub const MIN_10_EXP: i32 = -307;
390-
/// Maximum possible power of 10 exponent.
424+
/// Maximum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
425+
///
426+
/// Equal to floor(log<sub>10</sub>&nbsp;[`MAX`]).
427+
///
428+
/// [`MAX`]: f64::MAX
391429
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
392430
pub const MAX_10_EXP: i32 = 308;
393431

0 commit comments

Comments
 (0)