Skip to content

Commit

Permalink
fix zsl_phy_atom_bohr_orb_radius for single percision
Browse files Browse the repository at this point in the history
zsl_phy_atom_bohr_orb_radius does not work with single percision
as numbers to small get multipled and just become 0.0f. Multiple
a large constant in to the numerator and denomerator to prevent
numbers from getting to small.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
  • Loading branch information
XenuIsWatching committed Dec 12, 2023
1 parent ee68842 commit 045dbb0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/physics/atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ zsl_phy_atom_bohr_orb_radius(uint8_t z, uint8_t n, zsl_real_t *r)
return -EINVAL;
}

#ifdef CONFIG_ZSL_SINGLE_PRECISION
/*
* Numbers get too small for single percision so multiply a large
* constant in to the numerator and denomerator to prevent numbers
* from going to 0.0f
*/
*r = ((zsl_real_t) n * (zsl_real_t) n * ZSL_RED_PLANCK * 1E30 *
ZSL_RED_PLANCK * 1E9) / ((zsl_real_t) z * ZSL_COULOMB *
ZSL_E_CHARGE * 1E30 * ZSL_E_CHARGE * ZSL_E_MASS);
#else
*r = ((zsl_real_t) n * (zsl_real_t) n * ZSL_RED_PLANCK *
ZSL_RED_PLANCK * 1E9) / ((zsl_real_t) z * ZSL_COULOMB *
ZSL_E_CHARGE * ZSL_E_CHARGE * ZSL_E_MASS);

#endif

return 0;
}
Expand Down

0 comments on commit 045dbb0

Please sign in to comment.