Skip to content

float::to_str() and int::to_str() broken on not even that large values. #4314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kimundi opened this issue Dec 30, 2012 · 1 comment
Closed
Milestone

Comments

@Kimundi
Copy link
Member

Kimundi commented Dec 30, 2012

This code:

fn main () {
    let f_e_9: f64  = 1e9f64;
    let f_e_10: f64 = 1e10f64;
    let f_e_19: f64= 1e19f64;

    let u_e_9: u64  = 1e9f64 as u64;
    let u_e_10: u64 = 1e10f64 as u64;
    let u_e_19: u64 = 1e19f64 as u64;

    let i_e_9: i64  = 1e9f64 as i64;
    let i_e_10: i64 = 1e10f64 as i64;
    let i_e_18: i64 = 1e18f64 as i64;

    io::println(f_e_9.to_str());
    io::println(f_e_10.to_str());
    io::println(f_e_19.to_str());

    io::println(u_e_9.to_str());
    io::println(u_e_10.to_str());
    io::println(u_e_19.to_str());

    io::println(i_e_9.to_str());
    io::println(i_e_10.to_str());
    io::println(i_e_18.to_str());
}

produces this output:

1000000000
1410065408.0000
0.0000

1000000000
10000000000
10000000000000000000

1000000000
1410065408
2808348672

For the record, the maximum value of a f32 is ~1e38, and for a f64 ~1e308.

@Kimundi
Copy link
Member Author

Kimundi commented Dec 30, 2012

It's probably because those functions are using int and uint internally, and I'm running them on a 32bit linux. I'm currently writing generic replacements for the numeric to_str() and from_str() functions anyway, it just makes debugging either kinda a chicken-egg problem ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant