Merge remote-tracking branch 'mozilla/incoming' into issue-5910-dyna-freeze

This commit is contained in:
Niko Matsakis 2013-05-06 16:10:31 -04:00
commit 2e4790ca06
18 changed files with 403 additions and 363 deletions

View file

@ -0,0 +1,5 @@
#[packed]
struct S {
a: u8,
b: u32
}

View file

@ -0,0 +1,14 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:left: 1.0000001 does not approximately equal right: 1 with epsilon: 0.0000001
pub fn main() {
assert_approx_eq!(1.0000001f, 1.0f, 1.0e-7);
}

View file

@ -0,0 +1,14 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:left: 1.00001 does not approximately equal right: 1
pub fn main() {
assert_approx_eq!(1.00001f, 1.0f);
}

View file

@ -0,0 +1,16 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub fn main() {
assert_approx_eq!(1.0f, 1.0f);
assert_approx_eq!(1.0000001f, 1.0f);
assert_approx_eq!(1.0000001f, 1.0f, 1.0e-6);
assert_approx_eq!(1.000001f, 1.0f, 1.0e-5);
}

View file

@ -10,10 +10,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern mod std;
use std::cmp::FuzzyEq;
mod rusti {
#[abi = "rust-intrinsic"]
pub extern "rust-intrinsic" {
@ -54,44 +50,44 @@ pub fn main() {
unsafe {
use rusti::*;
assert!((sqrtf32(64f32).fuzzy_eq(&8f32)));
assert!((sqrtf64(64f64).fuzzy_eq(&8f64)));
assert!((sqrtf32(64f32).approx_eq(&8f32)));
assert!((sqrtf64(64f64).approx_eq(&8f64)));
assert!((powif32(25f32, -2i32).fuzzy_eq(&0.0016f32)));
assert!((powif64(23.2f64, 2i32).fuzzy_eq(&538.24f64)));
assert!((powif32(25f32, -2i32).approx_eq(&0.0016f32)));
assert!((powif64(23.2f64, 2i32).approx_eq(&538.24f64)));
assert!((sinf32(0f32).fuzzy_eq(&0f32)));
assert!((sinf64(f64::consts::pi / 2f64).fuzzy_eq(&1f64)));
assert!((sinf32(0f32).approx_eq(&0f32)));
assert!((sinf64(f64::consts::pi / 2f64).approx_eq(&1f64)));
assert!((cosf32(0f32).fuzzy_eq(&1f32)));
assert!((cosf64(f64::consts::pi * 2f64).fuzzy_eq(&1f64)));
assert!((cosf32(0f32).approx_eq(&1f32)));
assert!((cosf64(f64::consts::pi * 2f64).approx_eq(&1f64)));
assert!((powf32(25f32, -2f32).fuzzy_eq(&0.0016f32)));
assert!((powf64(400f64, 0.5f64).fuzzy_eq(&20f64)));
assert!((powf32(25f32, -2f32).approx_eq(&0.0016f32)));
assert!((powf64(400f64, 0.5f64).approx_eq(&20f64)));
assert!((fabsf32(expf32(1f32) - f32::consts::e).fuzzy_eq(&0f32)));
assert!((expf64(1f64).fuzzy_eq(&f64::consts::e)));
assert!((fabsf32(expf32(1f32) - f32::consts::e).approx_eq(&0f32)));
assert!((expf64(1f64).approx_eq(&f64::consts::e)));
assert!((exp2f32(10f32).fuzzy_eq(&1024f32)));
assert!((exp2f64(50f64).fuzzy_eq(&1125899906842624f64)));
assert!((exp2f32(10f32).approx_eq(&1024f32)));
assert!((exp2f64(50f64).approx_eq(&1125899906842624f64)));
assert!((fabsf32(logf32(f32::consts::e) - 1f32).fuzzy_eq(&0f32)));
assert!((logf64(1f64).fuzzy_eq(&0f64)));
assert!((fabsf32(logf32(f32::consts::e) - 1f32).approx_eq(&0f32)));
assert!((logf64(1f64).approx_eq(&0f64)));
assert!((log10f32(10f32).fuzzy_eq(&1f32)));
assert!((log10f64(f64::consts::e).fuzzy_eq(&f64::consts::log10_e)));
assert!((log10f32(10f32).approx_eq(&1f32)));
assert!((log10f64(f64::consts::e).approx_eq(&f64::consts::log10_e)));
assert!((log2f32(8f32).fuzzy_eq(&3f32)));
assert!((log2f64(f64::consts::e).fuzzy_eq(&f64::consts::log2_e)));
assert!((log2f32(8f32).approx_eq(&3f32)));
assert!((log2f64(f64::consts::e).approx_eq(&f64::consts::log2_e)));
assert!((fmaf32(1.0f32, 2.0f32, 5.0f32).fuzzy_eq(&7.0f32)));
assert!((fmaf64(0.0f64, -2.0f64, f64::consts::e).fuzzy_eq(&f64::consts::e)));
assert!((fmaf32(1.0f32, 2.0f32, 5.0f32).approx_eq(&7.0f32)));
assert!((fmaf64(0.0f64, -2.0f64, f64::consts::e).approx_eq(&f64::consts::e)));
assert!((fabsf32(-1.0f32).fuzzy_eq(&1.0f32)));
assert!((fabsf64(34.2f64).fuzzy_eq(&34.2f64)));
assert!((fabsf32(-1.0f32).approx_eq(&1.0f32)));
assert!((fabsf64(34.2f64).approx_eq(&34.2f64)));
assert!((floorf32(3.8f32).fuzzy_eq(&3.0f32)));
assert!((floorf64(-1.1f64).fuzzy_eq(&-2.0f64)));
assert!((floorf32(3.8f32).approx_eq(&3.0f32)));
assert!((floorf64(-1.1f64).approx_eq(&-2.0f64)));
// Causes linker error
// undefined reference to llvm.ceil.f32/64

View file

@ -0,0 +1,8 @@
// xfail-fast
// aux-build:packed.rs
extern mod packed;
fn main() {
assert_eq!(sys::size_of::<packed::S>(), 5);
}

View file

@ -14,11 +14,10 @@ extern mod std;
use core::cmp::{Eq, Ord};
use core::num::NumCast::from;
use std::cmp::FuzzyEq;
pub trait NumExt: Num + NumCast + Eq + Ord {}
pub trait FloatExt: NumExt + FuzzyEq<Self> {}
pub trait FloatExt: NumExt + ApproxEq<Self> {}
fn greater_than_one<T:NumExt>(n: &T) -> bool { *n > from(1) }
fn greater_than_one_float<T:FloatExt>(n: &T) -> bool { *n > from(1) }

View file

@ -16,7 +16,6 @@ extern mod std;
use core::cmp::{Eq, Ord};
use core::num::NumCast::from;
use std::cmp::FuzzyEq;
pub trait TypeExt {}
@ -94,7 +93,7 @@ impl IntegerExt for i64 {}
impl IntegerExt for int {}
pub trait FloatExt: NumExt + FuzzyEq<Self> {}
pub trait FloatExt: NumExt + ApproxEq<Self> {}
impl FloatExt for f32 {}
impl FloatExt for f64 {}