I need to implement square and square-root math functions in my program
what is the latest syntax for using them? as on a question in stack overflow, I saw one method but it was marked outdated
I need to implement square and square-root math functions in my program
what is the latest syntax for using them? as on a question in stack overflow, I saw one method but it was marked outdated
Check out the official docs: std - Rust
Which SO question was it? Those can be fixed.
i have to square them as well
If you read through the f32
documentation you'll find functions for that too. Square means raising to the power of 2 so you'd use .powi(2)
. For example:
let num: f32 = 4.0;
let squared = num.powi(2);
println!("{} squared is {}", num, squared);
let square_root = squared.sqrt();
println!("The square root of {} is {}", squared, square_root);