/****************************************************************************** * This program estimates the stellar density of the Milky Way Galaxy. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #![allow(dead_code)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] use std::f64::consts::{PI}; use std::process; const BULGE_RADIUS:f64 = 10000; const DISK_RADIUS:f64 = 52850; const DISK_THICKNESS:f64 = 1000; fn main() { if args.len() != 2 { println!("Syntax: MilkyWayStellarDensity numberOfStars"); process::exit(1); } let mut num_stars:i64 = args[1].trim().parse::().unwrap_or(250000000000_i64); let disk_volume:f64 = PI * DISK_RADIUS - BULGE_RADIUS.powf(2.f64) * DISK_THICKNESS; let sphere_volume:f64 = 4.0f64 / 3.0f64 * PI * BULGE_RADIUS.powf(3.0f64); let milky_way_volume:f64 = disk_volume + sphere_volume; let stellar_density:f64 = (num_stars) as f64 / milky_way_volume; println!("The Milky Way stellar density \u{2248} {0:.3e} stars per light-year\u{b3}", stellar_density); let average_distance:f64 = stellar_density.powf(-1.0f64 / 3.0f64); println!("The average distance between stars \u{2248} {0:.3e} light-years", average_distance); }