Black Hole Size Calculation

Published 416d ago

 cooluser

Calculates the size of a black hole given masses.

fn calculate_black_hole_size(mass: f64) -> f64 {
    // Gravitational constant (m³ kg⁻¹ s⁻²)
    let gravitational_constant: f64 = 6.67430e-11;
    // Speed of light (m/s)
    let speed_of_light: f64 = 299792458.0;

    // Calculate the Schwarzschild radius
    let schwarzschild_radius =
        (2.0 * gravitational_constant * mass) / (speed_of_light * speed_of_light);
    schwarzschild_radius
}

fn main() {
    // Test cases
    let black_hole_masses: [f64; 4] = [1.0, 10.0, 1_000.0, 1_000_000.0];

    for mass in &black_hole_masses {
        let schwarzschild_radius = calculate_black_hole_size(*mass);
        println!(
            "For a black hole with mass {} kg, the Schwarzschild radius is {} meters.",
            mass, schwarzschild_radius
        );
    }
}

1

Please login or sign up to comment and collaborate