Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement p_exp aproximation function #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/math/p_exp.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <pal.h>

/**
*
* Calculate exponent (e^a), where e is the base of the natural logarithm
* (2.71828.)
*
* Based of the algorithm in this paper: http://www.schraudolph.org/pubs/Schraudolph99.pdf,
* It calculates a approximation of e^a very efficiently, but at the cost of accuracy.
*
* @param a Pointer to input vector
*
* @param c Pointer to output vector
Expand All @@ -14,12 +16,19 @@
* @return None
*
*/
#include <math.h>

void p_exp_f32(const float *a, float *c, int n)
{

int i;
for (i = 0; i < n; i++) {
*(c + i) = expf(*(a + i));
union
{
float f;
uint32_t i;
} u;

// = 2^23 / M_LN2 * (*(a+i)) + (127 * 2^23 - 100000)
u.i = 12102203.16156 * ( *( a + i )) + (1065353216 - 100000);
*(c + i) = u.f;
}
}