Skip to content
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;
}
}