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
Respect precision format specifiers in Vec3::display #271
Comments
I think this is rather subjective. In some cases, floating point equality is useful (often when comparing against |
I think I know what you are getting at @ten3roberts but it might help to include example code. |
Of course. The following example demonstrated the slight problem I am having let pos = Vec3::new(0.00000000000004, 0.5, 1.0);
println!("Pos: {:.2}", pos); // Pos: [0.000000000004, 0.5, 1]
println!("Pos: [{:.2}, {:.2}, {:.2}]", pos.x, pos.y, pos.z); // -> Pos: [0.00, 0.50, 1.00] It happens in physics simulations where you have something slowing down but never due to a proportional force, and I would like to round the result. E.g where lim x->inf f = 0 The code for that example write!(
f,
concat!(
"frametime: {:.<7.1?} | {:>2.1}/s\n",
"elapsed: {:.2?}\n",
"pos: {:.2}\n",
"vel: {:.2}\n",
),
self.frametime,
1.0 / self.frametime.as_secs_f32(),
self.elapsed,
self.pos,
self.vel,
)?;
Ok(()) |
I noticed that You can kind of work around this to get what you want:
prints
So you can get the output that you want with the last one :) It should be possible to make |
I suppose the above trick works because In that case, the display trait could be implemented to just forward to the slice Display implementation, which means we will get all the features and formats correctly. |
Currently, the floating point value is display in full, which creates way too many decimals than are necessary for displaying e.g; position.
If it is not possible to respect format precision, it would be better if a precision of e.g 4 or 5 was used.
Example:
The text was updated successfully, but these errors were encountered: