Skip to main content

use_nuclear_basic_usage/
basic_usage.rs

1#![allow(clippy::float_cmp)]
2
3use use_nuclear::{
4    ATOMIC_MASS_UNIT_MEV_C2, DecayLaw, NuclideNumbers, activity,
5    binding_energy_mev_from_mass_defect_u,
6};
7
8fn main() -> Result<(), &'static str> {
9    let decay_law = DecayLaw::from_half_life(10.0).ok_or("expected valid half-life")?;
10    let remaining = decay_law
11        .remaining_quantity(100.0, 10.0)
12        .ok_or("expected valid remaining quantity")?;
13    let helium = NuclideNumbers::new(4, 2).ok_or("expected valid nuclide numbers")?;
14
15    assert!((remaining - 50.0).abs() < 1.0e-12);
16    assert_eq!(activity(2.0, 10.0), Some(20.0));
17    assert_eq!(helium.proton_count(), 2);
18    assert_eq!(helium.neutron_count(), 2);
19    assert_eq!(
20        binding_energy_mev_from_mass_defect_u(1.0),
21        Some(ATOMIC_MASS_UNIT_MEV_C2),
22    );
23
24    Ok(())
25}