Where is the sine function?
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.