diff --git a/src/main.rs b/src/main.rs index 5b986cf..683c9a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,7 +101,7 @@ fn offset_Momentum(bodies: &mut [body; BODIES_COUNT]) { } // Output the total energy of the system. -unsafe fn output_Energy(bodies: &mut [body; BODIES_COUNT]) { +fn output_Energy(bodies: &mut [body; BODIES_COUNT]) { let mut energy = 0.; for i in 0..BODIES_COUNT { // Add the kinetic energy for each body. @@ -114,14 +114,11 @@ unsafe fn output_Energy(bodies: &mut [body; BODIES_COUNT]) { // Add the potential energy between this body and // every other body for j in i + 1..BODIES_COUNT { - let mut position_Delta = [mem::MaybeUninit::::uninit(); 3]; + let mut position_Delta = [0.; 3]; for m in 0..3 { - position_Delta[m] - .as_mut_ptr() - .write(bodies[i].position[m] - bodies[j].position[m]); + position_Delta[m] = bodies[i].position[m] - bodies[j].position[m]; } - let position_Delta: [f64; 3] = mem::transmute(position_Delta); energy -= bodies[i].mass * bodies[j].mass / f64::sqrt(