Skip to content

Commit 5d6b32f

Browse files
authored
Merge pull request #1242 from dtolnay/writefloat
Document behavior of write_f32/f64 on non-finite floats
2 parents 7a79781 + e5bb8bd commit 5d6b32f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/ser.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,20 @@ pub trait Formatter {
16881688
}
16891689

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy