about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-09 17:41:23 -0700
committerbors <bors@rust-lang.org>2013-10-09 17:41:23 -0700
commit8f4b87290bfdaf9f13663539f2969a0567e5b154 (patch)
tree14e3345c8abfdbc5c9835ab0b1afc61ea9498b29 /src/libstd
parent2076959336a1751bccfb24e1b8e0107341bec58a (diff)
parent8ac0d0a59ee47d9f8027955ca13f545f89bcc687 (diff)
downloadrust-8f4b87290bfdaf9f13663539f2969a0567e5b154.tar.gz
rust-8f4b87290bfdaf9f13663539f2969a0567e5b154.zip
auto merge of #9774 : sebcrozet/rust/master, r=huonw
The minimum (negative) value of a float is `-Bounded::max_value()`, not `Bounded::min_value()`.
Otherwise the following has an incorrect behavior:

```rust
let a = -1.0f64;
let b: f32 = NumCast::from(a); // incorrectly returns None
```
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/num/num.rs3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/libstd/num/num.rs b/src/libstd/num/num.rs
index 379e874f862..aacf807a875 100644
--- a/src/libstd/num/num.rs
+++ b/src/libstd/num/num.rs
@@ -567,9 +567,8 @@ macro_rules! impl_to_primitive_float_to_float(
             Some(*self as $DstT)
         } else {
             let n = *self as f64;
-            let min_value: $SrcT = Bounded::min_value();
             let max_value: $SrcT = Bounded::max_value();
-            if min_value as f64 <= n && n <= max_value as f64 {
+            if -max_value as f64 <= n && n <= max_value as f64 {
                 Some(*self as $DstT)
             } else {
                 None