From 6fdb8d8b360b91a10045fe74467b98d218b7ffe9 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 31 Oct 2020 17:21:23 -0700 Subject: Update signed fmt/-0f32 docs "semantic equivalence" is too strong a phrasing here, which is why actually explaining what kind of circumstances might produce a -0 was chosen instead. --- library/std/src/primitive_docs.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'library/std/src') diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index d4bb2083d00..b48718df31c 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -805,10 +805,12 @@ mod prim_tuple {} /// often discard insignificant digits: `println!("{}", 1.0f32 / 5.0f32)` will /// print `0.2`. /// -/// Additionally, `f32` can represent a couple of special values: +/// Additionally, `f32` can represent some special values: /// -/// - `-0`: this is just due to how floats are encoded. It is semantically -/// equivalent to `0` and `-0.0 == 0.0` results in `true`. +/// - `-0`: this value exists due to how floats are encoded. -0 == 0 is true, but for other +/// operations they are not equal and the difference can be useful to certain algorithms. +/// For example, operations on negative numbers that underflow to 0 will usually generate -0 +/// instead of +0. /// - [∞](#associatedconstant.INFINITY) and /// [−∞](#associatedconstant.NEG_INFINITY): these result from calculations /// like `1.0 / 0.0`. -- cgit 1.4.1-3-g733a5 From e8dfbaca76616a32cabba30ec343cd4fcb28bda9 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 1 Nov 2020 10:31:08 -0800 Subject: Rephrase -0.0 docs --- library/std/src/primitive_docs.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'library/std/src') diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index b48718df31c..64b22b64f4b 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -807,10 +807,10 @@ mod prim_tuple {} /// /// Additionally, `f32` can represent some special values: /// -/// - `-0`: this value exists due to how floats are encoded. -0 == 0 is true, but for other -/// operations they are not equal and the difference can be useful to certain algorithms. -/// For example, operations on negative numbers that underflow to 0 will usually generate -0 -/// instead of +0. +/// - -0.0: IEEE 754 floating point numbers have a bit that indicates their sign, so -0.0 is a +/// possible value. For comparison `-0.0 == +0.0` is true but floating point operations can +/// carry the sign bit through arithmetic operations. This means `-1.0 * 0.0` produces -0.0 and +/// a negative number rounded to a value smaller than a float can represent also produces -0.0. /// - [∞](#associatedconstant.INFINITY) and /// [−∞](#associatedconstant.NEG_INFINITY): these result from calculations /// like `1.0 / 0.0`. -- cgit 1.4.1-3-g733a5