Skip to content

Instantly share code, notes, and snippets.

@jhjin
Created December 13, 2016 22:14
Show Gist options
  • Save jhjin/4f7dbf063098133ef849f56e44c231a0 to your computer and use it in GitHub Desktop.
Save jhjin/4f7dbf063098133ef849f56e44c231a0 to your computer and use it in GitHub Desktop.
A Fast, Compact Approximation of the Exponential Function (double precision)
// A Fast, Compact Approximation of the Exponential Function
// http://www.schraudolph.org/pubs/Schraudolph99.pdf
inline double fast_exp(double y) {
double d;
*(reinterpret_cast<int*>(&d) + 0) = 0;
*(reinterpret_cast<int*>(&d) + 1) = static_cast<int>(1512775 * y + 1072632447);
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment