Welcome to mirror list, hosted at ThFree Co, Russian Federation.

catanl.c « complex « mingwex « mingw « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1fd62685a8f50e4e091670f09938c66cc80a4c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* catanl.c */

/*
   Contributed by Danny Smith
   2005-01-04

   FIXME: This needs some serious numerical analysis.
*/

#include <math.h>
#include <complex.h>
#include <errno.h>

/* catan (z) = -I/2 * clog ((I + z) / (I - z)) */ 

#ifndef _M_PI_2L
#define _M_PI_2L 1.5707963267948966192313L
#endif

long double complex 
catanl (long double complex Z)
{
  long double complex Res;
  long double complex Tmp;
  long double x = __real__ Z;
  long double y = __imag__ Z;

  if ( x == 0.0L && (1.0L - fabsl (y)) == 0.0L)
    {
      errno = ERANGE;
      __real__ Res = HUGE_VALL;
      __imag__ Res = HUGE_VALL;
    }
   else if (isinf (hypotl (x, y)))
   {
     __real__ Res = (x > 0 ? _M_PI_2L : -_M_PI_2L);
     __imag__ Res = 0.0L;
   }
  else
    {
      __real__ Tmp = - x; 
      __imag__ Tmp = 1.0L - y;

      __real__ Res = x; 
      __imag__ Res = y + 1.0L;

      Tmp = clogl (Res/Tmp);	
      __real__ Res  = - 0.5L * __imag__ Tmp;
      __imag__ Res =  0.5L * __real__ Tmp;
    }

   return Res; 
}