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.rs111 chars6 lines
This program will output:
main.rs39 chars2 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.rs151 chars8 lines
This program will output:
main.rs64 chars2 lines
gistlibby LogSnag