Skip to content

Commit 36b492a

Browse files
committed
Merge #315
315: Fix float NaN positive/negative assumptions r=cuviper These are the minimal assumptions to make about `NaN`. Fixes part of #312 (but not the `next` branch).
2 parents 31fa9f6 + 426034b commit 36b492a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

traits/src/float.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,41 +323,39 @@ pub trait Float
323323
/// ```
324324
fn signum(self) -> Self;
325325

326-
/// Returns `true` if `self` is positive, including `+0.0` and
327-
/// `Float::infinity()`.
326+
/// Returns `true` if `self` is positive, including `+0.0`,
327+
/// `Float::infinity()`, and with newer versions of Rust `f64::NAN`.
328328
///
329329
/// ```
330330
/// use num_traits::Float;
331331
/// use std::f64;
332332
///
333-
/// let nan: f64 = f64::NAN;
333+
/// let neg_nan: f64 = -f64::NAN;
334334
///
335335
/// let f = 7.0;
336336
/// let g = -7.0;
337337
///
338338
/// assert!(f.is_sign_positive());
339339
/// assert!(!g.is_sign_positive());
340-
/// // Requires both tests to determine if is `NaN`
341-
/// assert!(!nan.is_sign_positive() && !nan.is_sign_negative());
340+
/// assert!(!neg_nan.is_sign_positive());
342341
/// ```
343342
fn is_sign_positive(self) -> bool;
344343

345-
/// Returns `true` if `self` is negative, including `-0.0` and
346-
/// `Float::neg_infinity()`.
344+
/// Returns `true` if `self` is negative, including `-0.0`,
345+
/// `Float::neg_infinity()`, and with newer versions of Rust `-f64::NAN`.
347346
///
348347
/// ```
349348
/// use num_traits::Float;
350349
/// use std::f64;
351350
///
352-
/// let nan = f64::NAN;
351+
/// let nan: f64 = f64::NAN;
353352
///
354353
/// let f = 7.0;
355354
/// let g = -7.0;
356355
///
357356
/// assert!(!f.is_sign_negative());
358357
/// assert!(g.is_sign_negative());
359-
/// // Requires both tests to determine if is `NaN`.
360-
/// assert!(!nan.is_sign_positive() && !nan.is_sign_negative());
358+
/// assert!(!nan.is_sign_negative());
361359
/// ```
362360
fn is_sign_negative(self) -> bool;
363361

0 commit comments

Comments
 (0)