Skip to content

Commit a4bb6cf

Browse files
XenuIsWatchingmicrobuilder
authored andcommitted
fix zsl_phy_atom_bohr_orb_radius for single percision
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>
1 parent 7736927 commit a4bb6cf

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/physics/atomic.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,20 @@ zsl_phy_atom_bohr_orb_radius(uint8_t z, uint8_t n, zsl_real_t *r)
3030
return -EINVAL;
3131
}
3232

33+
#ifdef CONFIG_ZSL_SINGLE_PRECISION
34+
/*
35+
* Numbers get too small for single percision so multiply a large
36+
* constant in to the numerator and denomerator to prevent numbers
37+
* from going to 0.0f
38+
*/
39+
*r = ((zsl_real_t) n * (zsl_real_t) n * ZSL_RED_PLANCK * 1E30 *
40+
ZSL_RED_PLANCK * 1E9) / ((zsl_real_t) z * ZSL_COULOMB *
41+
ZSL_E_CHARGE * 1E30 * ZSL_E_CHARGE * ZSL_E_MASS);
42+
#else
3343
*r = ((zsl_real_t) n * (zsl_real_t) n * ZSL_RED_PLANCK *
3444
ZSL_RED_PLANCK * 1E9) / ((zsl_real_t) z * ZSL_COULOMB *
3545
ZSL_E_CHARGE * ZSL_E_CHARGE * ZSL_E_MASS);
36-
46+
#endif
3747

3848
return 0;
3949
}

0 commit comments

Comments
 (0)