Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 15, 2025 11:59
Show Gist options
  • Save rust-play/08828578739e3796fe09bd9c1271b835 to your computer and use it in GitHub Desktop.
Save rust-play/08828578739e3796fe09bd9c1271b835 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
// The Golden Ratio is (1 + sqrt(5)) / 2
let five = 5.0f64;
// --- Floating-Point Types (Accurate Representation) ---
// f64: Double-precision floating point (default and most precise)
let phi_f64: f64 = (1.0 + five.sqrt()) / 2.0;
// f32: Single-precision floating point (less precision)
let phi_f32: f32 = (1.0f32 + (5.0f32).sqrt()) / 2.0f32;
// Print the results
println!("⭐ Golden Ratio: (1 + sqrt(5)) / 2 ⭐");
println!("--- Floating-Point Types (Accurate) ---");
println!("f64: {}", phi_f64);
println!("f32: {}", phi_f32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment