Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 19, 2025 19:12
Show Gist options
  • Select an option

  • Save rust-play/c60f8e78ef58d25b493ce6abd987dd8d to your computer and use it in GitHub Desktop.

Select an option

Save rust-play/c60f8e78ef58d25b493ce6abd987dd8d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
// Verbose Script: Corrected Floating-Point Comparison
fn main() {
// ----------------------------------------------------
// 1. Define Constants
// ----------------------------------------------------
const PI: f64 = std::f64::consts::PI;
let gamma_one_half: f64 = PI.sqrt();
println!("--- Initial Mathematical Fact ---");
println!("Gamma(1/2) (Simulated) = {:.16}", gamma_one_half);
println!("Square Root of Pi = {:.16}", PI.sqrt());
println!("---------------------------------");
// ----------------------------------------------------
// 2. Perform the Squaring Operation
// ----------------------------------------------------
// LHS: (Gamma(1/2))^2 = (sqrt(PI))^2. The result might hold a slight rounding error.
let lhs_squared: f64 = gamma_one_half.powi(2);
// RHS: PI (the original constant)
let rhs_squared: f64 = PI;
// ----------------------------------------------------
// 3. Print the Resulting Equation
// ----------------------------------------------------
println!("\n--- Resulting Equation After Squaring Both Sides ---");
println!("LHS: (Gamma(1/2))^2 = {:.16}", lhs_squared);
println!("RHS: pi = {:.16}", rhs_squared);
// ----------------------------------------------------
// 4. Robust Comparison
// ----------------------------------------------------
const TOLERANCE: f64 = 1e-15; // A more appropriate fixed tolerance for high-precision math
println!("\n--- Conclusion ---");
// Check for equality using a reasonable tolerance.
if (lhs_squared - rhs_squared).abs() < TOLERANCE {
println!("The squared LHS and RHS are equal within tolerance of {}.", TOLERANCE);
println!("The resulting equation is mathematically verified: (Gamma(1/2))^2 = pi");
} else {
println!("Error: The calculated values do not match (even with tolerance).");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment