take the arccosine of a number in rust

To take the arccosine of a number in Rust, you can use the acos method provided by the standard library's f64 type. Here's an example:

main.rs
fn main() {
    let x = 0.5;
    let y = x.acos();
    println!("arccos({}) = {}", x, y);
}
92 chars
6 lines

In this example, x is the number whose arccosine we want to take, and y is the result. We use the acos method on x to compute the arccosine and store the result in y. Finally, we print out the result using println!.

Note that the acos method returns the arccosine in radians. If you want the result in degrees, you'll need to convert it using the to_degrees method:

main.rs
fn main() {
    let x = 0.5;
    let y = x.acos().to_degrees();
    println!("arccos({}) = {} degrees", x, y);
}
113 chars
6 lines

This will print arccos(0.5) = 60.0 degrees.

gistlibby LogSnag