take the tangent of a number in rust

To take the tangent of a number in Rust, you can use the standard library function tan(). This function takes a single argument of type f64 (a 64-bit floating point number), and returns the tangent of that number. Here's an example:

main.rs
fn main() {
    let x = 1.0;
    let tangent = x.tan();
    println!("The tangent of {} is {}", x, tangent);
}
111 chars
6 lines

This program will output:

main.rs
The tangent of 1 is 1.5574077246549023
39 chars
2 lines

If you need to work with radians instead of degrees, Rust's standard library also provides a constant std::f64::consts::PI for the value of pi. Here's an example that takes the tangent of π/4 radians:

main.rs
use std::f64::consts::PI;

fn main() {
    let x = PI / 4.0;
    let tangent = x.tan();
    println!("The tangent of {} radians is {}", x, tangent);
}
151 chars
8 lines

This program will output:

main.rs
The tangent of 0.7853981633974483 radians is 0.9999999999999999
64 chars
2 lines

gistlibby LogSnag