microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps
https://walbourn.github.io/introducing-directxmath/
MIT License
1.54k stars 238 forks source link

Missing Exp10 / Log10 functions #107

Closed walbourn closed 4 years ago

walbourn commented 4 years ago

DirectXMath has XMVectorExp2, XMVectorExpE, XMVectorLog2, and XMVectorLogE.

This covers exp/log base 2, exp/log base e.

There is not an implementation of XMVectorExp10 or XMVectorLog10

walbourn commented 4 years ago

Note that Intel's SVML has a _mm_exp10_ps and a _mm_log10_ps

walbourn commented 4 years ago

The basic implementation is very simple. Just like XMVectorExpE and XMVectorLogE, we compute the base 2 from the minimax constants, then convert using:

log(x) = log2(x) / log2(10)
exp(x) = exp2(x) / exp2(10) = exp2(x) * log2(10)

For base e it was:

g_XMLgE = { { { +1.442695f, +1.442695f, +1.442695f, +1.442695f } } };
g_XMInvLgE = { { { +6.93147182e-1f, +6.93147182e-1f, +6.93147182e-1f, +6.93147182e-1f } } };

For base 10 it should be:

g_XMLg10 = { { { +3.321928f, +3.321928f, +3.321928f, +3.321928f } } };
g_XMInvLg10 = { { { +3.010299956e-1f, +3.010299956e-1f, +3.010299956e-1f, +3.010299956e-1f } } };
walbourn commented 4 years ago

PR: https://github.com/microsoft/DirectXMath/pull/109