Skip to content

Commit

Permalink
core: updated for the master changes.
Browse files Browse the repository at this point in the history
The master no longer has `std::num::Float`, so a generic `ldexp` is
not readily available. `DecodableFloat::ldexpi` works around this.
  • Loading branch information
lifthrasiir committed May 6, 2015
1 parent 97ea7c1 commit a641b05
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 98 deletions.
5 changes: 5 additions & 0 deletions src/libcore/num/flt2dec/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ pub enum FullDecoded {

/// A floating point type which can be `decode`d.
pub trait DecodableFloat: Float + Copy {
/// Returns `x * 2^exp`. Almost same to `std::{f32,f64}::ldexp`.
/// This is used for testing.
fn ldexpi(f: i64, exp: isize) -> Self;
/// The minimum positive normalized value.
fn min_pos_norm_value() -> Self;
}

impl DecodableFloat for f32 {
fn ldexpi(f: i64, exp: isize) -> Self { f as Self * (exp as Self).exp2() }
fn min_pos_norm_value() -> Self { f32::MIN_POSITIVE }
}

impl DecodableFloat for f64 {
fn ldexpi(f: i64, exp: isize) -> Self { f as Self * (exp as Self).exp2() }
fn min_pos_norm_value() -> Self { f64::MIN_POSITIVE }
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcoretest/num/flt2dec/estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::num::Float;
use std::f64;
use core::num::flt2dec::estimator::*;

#[test]
Expand Down Expand Up @@ -54,7 +54,7 @@ fn test_estimate_scaling_factor() {
assert_almost_eq!(estimate_scaling_factor(0x1fffffffffffff, 971), 309);

for i in -1074..972 {
let expected = Float::ldexp(1.0, i).log10().ceil();
let expected = f64::ldexp(1.0, i).log10().ceil();
assert_almost_eq!(estimate_scaling_factor(1, i as i16), expected as i16);
}
}
Expand Down
Loading

0 comments on commit a641b05

Please sign in to comment.