Skip to content

Commit

Permalink
Merge pull request #1242 from dtolnay/writefloat
Browse files Browse the repository at this point in the history
Document behavior of write_f32/f64 on non-finite floats
  • Loading branch information
dtolnay authored Feb 20, 2025
2 parents 7a79781 + e5bb8bd commit 5d6b32f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,20 @@ pub trait Formatter {
}

/// Writes a floating point value like `-31.26e+12` to the specified writer.
///
/// # Special cases
///
/// This function **does not** check for NaN or infinity. If the input
/// number is not a finite float, the printed representation will be some
/// correctly formatted but unspecified numerical value.
///
/// Please check [`is_finite`] yourself before calling this function, or
/// check [`is_nan`] and [`is_infinite`] and handle those cases yourself
/// with a different `Formatter` method.
///
/// [`is_finite`]: f32::is_finite
/// [`is_nan`]: f32::is_nan
/// [`is_infinite`]: f32::is_infinite
#[inline]
fn write_f32<W>(&mut self, writer: &mut W, value: f32) -> io::Result<()>
where
Expand All @@ -1699,6 +1713,20 @@ pub trait Formatter {
}

/// Writes a floating point value like `-31.26e+12` to the specified writer.
///
/// # Special cases
///
/// This function **does not** check for NaN or infinity. If the input
/// number is not a finite float, the printed representation will be some
/// correctly formatted but unspecified numerical value.
///
/// Please check [`is_finite`] yourself before calling this function, or
/// check [`is_nan`] and [`is_infinite`] and handle those cases yourself
/// with a different `Formatter` method.
///
/// [`is_finite`]: f64::is_finite
/// [`is_nan`]: f64::is_nan
/// [`is_infinite`]: f64::is_infinite
#[inline]
fn write_f64<W>(&mut self, writer: &mut W, value: f64) -> io::Result<()>
where
Expand Down

0 comments on commit 5d6b32f

Please sign in to comment.