rust/src/libcore
Dylan DPC c09f0eb3eb
Rollup merge of #72568 - golddranks:add_total_cmp_to_floats, r=sfackler
Implement total_cmp for f32, f64

# Overview
* Implements method `total_cmp` on `f32` and `f64`. This method implements a float comparison that, unlike the standard `partial_cmp`, is total (defined on all values) in accordance to the IEEE 754 (rev 2008) §5.10 `totalOrder` predicate.
* The method has an API similar to `cmp`: `pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering { ... }`.
* Implements tests.
* Has documentation.

# Justification for the API
* Total ordering for `f32` and `f64` has been discussed many time before:
  * https://internals.rust-lang.org/t/pre-pre-rfc-range-restricting-wrappers-for-floating-point-types/6701
  * https://github.com/rust-lang/rfcs/issues/1249
  * https://github.com/rust-lang/rust/pull/53938
  * https://github.com/rust-lang/rust/issues/5585
* The lack of total ordering leads to frequent complaints, especially from people new to Rust.
  * This is an ergonomics issue that needs to be addressed.
  * However, the default behaviour of implementing only `PartialOrd` is intentional, as relaxing it might lead to correctness issues.
* Most earlier implementations and discussions have been focusing on a wrapper type that implements trait `Ord`. Such a wrapper type is, however not easy to add because of the large API surface added.
* As a minimal step that hopefully proves uncontroversial, we can implement a stand-alone method `total_cmp` on floating point types.
  * I expect adding such methods should be uncontroversial because...
    * Similar methods on `f32` and `f64` would be warranted even in case stdlib would provide a wrapper type that implements `Ord` some day.
    * It implements functionality that is standardised. (IEEE 754, 2008 rev. §5.10 Note, that the 2019 revision relaxes the ordering. The way we do ordering in this method conforms to the stricter 2008 standard.)
* With stdlib APIs such as `slice::sort_by` and `slice::binary_search_by` that allow users to provide a custom ordering criterion, providing additional helper methods is a minimal way of adding ordering functionality.
  * Not also does it allow easily using aforementioned APIs, it also provides an easy and well-tested primitive for the users and library authors to implement an `Ord`-implementing wrapper, if needed.
2020-05-29 20:21:18 +02:00
..
alloc Rollup merge of #71492 - LeSeulArtichaut:document-unsafe-2, r=Mark-Simulacrum 2020-04-24 02:47:38 +02:00
array Add comment for Ord implementation for array 2020-05-06 17:02:53 +08:00
benches Use assoc float consts in libcore 2020-04-06 22:44:51 +02:00
char Rollup merge of #72371 - Elrendio:char_documentation, r=steveklabnik 2020-05-21 13:12:22 +02:00
convert Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
fmt Rollup merge of #72452 - Lucretiel:precision-doc, r=dtolnay 2020-05-29 15:06:59 +09:00
future Add core::future::IntoFuture 2020-05-22 10:55:01 +02:00
hash Add a note about fat pointers 2020-04-23 23:05:37 +02:00
iter Rollup merge of #72310 - jyn514:peekable-next-if, r=dtolnay 2020-05-29 20:21:11 +02:00
macros Auto merge of #69171 - Amanieu:new-asm, r=nagisa,nikomatsakis 2020-05-19 18:32:40 +00:00
mem add warning sign to UB examples 2020-05-23 14:00:55 +02:00
num Add tracing issue for total_cmp 2020-05-26 11:59:23 +09:00
ops only try to suggest for try trait_ref 2020-05-22 10:11:52 +08:00
prelude Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
ptr Apply suggestions from code review 2020-05-18 21:29:43 +02:00
slice Use sort_unstable_by in its own docs 2020-05-24 14:56:57 +02:00
str Stabilize str_strip feature 2020-05-22 15:29:47 +00:00
sync Rollup merge of #72324 - Amanieu:atomic_minmax, r=dtolnay 2020-05-29 15:06:57 +09:00
task Use matches macro in libcore and libstd 2020-01-08 07:10:28 +03:00
tests Rollup merge of #72310 - jyn514:peekable-next-if, r=dtolnay 2020-05-29 20:21:11 +02:00
unicode Stabilize UNICODE_VERSION (feature unicode_version) 2020-04-23 14:36:30 +02:00
any.rs Map to -> return. 2020-05-12 16:54:29 +01:00
ascii.rs Format libcore with rustfmt 2019-11-26 23:02:11 -08:00
bool.rs Format libcore with rustfmt (including tests and benches) 2019-12-06 20:20:51 -08:00
borrow.rs Format the world 2019-12-22 17:42:47 -05:00
Cargo.toml Move the matches! macro to the prelude 2019-10-23 15:35:36 +02:00
cell.rs Rollup merge of #72606 - GuillaumeGomez:cell-example-update, r=Dylan-DPC 2020-05-27 03:09:19 +02:00
clone.rs Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
cmp.rs Fix doc link to Eq trait from PartialEq trait 2020-04-29 12:06:32 -04:00
default.rs Fix typo in Default trait docs: Provides -> Provide 2020-04-16 22:39:00 +01:00
ffi.rs Make VaList::arg link actually work 2020-04-23 11:06:46 -04:00
hint.rs Document unsafety in core::{panicking, alloc::layout, hint, iter::adapters::zip} 2020-04-24 01:48:48 +02:00
internal_macros.rs Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
intrinsics.rs update libcore, add discriminant_kind lang-item 2020-05-19 10:12:35 +02:00
lib.rs Add len and slice_from_raw_parts to NonNull<[T]> 2020-05-18 21:29:43 +02:00
marker.rs update libcore, add discriminant_kind lang-item 2020-05-19 10:12:35 +02:00
option.rs Update src/libcore/option.rs 2020-05-13 21:13:35 +08:00
panic.rs document stable counterparts of intrinsics 2020-04-29 15:50:21 +02:00
panicking.rs make abort intrinsic safe, and correct its documentation 2020-05-17 11:23:42 +02:00
pin.rs clarify interaction of pin drop guarantee and panics 2020-04-27 14:45:37 +02:00
primitive.rs Bump core::primitive to 1.43 2020-02-23 23:59:39 -08:00
raw.rs Use dyn trait syntax in more comments and docs 2020-05-24 14:46:50 +03:00
result.rs docs: make the description of Result::map_or more clear 2020-04-04 14:18:02 +03:00
time.rs Stop accessing module level int consts via crate::<Ty> 2020-04-20 23:38:06 +02:00
tuple.rs Format libcore with rustfmt 2019-11-26 23:02:11 -08:00
unit.rs Format libcore with rustfmt 2019-11-26 23:02:11 -08:00