Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to convert a float value to an absolute value in Rust

2 Answers

0 votes
pub fn absfloat32(x: f32) -> f32 {
    f32::from_bits(x.to_bits() & (i32::MAX as u32))
}

fn main() {
    println!("{}", absfloat32(-837.37948));
}

   
   
/*
run:

837.37946

*/

 



answered Aug 10, 2024 by avibootz
0 votes
pub fn absfloat64(x: f64) -> f64 {
    f64::from_bits(x.to_bits() & (i64::MAX as u64))
}

fn main() {
    println!("{}", absfloat64(-94872.89201));
}

   
   
/*
run:

94872.89201

*/

 



answered Aug 10, 2024 by avibootz

Related questions

1 answer 115 views
115 views asked Dec 8, 2022 by avibootz
1 answer 145 views
1 answer 124 views
1 answer 90 views
3 answers 98 views
98 views asked Oct 30, 2024 by avibootz
1 answer 77 views
77 views asked Jul 5, 2024 by avibootz
...