use crate::constants::universal::speed_of_light;
use crate::real_from_f64;
use crate::{AmountOfSubstance, Energy, HalfLife, Mass, PhysicsError, Time};
use deep_causality_algebra::RealField;
use deep_causality_num::FromPrimitive;
pub fn radioactive_decay_kernel<R>(
n0: &AmountOfSubstance<R>,
half_life: &HalfLife<R>,
time: &Time<R>,
) -> Result<AmountOfSubstance<R>, PhysicsError>
where
R: RealField + FromPrimitive,
{
let zero = R::zero();
if half_life.value() == zero {
return Err(PhysicsError::Singularity(
"Radioactive half-life cannot be zero".into(),
));
}
let two = real_from_f64::<R>(2.0);
let decay_ratio = time.value() / half_life.value();
let remaining = n0.value() * two.powf(-decay_ratio);
AmountOfSubstance::new(remaining)
}
pub fn binding_energy_kernel<R>(mass_defect: &Mass<R>) -> Result<Energy<R>, PhysicsError>
where
R: RealField + FromPrimitive,
{
let c = speed_of_light::<R>();
let e = mass_defect.value() * c * c;
Energy::new(e)
}