File tree 1 file changed +26
-2
lines changed
library/core/src/iter/traits
1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -2602,6 +2602,18 @@ pub trait Iterator {
2602
2602
/// If several elements are equally maximum, the last element is
2603
2603
/// returned. If the iterator is empty, [`None`] is returned.
2604
2604
///
2605
+ /// Note that [`f32`]/[`f64`] doesn't implement [`Ord`] due to NaN being
2606
+ /// incomparable. You can work around this by using [`Iterator::reduce`]:
2607
+ /// ```
2608
+ /// assert_eq!(
2609
+ /// vec![2.4, f32::NAN, 1.3]
2610
+ /// .into_iter()
2611
+ /// .reduce(|a, b| f32::max(a, b))
2612
+ /// .unwrap(),
2613
+ /// 2.4
2614
+ /// );
2615
+ /// ```
2616
+ ///
2605
2617
/// # Examples
2606
2618
///
2607
2619
/// Basic usage:
@@ -2625,8 +2637,20 @@ pub trait Iterator {
2625
2637
2626
2638
/// Returns the minimum element of an iterator.
2627
2639
///
2628
- /// If several elements are equally minimum, the first element is
2629
- /// returned. If the iterator is empty, [`None`] is returned.
2640
+ /// If several elements are equally minimum, the first element is returned.
2641
+ /// If the iterator is empty, [`None`] is returned.
2642
+ ///
2643
+ /// Note that [`f32`]/[`f64`] doesn't implement [`Ord`] due to NaN being
2644
+ /// incomparable. You can work around this by using [`Iterator::reduce`]:
2645
+ /// ```
2646
+ /// assert_eq!(
2647
+ /// vec![2.4, f32::NAN, 1.3]
2648
+ /// .into_iter()
2649
+ /// .reduce(|a, b| f32::min(a, b))
2650
+ /// .unwrap(),
2651
+ /// 1.3
2652
+ /// );
2653
+ /// ```
2630
2654
///
2631
2655
/// # Examples
2632
2656
///
You can’t perform that action at this time.
0 commit comments