2012-12-13 15:05:22 -06:00
|
|
|
// xfail-fast
|
|
|
|
|
2012-12-10 19:32:48 -06: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 14:34:30 -06:00
|
|
|
// A more complex example of numeric extensions
|
|
|
|
|
2013-05-20 19:07:24 -05:00
|
|
|
extern mod extra;
|
2013-03-26 23:17:29 -05:00
|
|
|
|
2013-05-20 19:07:24 -05:00
|
|
|
use std::cmp::{Eq, Ord};
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
pub trait TypeExt {}
|
|
|
|
|
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl TypeExt for u8 {}
|
|
|
|
impl TypeExt for u16 {}
|
|
|
|
impl TypeExt for u32 {}
|
|
|
|
impl TypeExt for u64 {}
|
|
|
|
impl TypeExt for uint {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl TypeExt for i8 {}
|
|
|
|
impl TypeExt for i16 {}
|
|
|
|
impl TypeExt for i32 {}
|
|
|
|
impl TypeExt for i64 {}
|
|
|
|
impl TypeExt for int {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl TypeExt for f32 {}
|
|
|
|
impl TypeExt for f64 {}
|
|
|
|
impl TypeExt for float {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
2013-04-13 11:19:35 -05:00
|
|
|
pub trait NumExt: TypeExt + Eq + Ord + Num + NumCast {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl NumExt for u8 {}
|
|
|
|
impl NumExt for u16 {}
|
|
|
|
impl NumExt for u32 {}
|
|
|
|
impl NumExt for u64 {}
|
|
|
|
impl NumExt for uint {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl NumExt for i8 {}
|
|
|
|
impl NumExt for i16 {}
|
|
|
|
impl NumExt for i32 {}
|
|
|
|
impl NumExt for i64 {}
|
|
|
|
impl NumExt for int {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl NumExt for f32 {}
|
|
|
|
impl NumExt for f64 {}
|
|
|
|
impl NumExt for float {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
pub trait UnSignedExt: NumExt {}
|
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl UnSignedExt for u8 {}
|
|
|
|
impl UnSignedExt for u16 {}
|
|
|
|
impl UnSignedExt for u32 {}
|
|
|
|
impl UnSignedExt for u64 {}
|
|
|
|
impl UnSignedExt for uint {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
pub trait SignedExt: NumExt {}
|
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl SignedExt for i8 {}
|
|
|
|
impl SignedExt for i16 {}
|
|
|
|
impl SignedExt for i32 {}
|
|
|
|
impl SignedExt for i64 {}
|
|
|
|
impl SignedExt for int {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl SignedExt for f32 {}
|
|
|
|
impl SignedExt for f64 {}
|
|
|
|
impl SignedExt for float {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
pub trait IntegerExt: NumExt {}
|
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl IntegerExt for u8 {}
|
|
|
|
impl IntegerExt for u16 {}
|
|
|
|
impl IntegerExt for u32 {}
|
|
|
|
impl IntegerExt for u64 {}
|
|
|
|
impl IntegerExt for uint {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl IntegerExt for i8 {}
|
|
|
|
impl IntegerExt for i16 {}
|
|
|
|
impl IntegerExt for i32 {}
|
|
|
|
impl IntegerExt for i64 {}
|
|
|
|
impl IntegerExt for int {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
2013-05-06 01:10:26 -05:00
|
|
|
pub trait FloatExt: NumExt + ApproxEq<Self> {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl FloatExt for f32 {}
|
|
|
|
impl FloatExt for f64 {}
|
|
|
|
impl FloatExt for float {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
2013-07-22 11:04:51 -05:00
|
|
|
fn test_float_ext<T:FloatExt>(n: T) { printfln!(n < n) }
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2012-11-28 14:34:30 -06:00
|
|
|
test_float_ext(1f32);
|
2012-12-13 15:05:22 -06:00
|
|
|
}
|