summaryrefslogtreecommitdiff
path: root/lib/libm/catanf.c
blob: 16d480e0ae0627468e7152617c084b39f1fcb8a8 (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
#include <float.h>
#include "__complex.h"

float complex catanf(float complex z)
{
	float complex w;
	float a, t, x, x2, y;

	x = crealf(z);
	y = cimagf(z);

	if ((x == 0.0f) && (y > 1.0f))
		goto overflow;

	x2 = x * x;
	a = 1.0f - x2 - (y * y);
	if (a == 0.0f)
		goto overflow;

	t = 0.5f * atan2f(2.0f * x, a);
	w = redupif(t);

	t = y - 1.0f;
	a = x2 + (t * t);
	if (a == 0.0f)
		goto overflow;

	t = y + 1.0f;
	a = (x2 + (t * t)) / a;

	return w + (0.25f * logf(a)) * I;

overflow:
	return FLT_MAX + FLT_MAX * I;
}