1
Fork 0

Add NumCast trait for generic numeric type casts

This commit is contained in:
Brendan Zabarauskas 2013-02-11 12:33:05 +11:00
parent 0f04df8522
commit 48b2141b83
24 changed files with 1041 additions and 88 deletions

View file

@ -9,13 +9,13 @@
// except according to those terms.
use cmp::{Eq, Ord};
use num::Num::from_int;
use num::NumCast::from;
pub trait NumExt: Eq Ord Num {}
pub trait NumExt: Eq Ord Num NumCast {}
pub impl f32: NumExt {}
fn num_eq_one<T:NumExt>(n: T) { io::println(fmt!("%?", n == from_int(1))) }
fn num_eq_one<T:NumExt>(n: T) { io::println(fmt!("%?", n == from(1))) }
pub fn main() {
num_eq_one(1f32); // you need to actually use the function to trigger the ICE