Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <math.h>
  2. #include <errno.h>
  3. #include "fastmath.h"
  4.  
  5. /* atanh (x) = 0.5 * log ((1.0 + x)/(1.0 - x)) */
  6. long double atanhl (long double x)
  7. {
  8.   long double z;
  9.   if isnan (x)
  10.     return x;
  11.   z = fabsl (x);
  12.   if (z == 1.0L)
  13.     {
  14.       errno  = ERANGE;
  15.       return (x > 0 ? INFINITY : -INFINITY);
  16.     }
  17.   if ( z > 1.0L)
  18.     {
  19.       errno = EDOM;
  20.       return nanl("");
  21.     }
  22.   /* Rearrange formula to avoid precision loss for small x.
  23.   atanh(x) = 0.5 * log ((1.0 + x)/(1.0 - x))
  24.            = 0.5 * log1p ((1.0 + x)/(1.0 - x) - 1.0)
  25.            = 0.5 * log1p ((1.0 + x - 1.0 + x) /(1.0 - x))
  26.            = 0.5 * log1p ((2.0 * x ) / (1.0 - x))  */
  27.   z = 0.5L * __fast_log1pl ((z + z) / (1.0L - z));
  28.   return x >= 0 ? z : -z;
  29. }
  30.