24 days of Rust - the glorious tau

Important note: this article is outdated! Go to http://zsiciarz.github.io/24daysofrust/ for a recent version of all of 24 days of Rust articles. The blogpost here is kept as it is for historical reasons.

τ (tau) is one of the most important mathematical constants (if not the most important), relating circle's circumference to it's radius. See the tau manifesto for the long explanation if you're still an unbeliever. Can we use it in Rust? Of course, there's a crate for that!

Let's see this amazing number in full glory:

extern crate tau ; fn main () { println ! ( "τ = {}" , tau :: TAU ); }

$ cargo run τ = 6.283185

We can do all sorts of important calculations with τ, just look:

extern crate num ; use std :: num :: FloatMath ; use num :: complex :: { Complex , Complex64 }; let radius : f64 = 15.0 ; println ! ( "circle circumference = τ * r = {}" , tau :: TAU * radius ); let c : Complex64 = Complex :: from_polar ( & 1.0 , & tau :: TAU ); println ! ( "Euler's identity: exp(i * τ) = {}" , c ); println ! ( "Trigonometry: sin(τ) = {}, cos(τ) = {}" , tau :: TAU . sin (), tau :: TAU . cos ());

And if someone really, I mean really needs to refer to that other mathematical constant, it is (regrettably) possible as well.

println ! ( "That other constant = {}" , tau :: TAU / 2.0 );

Here's the output:

$ cargo run circle circumference = τ * r = 94.24778 Euler ' s identity: exp ( i * τ ) = 1-0i Trigonometry: sin ( τ ) = -0, cos ( τ ) = 1 That other constant = 3.141593

Code examples in this article were built with rustc 0.13.0-nightly and tau 1.0.0.

The header photo (taken by me) shows Warsaw skyline from the Siekierkowski bridge.

Napisane 10 grudnia 2014