Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn round(n: f64, precision: u32) -> f64 {
- (n * 10_u32.pow(precision) as f64).round() / 10_i32.pow(precision) as f64
- }
- fn precision(x: f64) -> u32 {
- for digits in 0..std::f64::DIGITS {
- if round(x, digits) == x {
- return digits;
- }
- }
- return std::f64::DIGITS;
- }
- fn main() {
- let x = 1.0005_f64;
- println!("{:?}", precision(x));
- }
Add Comment
Please, Sign In to add comment