libcore: Move the numeric operations out of Num. r=brson
Sadly I could not use trait inheritance due to a type parameter substitution bug.
This commit is contained in:
parent
6efa3543a8
commit
216e85fadf
15 changed files with 165 additions and 118 deletions
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern: binary operation + cannot be applied to type
|
||||
// error-pattern: mismatched types
|
||||
type clam = {x: @int, y: @int};
|
||||
|
||||
type fish = {a: @int};
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pure fn Matrix4<T:Copy Num>(m11: T, m12: T, m13: T, m14: T,
|
||||
m21: T, m22: T, m23: T, m24: T,
|
||||
m31: T, m32: T, m33: T, m34: T,
|
||||
m41: T, m42: T, m43: T, m44: T)
|
||||
-> Matrix4<T> {
|
||||
pure fn Matrix4<T:Copy>(m11: T, m12: T, m13: T, m14: T,
|
||||
m21: T, m22: T, m23: T, m24: T,
|
||||
m31: T, m32: T, m33: T, m34: T,
|
||||
m41: T, m42: T, m43: T, m44: T)
|
||||
-> Matrix4<T> {
|
||||
|
||||
Matrix4 {
|
||||
m11: m11, m12: m12, m13: m13, m14: m14,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use num::NumCast::from;
|
|||
extern mod std;
|
||||
use std::cmp::FuzzyEq;
|
||||
|
||||
pub trait NumExt: Num NumCast Eq Ord {}
|
||||
pub trait NumExt: NumCast Eq Ord {}
|
||||
|
||||
pub trait FloatExt: NumExt FuzzyEq<Self> {}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Using the real Num from core
|
||||
|
||||
use cmp::Ord;
|
||||
use num::NumCast::from;
|
||||
|
||||
pub trait NumExt: Num NumCast Ord { }
|
||||
pub trait NumExt: NumCast Ord { }
|
||||
|
||||
fn greater_than_one<T:NumExt>(n: &T) -> bool {
|
||||
*n > from(1)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ pub impl f64: TypeExt {}
|
|||
pub impl float: TypeExt {}
|
||||
|
||||
|
||||
pub trait NumExt: TypeExt Eq Ord Num NumCast {}
|
||||
pub trait NumExt: TypeExt Eq Ord NumCast {}
|
||||
|
||||
pub impl u8: NumExt {}
|
||||
pub impl u16: NumExt {}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
use cmp::{Eq, Ord};
|
||||
use num::NumCast::from;
|
||||
|
||||
pub trait NumExt: Eq Ord Num NumCast {}
|
||||
pub trait NumExt: Eq Ord NumCast {}
|
||||
|
||||
pub impl f32: NumExt {}
|
||||
|
||||
|
|
@ -19,4 +19,4 @@ 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
use cmp::{Eq, Ord};
|
||||
use num::NumCast::from;
|
||||
|
||||
pub trait NumExt: Eq Num NumCast {}
|
||||
pub trait NumExt: Eq NumCast {}
|
||||
|
||||
pub impl f32: NumExt {}
|
||||
pub impl int: NumExt {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue