2012-12-13 13:05:22 -08:00
|
|
|
// xfail-fast
|
|
|
|
|
2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2012-11-28 12:34:30 -08:00
|
|
|
// A more complex example of numeric extensions
|
|
|
|
|
|
|
|
use cmp::{Eq, Ord};
|
2013-02-11 12:33:05 +11:00
|
|
|
use num::NumCast::from;
|
2012-11-28 12:34:30 -08:00
|
|
|
|
|
|
|
extern mod std;
|
|
|
|
use std::cmp::FuzzyEq;
|
|
|
|
|
|
|
|
pub trait TypeExt {}
|
|
|
|
|
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl TypeExt for u8 {}
|
|
|
|
pub impl TypeExt for u16 {}
|
|
|
|
pub impl TypeExt for u32 {}
|
|
|
|
pub impl TypeExt for u64 {}
|
|
|
|
pub impl TypeExt for uint {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl TypeExt for i8 {}
|
|
|
|
pub impl TypeExt for i16 {}
|
|
|
|
pub impl TypeExt for i32 {}
|
|
|
|
pub impl TypeExt for i64 {}
|
|
|
|
pub impl TypeExt for int {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl TypeExt for f32 {}
|
|
|
|
pub impl TypeExt for f64 {}
|
|
|
|
pub impl TypeExt for float {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
|
|
|
|
2013-02-12 17:07:26 -08:00
|
|
|
pub trait NumExt: TypeExt Eq Ord NumCast {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl NumExt for u8 {}
|
|
|
|
pub impl NumExt for u16 {}
|
|
|
|
pub impl NumExt for u32 {}
|
|
|
|
pub impl NumExt for u64 {}
|
|
|
|
pub impl NumExt for uint {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl NumExt for i8 {}
|
|
|
|
pub impl NumExt for i16 {}
|
|
|
|
pub impl NumExt for i32 {}
|
|
|
|
pub impl NumExt for i64 {}
|
|
|
|
pub impl NumExt for int {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl NumExt for f32 {}
|
|
|
|
pub impl NumExt for f64 {}
|
|
|
|
pub impl NumExt for float {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
pub trait UnSignedExt: NumExt {}
|
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl UnSignedExt for u8 {}
|
|
|
|
pub impl UnSignedExt for u16 {}
|
|
|
|
pub impl UnSignedExt for u32 {}
|
|
|
|
pub impl UnSignedExt for u64 {}
|
|
|
|
pub impl UnSignedExt for uint {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
pub trait SignedExt: NumExt {}
|
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl SignedExt for i8 {}
|
|
|
|
pub impl SignedExt for i16 {}
|
|
|
|
pub impl SignedExt for i32 {}
|
|
|
|
pub impl SignedExt for i64 {}
|
|
|
|
pub impl SignedExt for int {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl SignedExt for f32 {}
|
|
|
|
pub impl SignedExt for f64 {}
|
|
|
|
pub impl SignedExt for float {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
pub trait IntegerExt: NumExt {}
|
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl IntegerExt for u8 {}
|
|
|
|
pub impl IntegerExt for u16 {}
|
|
|
|
pub impl IntegerExt for u32 {}
|
|
|
|
pub impl IntegerExt for u64 {}
|
|
|
|
pub impl IntegerExt for uint {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl IntegerExt for i8 {}
|
|
|
|
pub impl IntegerExt for i16 {}
|
|
|
|
pub impl IntegerExt for i32 {}
|
|
|
|
pub impl IntegerExt for i64 {}
|
|
|
|
pub impl IntegerExt for int {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
|
|
|
|
2013-02-08 02:41:23 +11:00
|
|
|
pub trait FloatExt: NumExt FuzzyEq<Self> {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
2013-02-14 21:17:26 -08:00
|
|
|
pub impl FloatExt for f32 {}
|
|
|
|
pub impl FloatExt for f64 {}
|
|
|
|
pub impl FloatExt for float {}
|
2012-11-28 12:34:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
fn test_float_ext<T:FloatExt>(n: T) { io::println(fmt!("%?", n < n)) }
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2012-11-28 12:34:30 -08:00
|
|
|
test_float_ext(1f32);
|
2012-12-13 13:05:22 -08:00
|
|
|
}
|