Guest User

Untitled

a guest
Apr 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. static inline uint32_t
  2. top12 (float x)
  3. {
  4. return asuint (x) >> 20;
  5. }
  6.  
  7. float
  8. __expf (float x)
  9. {
  10. uint64_t ki, t;
  11. /* double_t for better performance on targets with FLT_EVAL_METHOD==2. */
  12. double_t kd, xd, z, r, r2, y, s;
  13.  
  14. xd = (double_t) x;
  15. // [...] skipping fast under/overflow handling
  16.  
  17. /* x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k. */
  18. z = InvLn2N * xd;
  19.  
  20. /* Round and convert z to int, the result is in [-150*N, 128*N] and
  21. ideally ties-to-even rule is used, otherwise the magnitude of r
  22. can be bigger which gives larger approximation error. */
  23. kd = roundtoint (z);
  24. ki = converttoint (z);
  25. r = z - kd;
  26.  
  27. /* exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */
  28. t = T[ki % N];
  29. t += ki << (52 - EXP2F_TABLE_BITS);
  30. s = asdouble (t);
  31. z = C[0] * r + C[1];
  32. r2 = r * r;
  33. y = C[2] * r + 1;
  34. y = z * r2 + y;
  35. y = y * s;
  36. return (float) y;
  37. }
Add Comment
Please, Sign In to add comment