Skip to content

Commit 66d20d7

Browse files
committed
Auto merge of rust-lang#97315 - Dylan-DPC:rollup-2wee2oz, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - rust-lang#96129 (Document rounding for floating-point primitive operations and string parsing) - rust-lang#97286 (Add new eslint rule to prevent whitespace before function call paren) - rust-lang#97292 (Lifetime variance fixes for rustc) - rust-lang#97309 (Add some regression tests for rust-lang#90400) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 31a5521 + 624cb31 commit 66d20d7

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

core/src/num/dec2flt/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ macro_rules! from_str_float_impl {
143143
/// # Return value
144144
///
145145
/// `Err(ParseFloatError)` if the string did not represent a valid
146-
/// number. Otherwise, `Ok(n)` where `n` is the floating-point
147-
/// number represented by `src`.
146+
/// number. Otherwise, `Ok(n)` where `n` is the closest
147+
/// representable floating-point number to the number represented
148+
/// by `src` (following the same rules for rounding as for the
149+
/// results of primitive operations).
148150
#[inline]
149151
fn from_str(src: &str) -> Result<Self, ParseFloatError> {
150152
dec2flt(src)

core/src/primitive_docs.rs

+13
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,19 @@ mod prim_tuple {}
994994
/// surprising results upon inspecting the bit patterns,
995995
/// as the same calculations might produce NaNs with different bit patterns.
996996
///
997+
/// When the number resulting from a primitive operation (addition,
998+
/// subtraction, multiplication, or division) on this type is not exactly
999+
/// representable as `f32`, it is rounded according to the roundTiesToEven
1000+
/// direction defined in IEEE 754-2008. That means:
1001+
///
1002+
/// - The result is the representable value closest to the true value, if there
1003+
/// is a unique closest representable value.
1004+
/// - If the true value is exactly half-way between two representable values,
1005+
/// the result is the one with an even least-significant binary digit.
1006+
/// - If the true value's magnitude is ≥ `f32::MAX` + 2<sup>(`f32::MAX_EXP` −
1007+
/// `f32::MANTISSA_DIGITS` − 1)</sup>, the result is ∞ or −∞ (preserving the
1008+
/// true value's sign).
1009+
///
9971010
/// For more information on floating point numbers, see [Wikipedia][wikipedia].
9981011
///
9991012
/// *[See also the `std::f32::consts` module](crate::f32::consts).*

std/src/primitive_docs.rs

+13
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,19 @@ mod prim_tuple {}
994994
/// surprising results upon inspecting the bit patterns,
995995
/// as the same calculations might produce NaNs with different bit patterns.
996996
///
997+
/// When the number resulting from a primitive operation (addition,
998+
/// subtraction, multiplication, or division) on this type is not exactly
999+
/// representable as `f32`, it is rounded according to the roundTiesToEven
1000+
/// direction defined in IEEE 754-2008. That means:
1001+
///
1002+
/// - The result is the representable value closest to the true value, if there
1003+
/// is a unique closest representable value.
1004+
/// - If the true value is exactly half-way between two representable values,
1005+
/// the result is the one with an even least-significant binary digit.
1006+
/// - If the true value's magnitude is ≥ `f32::MAX` + 2<sup>(`f32::MAX_EXP` −
1007+
/// `f32::MANTISSA_DIGITS` − 1)</sup>, the result is ∞ or −∞ (preserving the
1008+
/// true value's sign).
1009+
///
9971010
/// For more information on floating point numbers, see [Wikipedia][wikipedia].
9981011
///
9991012
/// *[See also the `std::f32::consts` module](crate::f32::consts).*

0 commit comments

Comments
 (0)