Skip to content

Commit

Permalink
Made num <-> str conversion functions use NumStrConv trait
Browse files Browse the repository at this point in the history
Removed hacky dependency on Round trait and generic infinity functions
Removed generic-runtime-failure-depending-on-type behavior
  • Loading branch information
Kimundi committed Feb 15, 2013
1 parent 26e0aaf commit bd93a36
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 119 deletions.
12 changes: 6 additions & 6 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl num::Round for f32 {
#[inline(always)]
pub pure fn to_str(num: f32) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigAll);
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
r
}

Expand All @@ -392,7 +392,7 @@ pub pure fn to_str(num: f32) -> ~str {
#[inline(always)]
pub pure fn to_str_hex(num: f32) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 16u, true, true, strconv::SignNeg, strconv::DigAll);
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
r
}

Expand All @@ -413,7 +413,7 @@ pub pure fn to_str_hex(num: f32) -> ~str {
#[inline(always)]
pub pure fn to_str_radix(num: f32, rdx: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, rdx, true, true, strconv::SignNeg, strconv::DigAll);
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
try to_str_radix_special() if those are expected") }
r
Expand All @@ -430,7 +430,7 @@ pub pure fn to_str_radix(num: f32, rdx: uint) -> ~str {
*/
#[inline(always)]
pub pure fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
strconv::to_str_common(&num, rdx, true, true,
strconv::to_str_common(&num, rdx, true,
strconv::SignNeg, strconv::DigAll)
}

Expand All @@ -446,7 +446,7 @@ pub pure fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
#[inline(always)]
pub pure fn to_str_exact(num: f32, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigExact(dig));
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
r
}

Expand All @@ -462,7 +462,7 @@ pub pure fn to_str_exact(num: f32, dig: uint) -> ~str {
#[inline(always)]
pub pure fn to_str_digits(num: f32, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigMax(dig));
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
r
}

Expand Down
12 changes: 6 additions & 6 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl num::Round for f64 {
#[inline(always)]
pub pure fn to_str(num: f64) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigAll);
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
r
}

Expand All @@ -417,7 +417,7 @@ pub pure fn to_str(num: f64) -> ~str {
#[inline(always)]
pub pure fn to_str_hex(num: f64) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 16u, true, true, strconv::SignNeg, strconv::DigAll);
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
r
}

Expand All @@ -438,7 +438,7 @@ pub pure fn to_str_hex(num: f64) -> ~str {
#[inline(always)]
pub pure fn to_str_radix(num: f64, rdx: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, rdx, true, true, strconv::SignNeg, strconv::DigAll);
&num, rdx, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
try to_str_radix_special() if those are expected") }
r
Expand All @@ -455,7 +455,7 @@ pub pure fn to_str_radix(num: f64, rdx: uint) -> ~str {
*/
#[inline(always)]
pub pure fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
strconv::to_str_common(&num, rdx, true, true,
strconv::to_str_common(&num, rdx, true,
strconv::SignNeg, strconv::DigAll)
}

Expand All @@ -471,7 +471,7 @@ pub pure fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
#[inline(always)]
pub pure fn to_str_exact(num: f64, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigExact(dig));
&num, 10u, true, strconv::SignNeg, strconv::DigExact(dig));
r
}

Expand All @@ -487,7 +487,7 @@ pub pure fn to_str_exact(num: f64, dig: uint) -> ~str {
#[inline(always)]
pub pure fn to_str_digits(num: f64, dig: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigMax(dig));
&num, 10u, true, strconv::SignNeg, strconv::DigMax(dig));
r
}

Expand Down
12 changes: 6 additions & 6 deletions src/libcore/num/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub mod consts {
#[inline(always)]
pub pure fn to_str(num: float) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigAll);
&num, 10u, true, strconv::SignNeg, strconv::DigAll);
r
}

Expand All @@ -123,7 +123,7 @@ pub pure fn to_str(num: float) -> ~str {
#[inline(always)]
pub pure fn to_str_hex(num: float) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 16u, true, true, strconv::SignNeg, strconv::DigAll);
&num, 16u, true, strconv::SignNeg, strconv::DigAll);
r
}

Expand All @@ -144,7 +144,7 @@ pub pure fn to_str_hex(num: float) -> ~str {
#[inline(always)]
pub pure fn to_str_radix(num: float, radix: uint) -> ~str {
let (r, special) = strconv::to_str_common(
&num, radix, true, true, strconv::SignNeg, strconv::DigAll);
&num, radix, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \
try to_str_radix_special() if those are expected") }
r
Expand All @@ -161,7 +161,7 @@ pub pure fn to_str_radix(num: float, radix: uint) -> ~str {
*/
#[inline(always)]
pub pure fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
strconv::to_str_common(&num, radix, true, true,
strconv::to_str_common(&num, radix, true,
strconv::SignNeg, strconv::DigAll)
}
Expand All @@ -177,7 +177,7 @@ pub pure fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
#[inline(always)]
pub pure fn to_str_exact(num: float, digits: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigExact(digits));
&num, 10u, true, strconv::SignNeg, strconv::DigExact(digits));
r
}
Expand All @@ -199,7 +199,7 @@ pub fn test_to_str_exact_do_decimal() {
#[inline(always)]
pub pure fn to_str_digits(num: float, digits: uint) -> ~str {
let (r, _) = strconv::to_str_common(
&num, 10u, true, true, strconv::SignNeg, strconv::DigMax(digits));
&num, 10u, true, strconv::SignNeg, strconv::DigMax(digits));
r
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/num/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,23 @@ impl FromStrRadix for T {
/// Convert to a string as a byte slice in a given base.
#[inline(always)]
pub pure fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false, false,
let (buf, _) = strconv::to_str_bytes_common(&n, radix, false,
strconv::SignNeg, strconv::DigAll);
f(buf)
}
/// Convert to a string in base 10.
#[inline(always)]
pub pure fn to_str(num: T) -> ~str {
let (buf, _) = strconv::to_str_common(&num, 10u, false, false,
let (buf, _) = strconv::to_str_common(&num, 10u, false,
strconv::SignNeg, strconv::DigAll);
buf
}
/// Convert to a string in a given base.
#[inline(always)]
pub pure fn to_str_radix(num: T, radix: uint) -> ~str {
let (buf, _) = strconv::to_str_common(&num, radix, false, false,
let (buf, _) = strconv::to_str_common(&num, radix, false,
strconv::SignNeg, strconv::DigAll);
buf
}
Expand Down
Loading

0 comments on commit bd93a36

Please sign in to comment.