Revisions
-
JcBernack created this gist
May 4, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ /// <summary> /// Fast exponential approximation. /// </summary> /// <remarks> /// Based on "A Fast, Compact Approximation of the Exponential Function" by Nicol N.Schraudolph (1999) /// <code>e^x ~ a*x + b /// a = 2 ^ (mantissa bits) / ln(2) ~ 12102203 /// b = (exponent bias) * 2^(mantissa bits) ~ 1065353216</code> /// </remarks> /// <param name="x">A number specifying a power.</param> /// <returns>The number e raised to the power x.</returns> public static float FastExp(float x) { var temp = (int)(12102203 * x + 1065353216); return BitConverter.ToSingle(BitConverter.GetBytes(temp), 0); }