diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-09-25 15:15:49 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-09-25 15:52:41 -0700 |
| commit | e85a3d82470e2e45db370b62e4fd54175c4b144d (patch) | |
| tree | 078c2e710c3a240bc63a5d1bd5192a6cd549652c /src/libcore/float.rs | |
| parent | 2d915678926f4b1c64c5916b01f526844f5521b9 (diff) | |
| download | rust-e85a3d82470e2e45db370b62e4fd54175c4b144d.tar.gz rust-e85a3d82470e2e45db370b62e4fd54175c4b144d.zip | |
Demode Num trait and impls
Diffstat (limited to 'src/libcore/float.rs')
| -rw-r--r-- | src/libcore/float.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/libcore/float.rs b/src/libcore/float.rs index 2cd95269aaf..eaa51814056 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -139,7 +139,7 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { // while we still need digits // build stack of digits - while ii > 0u && (frac >= epsilon_prime || exact) { + while ii > 0 && (frac >= epsilon_prime || exact) { // store the next digit frac *= 10.0; let digit = frac as uint; @@ -153,25 +153,25 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { let mut acc; let mut racc = ~""; - let mut carry = if frac * 10.0 as uint >= 5u { 1u } else { 0u }; + let mut carry = if frac * 10.0 as uint >= 5 { 1 } else { 0 }; // turn digits into string // using stack of digits - while vec::len(fractionalParts) > 0u { + while fractionalParts.is_not_empty() { let mut adjusted_digit = carry + vec::pop(fractionalParts); - if adjusted_digit == 10u { - carry = 1u; - adjusted_digit %= 10u + if adjusted_digit == 10 { + carry = 1; + adjusted_digit %= 10 } else { - carry = 0u + carry = 0; }; racc = uint::str(adjusted_digit) + racc; } // pad decimals with trailing zeroes - while str::len(racc) < digits && exact { + while racc.len() < digits && exact { racc += ~"0" } @@ -428,11 +428,11 @@ impl float : Ord { } impl float: num::Num { - pure fn add(&&other: float) -> float { return self + other; } - pure fn sub(&&other: float) -> float { return self - other; } - pure fn mul(&&other: float) -> float { return self * other; } - pure fn div(&&other: float) -> float { return self / other; } - pure fn modulo(&&other: float) -> float { return self % other; } + pure fn add(other: &float) -> float { return self + *other; } + pure fn sub(other: &float) -> float { return self - *other; } + pure fn mul(other: &float) -> float { return self * *other; } + pure fn div(other: &float) -> float { return self / *other; } + pure fn modulo(other: &float) -> float { return self % *other; } pure fn neg() -> float { return -self; } pure fn to_int() -> int { return self as int; } @@ -540,11 +540,11 @@ fn test_traits() { let two: U = from_int(2); assert (two.to_int() == 2); - assert (ten.add(two) == from_int(12)); - assert (ten.sub(two) == from_int(8)); - assert (ten.mul(two) == from_int(20)); - assert (ten.div(two) == from_int(5)); - assert (ten.modulo(two) == from_int(0)); + assert (ten.add(&two) == from_int(12)); + assert (ten.sub(&two) == from_int(8)); + assert (ten.mul(&two) == from_int(20)); + assert (ten.div(&two) == from_int(5)); + assert (ten.modulo(&two) == from_int(0)); } test(&10.0); |
