Degrees And Radians With to_degrees And to_radians
Math APIs speak radians while users speak degrees; to_radians and to_degrees translate at the boundary and round-trip within one ulp.
Code
use std::f64::consts::FRAC_PI_2;
fn main() {
// 库函数只吃弧度:度数输入在边界先 to_radians
let right_angle = 90.0_f64;
println!("90 deg = {:.4} rad", right_angle.to_radians());
// 展示层转回度数:FRAC_PI_2 就是 90 deg
println!("FRAC_PI_2 = {:.1} deg", FRAC_PI_2.to_degrees());
// 度 → 弧 → 度往返:误差在 1 ulp 内,格式化后回到原值
let heading = 137.5_f64;
let back = heading.to_radians().to_degrees();
println!("heading round trip: {:.1}", back);
}How it works
Degrees And Radians With to_degrees And to_radians keeps everything in the function main.
Putting it to use
The demo output is labeled (90 deg =, FRAC_PI_2 =, heading round trip:), so every printed line maps back to its originating operation.
Core lines
let back = heading.to_radians().to_degrees();
let right_angle = 90.0_f64;
let heading = 137.5_f64;
Interactive Tools for This Topic
A/B Test Sample Size CalculatorCalculate required per-variant sample size and experiment duration for two-proportion A/B tests from baseline conversion, MDE, alpha, and statistical power.CSS Unit ConverterConvert a length between px, rem, em, pt, pc, in, cm, mm, and percent using a configurable root font size, following the 96dpi CSS definition.GCD & LCM CalculatorFind the greatest common divisor and least common multiple of two or more integers, computed exactly with BigInt.Number to WordsConvert an integer up to 999,999,999,999 into US English words, using the short scale and a minus prefix for negative values.
FAQ
- What does Degrees And Radians With to_degrees And to_radians print when run?
- Invoke the file as-is — the `90 deg =`, `FRAC_PI_2 =`, `heading round trip:` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.