-
-
Save RandyMcMillan/d4c2014bdbf6fca608012feb975900bf to your computer and use it in GitHub Desktop.
golden_ratio.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=08828578739e3796fe09bd9c1271b835