std-method
Floating-point trigonometry and angle conversion
Convert angles from degrees to radians before applying trigonometric functions. Compare approximate results with a tolerance. Expected stdout (not executed): true Common mistake: Passing degrees directly to sin is a unit error.
Formal Syntax & Structure
rust syntaxrust
x.to_radians(); x.to_degrees(); x.sin(); x.cos()Working Example
Example Snippetrust
fn main() { let angle = 30.0_f64.to_radians(); println!("{}", (angle.sin() - 0.5).abs() < 1e-10);}