Skip to content

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

Closed
@Kimundi

Description

@Kimundi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions