Skip to content
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

Clarify example for trait method float::Float::integer_decode #326

Merged
Changes from 2 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
10 changes: 5 additions & 5 deletions src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,16 +1866,16 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ```
/// use num_traits::Float;
///
/// let num = 2.0f32;
/// let num = 42_f32;
///
/// // (8388608, -22, 1)
/// // (11010048, -18, 1)
/// let (mantissa, exponent, sign) = Float::integer_decode(num);
/// let sign_f = sign as f32;
/// let mantissa_f = mantissa as f32;
/// let exponent_f = num.powf(exponent as f32);
/// let exponent_f = exponent as f32;
///
/// // 1 * 8388608 * 2^(-22) == 2
/// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs();
/// // 1 * 11010048 * 2^(-18) == 42
/// let abs_difference = (sign_f * mantissa_f * 2_f32.powf(exponent_f) - num).abs();
mtilda marked this conversation as resolved.
Show resolved Hide resolved
///
/// assert!(abs_difference < 1e-10);
/// ```
Expand Down