Skip to content

deprecate f{32,64}::DIGITS #89238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ pub const RADIX: u32 = f32::RADIX;
)]
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;

/// Approximate number of significant digits in base 10.
/// Use [`f32::DIGITS`] instead.
/// A minimum number of significant digits in base 10.
/// This value is likely incorrect for usage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need to elaborate on this and add a small example of how this can be incorrect.

/// as it is not the upper limit of significant digits `f32` can contain.
///
/// # Examples
///
/// ```rust
/// // deprecated way
/// # #[allow(deprecated, deprecated_in_future)]
/// let d = std::f32::DIGITS;
///
/// // intended way
/// // also deprecated
/// # #[allow(deprecated, deprecated_in_future)]
/// let d = f32::DIGITS;
///
/// // the intended way may vary by application
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_deprecated(since = "TBD", reason = "replaced by the `DIGITS` associated constant on `f32`")]
#[rustc_deprecated(
since = "TBD",
reason = "this value is incorrect or misleading as it actually encompasses a range"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really tiny nit, but I feel like the word 'encompasses' is misleading here. I might read that and think that the deprecated value is the upper bound, and therefore safe.
Maybe change it to say "the actual number of significant digits varies over a range, and this value is the minimum number of significant digits" or something else that makes the problem clear.

)]
#[allow(deprecated, deprecated_in_future)]
pub const DIGITS: u32 = f32::DIGITS;

/// [Machine epsilon] value for `f32`.
Expand Down Expand Up @@ -381,8 +388,14 @@ impl f32 {
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
pub const MANTISSA_DIGITS: u32 = 24;

/// Approximate number of significant digits in base 10.
/// A minimum number of significant digits in base 10.
/// This value is likely incorrect for usage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here as well

/// as it is not the upper limit of significant digits `f32` can contain.
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
#[rustc_deprecated(
since = "TBD",
reason = "this value is incorrect or misleading as it actually encompasses a range"
)]
pub const DIGITS: u32 = 6;

/// [Machine epsilon] value for `f32`.
Expand Down
26 changes: 20 additions & 6 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ pub const RADIX: u32 = f64::RADIX;
)]
pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS;

/// Approximate number of significant digits in base 10.
/// Use [`f64::DIGITS`] instead.
/// A minimum number of significant digits in base 10.
/// This value is likely incorrect for usage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

/// as it is not the upper limit of significant digits `f64` can contain.
///
/// # Examples
///
/// ```rust
/// // deprecated way
/// # #[allow(deprecated, deprecated_in_future)]
/// let d = std::f64::DIGITS;
///
/// // intended way
/// // also deprecated
/// # #[allow(deprecated, deprecated_in_future)]
/// let d = f64::DIGITS;
///
/// // the intended way may vary by application
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_deprecated(since = "TBD", reason = "replaced by the `DIGITS` associated constant on `f64`")]
#[rustc_deprecated(
since = "TBD",
reason = "this value is incorrect or misleading as it actually encompasses a range"
)]
#[allow(deprecated, deprecated_in_future)]
pub const DIGITS: u32 = f64::DIGITS;

/// [Machine epsilon] value for `f64`.
Expand Down Expand Up @@ -380,8 +387,15 @@ impl f64 {
/// Number of significant digits in base 2.
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
pub const MANTISSA_DIGITS: u32 = 53;
/// Approximate number of significant digits in base 10.

/// A minimum number of significant digits in base 10.
/// This value is likely incorrect for usage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

/// as it is not the upper limit of significant digits `f64` can contain.
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
#[rustc_deprecated(
since = "TBD",
reason = "this value is incorrect or misleading as it actually encompasses a range"
)]
pub const DIGITS: u32 = 15;

/// [Machine epsilon] value for `f64`.
Expand Down