Skip to content

Instantly share code, notes, and snippets.

@Chelsea486MHz
Last active July 24, 2017 22:27
Show Gist options
  • Select an option

  • Save Chelsea486MHz/57ad89ae67f60c244dab4924b0e1008e to your computer and use it in GitHub Desktop.

Select an option

Save Chelsea486MHz/57ad89ae67f60c244dab4924b0e1008e to your computer and use it in GitHub Desktop.
#define EXP_TAYLOR_TERMS 18
static uint64_t fact[]=
{
1,
1,
2,
6,
24,
120,
720,
5040,
40320,
362880,
3628800,
39916800,
479001600,
6227020800,
87178291200,
1307674368000,
20922789888000,
355687428096000,
6402373705728000
};
long double expl(long double x)
{
long double res; /* Result of the operation */
long double xpow; /* At each iteration, will be multiplied by x to simulate pow(x, i) */
uint64_t i; /* Iteration variable */
uint64_t k; /* How many times we have to divide x by 2 to get x<1 */
res=0.0;
xpow=1.0;
if (x<0.0)
return (1.0/expl(-x));
for(k=0; x>1.0; ++k)
x /= 2.0;
for (i=0; i<EXP_TAYLOR_TERMS; ++i)
{
res += xpow/fact[i]
xpow *= x;
}
for (i=0; i<k; ++i)
res *= res;
return (res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment