libcore: Partially de-export char, f32, f64, and float

This commit is contained in:
Patrick Walton 2012-09-26 18:16:44 -07:00
parent dd80cb22e3
commit a08919a522
4 changed files with 135 additions and 143 deletions

View File

@ -47,9 +47,9 @@ export is_alphabetic,
to_digit, cmp,
escape_default, escape_unicode;
use is_alphabetic = unicode::derived_property::Alphabetic;
use is_XID_start = unicode::derived_property::XID_Start;
use is_XID_continue = unicode::derived_property::XID_Continue;
pub use is_alphabetic = unicode::derived_property::Alphabetic;
pub use is_XID_start = unicode::derived_property::XID_Start;
pub use is_XID_continue = unicode::derived_property::XID_Continue;
/**

View File

@ -6,8 +6,8 @@
// PORT
use cmath::c_float::*;
use cmath::c_float_targ_consts::*;
pub use cmath::c_float::*;
pub use cmath::c_float_targ_consts::*;
export add, sub, mul, div, rem, lt, le, eq, ne, ge, gt;
export is_positive, is_negative, is_nonpositive, is_nonnegative;
@ -22,50 +22,48 @@ export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
export signbit;
export num;
// These are not defined inside consts:: for consistency with
// the integer types
const NaN: f32 = 0.0_f32/0.0_f32;
pub const NaN: f32 = 0.0_f32/0.0_f32;
const infinity: f32 = 1.0_f32/0.0_f32;
pub const infinity: f32 = 1.0_f32/0.0_f32;
const neg_infinity: f32 = -1.0_f32/0.0_f32;
pub const neg_infinity: f32 = -1.0_f32/0.0_f32;
pure fn is_NaN(f: f32) -> bool { f != f }
pub pure fn is_NaN(f: f32) -> bool { f != f }
pure fn add(x: f32, y: f32) -> f32 { return x + y; }
pub pure fn add(x: f32, y: f32) -> f32 { return x + y; }
pure fn sub(x: f32, y: f32) -> f32 { return x - y; }
pub pure fn sub(x: f32, y: f32) -> f32 { return x - y; }
pure fn mul(x: f32, y: f32) -> f32 { return x * y; }
pub pure fn mul(x: f32, y: f32) -> f32 { return x * y; }
pure fn div(x: f32, y: f32) -> f32 { return x / y; }
pub pure fn div(x: f32, y: f32) -> f32 { return x / y; }
pure fn rem(x: f32, y: f32) -> f32 { return x % y; }
pub pure fn rem(x: f32, y: f32) -> f32 { return x % y; }
pure fn lt(x: f32, y: f32) -> bool { return x < y; }
pub pure fn lt(x: f32, y: f32) -> bool { return x < y; }
pure fn le(x: f32, y: f32) -> bool { return x <= y; }
pub pure fn le(x: f32, y: f32) -> bool { return x <= y; }
pure fn eq(x: f32, y: f32) -> bool { return x == y; }
pub pure fn eq(x: f32, y: f32) -> bool { return x == y; }
pure fn ne(x: f32, y: f32) -> bool { return x != y; }
pub pure fn ne(x: f32, y: f32) -> bool { return x != y; }
pure fn ge(x: f32, y: f32) -> bool { return x >= y; }
pub pure fn ge(x: f32, y: f32) -> bool { return x >= y; }
pure fn gt(x: f32, y: f32) -> bool { return x > y; }
pub pure fn gt(x: f32, y: f32) -> bool { return x > y; }
// FIXME (#1999): replace the predicates below with llvm intrinsics or
// calls to the libmath macros in the rust runtime for performance.
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
pure fn is_positive(x: f32) -> bool
pub pure fn is_positive(x: f32) -> bool
{ return x > 0.0f32 || (1.0f32/x) == infinity; }
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
pure fn is_negative(x: f32) -> bool
pub pure fn is_negative(x: f32) -> bool
{ return x < 0.0f32 || (1.0f32/x) == neg_infinity; }
/**
@ -73,7 +71,7 @@ pure fn is_negative(x: f32) -> bool
*
* This is the same as `f32::is_negative`.
*/
pure fn is_nonpositive(x: f32) -> bool {
pub pure fn is_nonpositive(x: f32) -> bool {
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
}
@ -82,78 +80,76 @@ pure fn is_nonpositive(x: f32) -> bool {
*
* This is the same as `f32::is_positive`.)
*/
pure fn is_nonnegative(x: f32) -> bool {
pub pure fn is_nonnegative(x: f32) -> bool {
return x > 0.0f32 || (1.0f32/x) == infinity;
}
/// Returns true if `x` is a zero number (positive or negative zero)
pure fn is_zero(x: f32) -> bool {
pub pure fn is_zero(x: f32) -> bool {
return x == 0.0f32 || x == -0.0f32;
}
/// Returns true if `x`is an infinite number
pure fn is_infinite(x: f32) -> bool {
pub pure fn is_infinite(x: f32) -> bool {
return x == infinity || x == neg_infinity;
}
/// Returns true if `x`is a finite number
pure fn is_finite(x: f32) -> bool {
pub pure fn is_finite(x: f32) -> bool {
return !(is_NaN(x) || is_infinite(x));
}
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify.
/* Module: consts */
mod consts {
#[legacy_exports];
pub mod consts {
// FIXME (requires Issue #1433 to fix): replace with mathematical
// constants from cmath.
/// Archimedes' constant
const pi: f32 = 3.14159265358979323846264338327950288_f32;
pub const pi: f32 = 3.14159265358979323846264338327950288_f32;
/// pi/2.0
const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32;
pub const frac_pi_2: f32 = 1.57079632679489661923132169163975144_f32;
/// pi/4.0
const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32;
pub const frac_pi_4: f32 = 0.785398163397448309615660845819875721_f32;
/// 1.0/pi
const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32;
pub const frac_1_pi: f32 = 0.318309886183790671537767526745028724_f32;
/// 2.0/pi
const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32;
pub const frac_2_pi: f32 = 0.636619772367581343075535053490057448_f32;
/// 2.0/sqrt(pi)
const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32;
pub const frac_2_sqrtpi: f32 = 1.12837916709551257389615890312154517_f32;
/// sqrt(2.0)
const sqrt2: f32 = 1.41421356237309504880168872420969808_f32;
pub const sqrt2: f32 = 1.41421356237309504880168872420969808_f32;
/// 1.0/sqrt(2.0)
const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32;
pub const frac_1_sqrt2: f32 = 0.707106781186547524400844362104849039_f32;
/// Euler's number
const e: f32 = 2.71828182845904523536028747135266250_f32;
pub const e: f32 = 2.71828182845904523536028747135266250_f32;
/// log2(e)
const log2_e: f32 = 1.44269504088896340735992468100189214_f32;
pub const log2_e: f32 = 1.44269504088896340735992468100189214_f32;
/// log10(e)
const log10_e: f32 = 0.434294481903251827651128918916605082_f32;
pub const log10_e: f32 = 0.434294481903251827651128918916605082_f32;
/// ln(2.0)
const ln_2: f32 = 0.693147180559945309417232121458176568_f32;
pub const ln_2: f32 = 0.693147180559945309417232121458176568_f32;
/// ln(10.0)
const ln_10: f32 = 2.30258509299404568401799145468436421_f32;
pub const ln_10: f32 = 2.30258509299404568401799145468436421_f32;
}
pure fn signbit(x: f32) -> int {
pub pure fn signbit(x: f32) -> int {
if is_negative(x) { return 1; } else { return 0; }
}
pure fn logarithm(n: f32, b: f32) -> f32 {
pub pure fn logarithm(n: f32, b: f32) -> f32 {
return log2(n) / log2(b);
}

View File

@ -9,6 +9,9 @@
use cmath::c_double::*;
use cmath::c_double_targ_consts::*;
// These are not defined inside consts:: for consistency with
// the integer types
// Even though this module exports everything defined in it,
// because it contains re-exports, we also have to explicitly
// export locally defined things. That's a bit annoying.
@ -30,69 +33,66 @@ export j0, j1, jn, y0, y1, yn;
export num;
// These are not defined inside consts:: for consistency with
// the integer types
// PORT check per architecture
// FIXME (#1433): obtain these in a different way
const radix: uint = 2u;
pub const radix: uint = 2u;
const mantissa_digits: uint = 53u;
const digits: uint = 15u;
pub const mantissa_digits: uint = 53u;
pub const digits: uint = 15u;
const epsilon: f64 = 2.2204460492503131e-16_f64;
pub const epsilon: f64 = 2.2204460492503131e-16_f64;
const min_value: f64 = 2.2250738585072014e-308_f64;
const max_value: f64 = 1.7976931348623157e+308_f64;
pub const min_value: f64 = 2.2250738585072014e-308_f64;
pub const max_value: f64 = 1.7976931348623157e+308_f64;
const min_exp: int = -1021;
const max_exp: int = 1024;
pub const min_exp: int = -1021;
pub const max_exp: int = 1024;
const min_10_exp: int = -307;
const max_10_exp: int = 308;
pub const min_10_exp: int = -307;
pub const max_10_exp: int = 308;
const NaN: f64 = 0.0_f64/0.0_f64;
pub const NaN: f64 = 0.0_f64/0.0_f64;
const infinity: f64 = 1.0_f64/0.0_f64;
pub const infinity: f64 = 1.0_f64/0.0_f64;
const neg_infinity: f64 = -1.0_f64/0.0_f64;
pub const neg_infinity: f64 = -1.0_f64/0.0_f64;
pure fn is_NaN(f: f64) -> bool { f != f }
pub pure fn is_NaN(f: f64) -> bool { f != f }
pure fn add(x: f64, y: f64) -> f64 { return x + y; }
pub pure fn add(x: f64, y: f64) -> f64 { return x + y; }
pure fn sub(x: f64, y: f64) -> f64 { return x - y; }
pub pure fn sub(x: f64, y: f64) -> f64 { return x - y; }
pure fn mul(x: f64, y: f64) -> f64 { return x * y; }
pub pure fn mul(x: f64, y: f64) -> f64 { return x * y; }
pure fn div(x: f64, y: f64) -> f64 { return x / y; }
pub pure fn div(x: f64, y: f64) -> f64 { return x / y; }
pure fn rem(x: f64, y: f64) -> f64 { return x % y; }
pub pure fn rem(x: f64, y: f64) -> f64 { return x % y; }
pure fn lt(x: f64, y: f64) -> bool { return x < y; }
pub pure fn lt(x: f64, y: f64) -> bool { return x < y; }
pure fn le(x: f64, y: f64) -> bool { return x <= y; }
pub pure fn le(x: f64, y: f64) -> bool { return x <= y; }
pure fn eq(x: f64, y: f64) -> bool { return x == y; }
pub pure fn eq(x: f64, y: f64) -> bool { return x == y; }
pure fn ne(x: f64, y: f64) -> bool { return x != y; }
pub pure fn ne(x: f64, y: f64) -> bool { return x != y; }
pure fn ge(x: f64, y: f64) -> bool { return x >= y; }
pub pure fn ge(x: f64, y: f64) -> bool { return x >= y; }
pure fn gt(x: f64, y: f64) -> bool { return x > y; }
pub pure fn gt(x: f64, y: f64) -> bool { return x > y; }
pure fn sqrt(x: f64) -> f64 {
pub pure fn sqrt(x: f64) -> f64 {
cmath::c_double::sqrt(x as libc::c_double) as f64
}
/// Returns true if `x` is a positive number, including +0.0f640 and +Infinity
pure fn is_positive(x: f64) -> bool
pub pure fn is_positive(x: f64) -> bool
{ return x > 0.0f64 || (1.0f64/x) == infinity; }
/// Returns true if `x` is a negative number, including -0.0f640 and -Infinity
pure fn is_negative(x: f64) -> bool
pub pure fn is_negative(x: f64) -> bool
{ return x < 0.0f64 || (1.0f64/x) == neg_infinity; }
/**
@ -100,7 +100,7 @@ pure fn is_negative(x: f64) -> bool
*
* This is the same as `f64::is_negative`.
*/
pure fn is_nonpositive(x: f64) -> bool {
pub pure fn is_nonpositive(x: f64) -> bool {
return x < 0.0f64 || (1.0f64/x) == neg_infinity;
}
@ -109,78 +109,76 @@ pure fn is_nonpositive(x: f64) -> bool {
*
* This is the same as `f64::positive`.
*/
pure fn is_nonnegative(x: f64) -> bool {
pub pure fn is_nonnegative(x: f64) -> bool {
return x > 0.0f64 || (1.0f64/x) == infinity;
}
/// Returns true if `x` is a zero number (positive or negative zero)
pure fn is_zero(x: f64) -> bool {
pub pure fn is_zero(x: f64) -> bool {
return x == 0.0f64 || x == -0.0f64;
}
/// Returns true if `x`is an infinite number
pure fn is_infinite(x: f64) -> bool {
pub pure fn is_infinite(x: f64) -> bool {
return x == infinity || x == neg_infinity;
}
/// Returns true if `x`is a finite number
pure fn is_finite(x: f64) -> bool {
pub pure fn is_finite(x: f64) -> bool {
return !(is_NaN(x) || is_infinite(x));
}
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
/* Module: consts */
mod consts {
#[legacy_exports];
pub mod consts {
// FIXME (requires Issue #1433 to fix): replace with mathematical
// constants from cmath.
/// Archimedes' constant
const pi: f64 = 3.14159265358979323846264338327950288_f64;
pub const pi: f64 = 3.14159265358979323846264338327950288_f64;
/// pi/2.0
const frac_pi_2: f64 = 1.57079632679489661923132169163975144_f64;
pub const frac_pi_2: f64 = 1.57079632679489661923132169163975144_f64;
/// pi/4.0
const frac_pi_4: f64 = 0.785398163397448309615660845819875721_f64;
pub const frac_pi_4: f64 = 0.785398163397448309615660845819875721_f64;
/// 1.0/pi
const frac_1_pi: f64 = 0.318309886183790671537767526745028724_f64;
pub const frac_1_pi: f64 = 0.318309886183790671537767526745028724_f64;
/// 2.0/pi
const frac_2_pi: f64 = 0.636619772367581343075535053490057448_f64;
pub const frac_2_pi: f64 = 0.636619772367581343075535053490057448_f64;
/// 2.0/sqrt(pi)
const frac_2_sqrtpi: f64 = 1.12837916709551257389615890312154517_f64;
pub const frac_2_sqrtpi: f64 = 1.12837916709551257389615890312154517_f64;
/// sqrt(2.0)
const sqrt2: f64 = 1.41421356237309504880168872420969808_f64;
pub const sqrt2: f64 = 1.41421356237309504880168872420969808_f64;
/// 1.0/sqrt(2.0)
const frac_1_sqrt2: f64 = 0.707106781186547524400844362104849039_f64;
pub const frac_1_sqrt2: f64 = 0.707106781186547524400844362104849039_f64;
/// Euler's number
const e: f64 = 2.71828182845904523536028747135266250_f64;
pub const e: f64 = 2.71828182845904523536028747135266250_f64;
/// log2(e)
const log2_e: f64 = 1.44269504088896340735992468100189214_f64;
pub const log2_e: f64 = 1.44269504088896340735992468100189214_f64;
/// log10(e)
const log10_e: f64 = 0.434294481903251827651128918916605082_f64;
pub const log10_e: f64 = 0.434294481903251827651128918916605082_f64;
/// ln(2.0)
const ln_2: f64 = 0.693147180559945309417232121458176568_f64;
pub const ln_2: f64 = 0.693147180559945309417232121458176568_f64;
/// ln(10.0)
const ln_10: f64 = 2.30258509299404568401799145468436421_f64;
pub const ln_10: f64 = 2.30258509299404568401799145468436421_f64;
}
pure fn signbit(x: f64) -> int {
pub pure fn signbit(x: f64) -> int {
if is_negative(x) { return 1; } else { return 0; }
}
pure fn logarithm(n: f64, b: f64) -> f64 {
pub pure fn logarithm(n: f64, b: f64) -> f64 {
return log2(n) / log2(b);
}

View File

@ -51,49 +51,47 @@ const infinity: float = 1.0/0.0;
const neg_infinity: float = -1.0/0.0;
/* Module: consts */
mod consts {
#[legacy_exports];
pub mod consts {
// FIXME (requires Issue #1433 to fix): replace with mathematical
// constants from cmath.
/// Archimedes' constant
const pi: float = 3.14159265358979323846264338327950288;
pub const pi: float = 3.14159265358979323846264338327950288;
/// pi/2.0
const frac_pi_2: float = 1.57079632679489661923132169163975144;
pub const frac_pi_2: float = 1.57079632679489661923132169163975144;
/// pi/4.0
const frac_pi_4: float = 0.785398163397448309615660845819875721;
pub const frac_pi_4: float = 0.785398163397448309615660845819875721;
/// 1.0/pi
const frac_1_pi: float = 0.318309886183790671537767526745028724;
pub const frac_1_pi: float = 0.318309886183790671537767526745028724;
/// 2.0/pi
const frac_2_pi: float = 0.636619772367581343075535053490057448;
pub const frac_2_pi: float = 0.636619772367581343075535053490057448;
/// 2.0/sqrt(pi)
const frac_2_sqrtpi: float = 1.12837916709551257389615890312154517;
pub const frac_2_sqrtpi: float = 1.12837916709551257389615890312154517;
/// sqrt(2.0)
const sqrt2: float = 1.41421356237309504880168872420969808;
pub const sqrt2: float = 1.41421356237309504880168872420969808;
/// 1.0/sqrt(2.0)
const frac_1_sqrt2: float = 0.707106781186547524400844362104849039;
pub const frac_1_sqrt2: float = 0.707106781186547524400844362104849039;
/// Euler's number
const e: float = 2.71828182845904523536028747135266250;
pub const e: float = 2.71828182845904523536028747135266250;
/// log2(e)
const log2_e: float = 1.44269504088896340735992468100189214;
pub const log2_e: float = 1.44269504088896340735992468100189214;
/// log10(e)
const log10_e: float = 0.434294481903251827651128918916605082;
pub const log10_e: float = 0.434294481903251827651128918916605082;
/// ln(2.0)
const ln_2: float = 0.693147180559945309417232121458176568;
pub const ln_2: float = 0.693147180559945309417232121458176568;
/// ln(10.0)
const ln_10: float = 2.30258509299404568401799145468436421;
pub const ln_10: float = 2.30258509299404568401799145468436421;
}
/**
@ -194,12 +192,12 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
* * num - The float value
* * digits - The number of significant digits
*/
fn to_str_exact(num: float, digits: uint) -> ~str {
pub fn to_str_exact(num: float, digits: uint) -> ~str {
to_str_common(num, digits, true)
}
#[test]
fn test_to_str_exact_do_decimal() {
pub fn test_to_str_exact_do_decimal() {
let s = to_str_exact(5.0, 4u);
assert s == ~"5.0000";
}
@ -214,7 +212,7 @@ fn test_to_str_exact_do_decimal() {
* * num - The float value
* * digits - The number of significant digits
*/
fn to_str(num: float, digits: uint) -> ~str {
pub fn to_str(num: float, digits: uint) -> ~str {
to_str_common(num, digits, false)
}
@ -244,7 +242,7 @@ fn to_str(num: float, digits: uint) -> ~str {
* `none` if the string did not represent a valid number. Otherwise,
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
*/
fn from_str(num: &str) -> Option<float> {
pub fn from_str(num: &str) -> Option<float> {
if num == "inf" {
return Some(infinity as float);
} else if num == "-inf" {
@ -379,7 +377,7 @@ fn from_str(num: &str) -> Option<float> {
*
* `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
*/
fn pow_with_uint(base: uint, pow: uint) -> float {
pub fn pow_with_uint(base: uint, pow: uint) -> float {
if base == 0u {
if pow == 0u {
return NaN as float;
@ -399,21 +397,21 @@ fn pow_with_uint(base: uint, pow: uint) -> float {
return total;
}
pure fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
pure fn is_negative(x: float) -> bool { f64::is_negative(x as f64) }
pure fn is_nonpositive(x: float) -> bool { f64::is_nonpositive(x as f64) }
pure fn is_nonnegative(x: float) -> bool { f64::is_nonnegative(x as f64) }
pure fn is_zero(x: float) -> bool { f64::is_zero(x as f64) }
pure fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
pure fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
pure fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
pub pure fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
pub pure fn is_negative(x: float) -> bool { f64::is_negative(x as f64) }
pub pure fn is_nonpositive(x: float) -> bool { f64::is_nonpositive(x as f64) }
pub pure fn is_nonnegative(x: float) -> bool { f64::is_nonnegative(x as f64) }
pub pure fn is_zero(x: float) -> bool { f64::is_zero(x as f64) }
pub pure fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
pub pure fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
pub pure fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
pure fn abs(x: float) -> float { f64::abs(x as f64) as float }
pure fn sqrt(x: float) -> float { f64::sqrt(x as f64) as float }
pure fn atan(x: float) -> float { f64::atan(x as f64) as float }
pure fn sin(x: float) -> float { f64::sin(x as f64) as float }
pure fn cos(x: float) -> float { f64::cos(x as f64) as float }
pure fn tan(x: float) -> float { f64::tan(x as f64) as float }
pub pure fn abs(x: float) -> float { f64::abs(x as f64) as float }
pub pure fn sqrt(x: float) -> float { f64::sqrt(x as f64) as float }
pub pure fn atan(x: float) -> float { f64::atan(x as f64) as float }
pub pure fn sin(x: float) -> float { f64::sin(x as f64) as float }
pub pure fn cos(x: float) -> float { f64::cos(x as f64) as float }
pub pure fn tan(x: float) -> float { f64::tan(x as f64) as float }
impl float : Eq {
pure fn eq(other: &float) -> bool { self == (*other) }
@ -440,7 +438,7 @@ impl float: num::Num {
}
#[test]
fn test_from_str() {
pub fn test_from_str() {
assert from_str(~"3") == Some(3.);
assert from_str(~"3") == Some(3.);
assert from_str(~"3.14") == Some(3.14);
@ -483,7 +481,7 @@ fn test_from_str() {
}
#[test]
fn test_positive() {
pub fn test_positive() {
assert(is_positive(infinity));
assert(is_positive(1.));
assert(is_positive(0.));
@ -494,7 +492,7 @@ fn test_positive() {
}
#[test]
fn test_negative() {
pub fn test_negative() {
assert(!is_negative(infinity));
assert(!is_negative(1.));
assert(!is_negative(0.));
@ -505,7 +503,7 @@ fn test_negative() {
}
#[test]
fn test_nonpositive() {
pub fn test_nonpositive() {
assert(!is_nonpositive(infinity));
assert(!is_nonpositive(1.));
assert(!is_nonpositive(0.));
@ -516,7 +514,7 @@ fn test_nonpositive() {
}
#[test]
fn test_nonnegative() {
pub fn test_nonnegative() {
assert(is_nonnegative(infinity));
assert(is_nonnegative(1.));
assert(is_nonnegative(0.));
@ -527,13 +525,13 @@ fn test_nonnegative() {
}
#[test]
fn test_to_str_inf() {
pub fn test_to_str_inf() {
assert to_str(infinity, 10u) == ~"inf";
assert to_str(-infinity, 10u) == ~"-inf";
}
#[test]
fn test_traits() {
pub fn test_traits() {
fn test<U:num::Num cmp::Eq>(ten: &U) {
assert (ten.to_int() == 10);