Skip to content

ToStr should return the same as Show #12477

@frgomes

Description

@frgomes

I found a floating point rounding error in ToStr.
Also, I would expect that ToStr should return exactly the same as Show returns, including all whitespaces.

#[deriving(Show, ToStr)]
struct S {
    f : f32,
    d : f64,
}

fn main() {
    let f : f32 = 1.8;
    println!("{}", f);          // prints '1.8'
    println!("{}", f.to_str()); // prints '1.79999995'

    let s = S { f: 1.8, d: 1.8 };
    println!("{}", s);          // prints 'S { f: 1.8, d: 1.8 }'
    println!("{}", s.to_str()); // prints 'S{f: 1.79999995, d: 1.8}'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions