Last active
October 31, 2021 20:39
-
-
Save Carandiru0/c1a7d51283a07641b7173c87e176641e to your computer and use it in GitHub Desktop.
optimized bellcurve function (including desmos) [0.0....1.0] input, [0.0....1.0] output
This file contains hidden or 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
// optimized bellcurve function | |
// https://www.desmos.com/calculator/xxwdiqa4sk | |
STATIC_INLINE_PURE float const __vectorcall bellcurve(float x) // 0..1 input to 0..1 output | |
{ | |
// mu is 0.0 (centered) sigma is 0.5 | |
constexpr float const c(XM_PI / -1.25331414f); // optimized magic value - bellcurve perfect match (to six digits of precision) | |
// removes sqrt | |
// https://www.desmos.com/calculator/xxwdiqa4sk | |
x = 2.0f * (x * 2.0f - 1.0f); // converts input range | |
return(SFM::__exp(x * x * c)); | |
} | |
// vector intrinsic support | |
STATIC_INLINE_PURE XMVECTOR const __vectorcall bellcurve(XMVECTOR x) // 0..1 input to 0..1 output | |
{ | |
// mu is 0.0 (centered) sigma is 0.5 | |
constexpr float const c(XM_PI / -1.25331414f); // optimized magic value - bellcurve perfect match (to six digits of precision) | |
// removes sqrt | |
// https://www.desmos.com/calculator/xxwdiqa4sk | |
XMVECTOR const xmTwo(XMVectorReplicate(2.0f)); | |
x = XMVectorMultiply(SFM::__fms(x, xmTwo, XMVectorReplicate(1.0f)), xmTwo); // converts input range | |
return(SFM::__exp(XMVectorMultiply(XMVectorMultiply(x, x), XMVectorReplicate(c)))); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment