/*
  ############################################################################
  This function computes the inverse hyperbolic tangent to up to 100 decimals.

  aTanh(x) = ln((1 + x) / (1 - x)) / 2

  Where: |x| < 1

  ERRORS:
  FALSE is returned if argument is non-numeric.

  DEPENDENCY: BC_Ln()
  ############################################################################
*/

   function BC_aTanh ($xArg, $Decimals=16)
{
   $Q = 256;
   $x = trim($xArg);
   $S = (bcComp($x, '0', $Q) < 0)? '-':'';
   $x = Str_Replace('+', '', Str_Replace('-', '', $x));
   $q = trim($Decimals);

// Error if either argument is non-numeric.
   if (!Is_Numeric($x) or !Is_Numeric($q))  {return FALSE;}

// Enforce decimals to be within
// legal limits, if necessary.
   if (!Is_Numeric($q)) {$q = 16;} // Default
   $q = floor(abs($q));
   if ($q <   1) {$q =   1;}
   if ($q > 100) {$q = 100;}

   $A = bcAdd('1', $x, $Q); // 1 + x
   $B = bcSub('1', $x, $Q); // 1 - x

   $AoverB = bcDiv($A, $B, $Q); // (1 + x)/(1 - x)

   $atanh = bcDiv(BC_Ln($AoverB, 2*$q), '2', $q);

   return $S.bcAdd($atanh, '0.'.Str_Repeat('0',$q).'5',$q);
}