Simple question: Where is sin()
? I've searched and only found in the Rust docs that there are traits like std::num::Float
that require sin, but no implementation.
The sine of one of the angles of a right triangle (often abbreviated “sin”) is the ratio of the length of the side of the triangle opposite the angle to the length of the triangle's hypotenuse.
Sine and cosine — a.k.a., sin(θ) and cos(θ) — are functions revealing the shape of a right triangle. Looking out from a vertex with angle θ, sin(θ) is the ratio of the opposite side to the hypotenuse , while cos(θ) is the ratio of the adjacent side to the hypotenuse .
The sine rule is used when we are given either a) two angles and one side, or b) two sides and a non-included angle. The cosine rule is used when we are given either a) three sides or b) two sides and the included angle.
The Float
trait was removed, and the methods are inherent implementations on the types now (f32
, f64
). That means there's a bit less typing to access math functions:
fn main() {
let val: f32 = 3.14159;
println!("{}", val.sin());
}
However, it's ambiguous if 3.14159.sin()
refers to a 32- or 64-bit number, so you need to specify it explicitly. Above, I set the type of the variable, but you can also use a type suffix:
fn main() {
println!("{}", 3.14159_f64.sin());
}
You can also use fully qualified syntax:
fn main() {
println!("{}", f32::sin(3.14159));
}
Real code should use the PI
constant; I've used an inline number to avoid complicating the matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With