Skip to content
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

Weird formatting behavior #112

Open
TheIronBorn opened this issue Jun 17, 2024 · 3 comments
Open

Weird formatting behavior #112

TheIronBorn opened this issue Jun 17, 2024 · 3 comments
Labels

Comments

@TheIronBorn
Copy link

this code:

let x = f16::from_f32(std::f32::consts::PI);
println!("{:.1e}", x);
println!("{:.1e}", f32::from(x));

produces this

3.140625e0
3.1e0

f16::debug just uses fmt(self.to_f32(), f) so I don't know what might be causing this

@VoidStarKat
Copy link
Owner

This is due to PI not being equal to 3.14 when converted to a 16-bit float. It's actually: 3.0996094. Loss of precision can be surprisingly nasty with 16-bit floats.

@TheIronBorn
Copy link
Author

3.09 should still print 3.1 when given the single decimal formatting

@VoidStarKat
Copy link
Owner

VoidStarKat commented Mar 14, 2025 via email

@VoidStarKat VoidStarKat added bug and removed invalid labels Mar 14, 2025
@VoidStarKat VoidStarKat reopened this Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants