-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01c03a3
commit 5c735ff
Showing
10 changed files
with
208 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# 0.1.0 | ||
|
||
Initial stable release. | ||
Initial release. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::{constants, units::PositiveFloat, Joule, Kilogram}; | ||
|
||
/// Convert energy to mass using $E=mc^2$ | ||
pub fn energy_to_mass(energy: Joule) -> Kilogram { | ||
PositiveFloat(energy.0 / (constants::C_M_PER_S).powf(2.)) | ||
} | ||
|
||
/// Convert mass to energy using $E=mc^2$ | ||
pub fn mass_to_energy(mass: Kilogram) -> Joule { | ||
PositiveFloat(mass.0 * (constants::C_M_PER_S).powf(2.)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn mass_energy_equivalance() { | ||
// ~1kg | ||
assert!(energy_to_mass(PositiveFloat(8.9e16)).0 > 0.99); | ||
assert!(energy_to_mass(PositiveFloat(8.9e16)).0 < 1.01); | ||
|
||
assert!(mass_to_energy(PositiveFloat(1.)).0 > 8.9e16); | ||
assert!(mass_to_energy(PositiveFloat(1.)).0 < 9.05e16); | ||
} | ||
} |