Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active October 15, 2025 12:00
Show Gist options
  • Save RandyMcMillan/d4c2014bdbf6fca608012feb975900bf to your computer and use it in GitHub Desktop.
Save RandyMcMillan/d4c2014bdbf6fca608012feb975900bf to your computer and use it in GitHub Desktop.
golden_ratio.rs
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);
}
@RandyMcMillan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment