GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libm/src/s_atanl.c Lines: 29 35 82.9 %
Date: 2017-11-13 Branches: 14 22 63.6 %

Line Branch Exec Source
1
/*	$OpenBSD: s_atanl.c,v 1.2 2016/09/12 19:47:02 guenther Exp $	*/
2
/* @(#)s_atan.c 5.1 93/09/24 */
3
/* FreeBSD: head/lib/msun/src/s_atan.c 176451 2008-02-22 02:30:36Z das */
4
/*
5
 * ====================================================
6
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7
 *
8
 * Developed at SunPro, a Sun Microsystems, Inc. business.
9
 * Permission to use, copy, modify, and distribute this
10
 * software is freely granted, provided that this notice
11
 * is preserved.
12
 * ====================================================
13
 */
14
15
/*
16
 * See comments in s_atan.c.
17
 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
18
 * Adapted for OpenBSD by Martynas Venckus <martynas@openbsd.org>.
19
 */
20
21
#include <float.h>
22
#include <math.h>
23
24
#include "invtrig.h"
25
#include "math_private.h"
26
27
#ifdef EXT_IMPLICIT_NBIT
28
#define	LDBL_NBIT	0
29
#else /* EXT_IMPLICIT_NBIT */
30
#define	LDBL_NBIT	0x80000000
31
#endif /* EXT_IMPLICIT_NBIT */
32
33
static const long double
34
one   = 1.0,
35
huge   = 1.0e300;
36
37
long double
38
atanl(long double x)
39
{
40
420
	union {
41
		long double e;
42
		struct ieee_ext bits;
43
	} u;
44
	long double w,s1,s2,z;
45
	int id;
46
	int16_t expsign, expt;
47
	int32_t expman;
48
49
210
	u.e = x;
50
210
	expsign = (u.bits.ext_sign << 15) | u.bits.ext_exp;
51
210
	expt = expsign & 0x7fff;
52
210
	if(expt >= ATAN_CONST) {	/* if |x| is large, atan(x)~=pi/2 */
53
	    if(expt == BIAS + LDBL_MAX_EXP &&
54
	       ((u.bits.ext_frach&~LDBL_NBIT)
55
#ifdef EXT_FRACHMBITS
56
		| u.bits.ext_frachm
57
#endif /* EXT_FRACHMBITS */
58
#ifdef EXT_FRACLMBITS
59
		| u.bits.ext_fraclm
60
#endif /* EXT_FRACLMBITS */
61
		| u.bits.ext_fracl)!=0)
62
		return x+x;		/* NaN */
63
	    if(expsign>0) return  atanhi[3]+atanlo[3];
64
	    else     return -atanhi[3]-atanlo[3];
65
	}
66
	/* Extract the exponent and the first few bits of the mantissa. */
67
	/* XXX There should be a more convenient way to do this. */
68
420
	expman = (expt << 8) |
69
210
		((u.bits.ext_frach >> (EXT_FRACHBITS - 9)) & 0xff);
70
210
	if (expman < ((BIAS - 2) << 8) + 0xc0) {	/* |x| < 0.4375 */
71
42
	    if (expt < ATAN_LINEAR) {	/* if |x| is small, atanl(x)~=x */
72
28
		if(huge+x>one) return x;	/* raise inexact */
73
	    }
74
	    id = -1;
75
28
	} else {
76
168
	x = fabsl(x);
77
168
	if (expman < (BIAS << 8) + 0x30) {		/* |x| < 1.1875 */
78
56
	    if (expman < ((BIAS - 1) << 8) + 0x60) {	/* 7/16 <=|x|<11/16 */
79
28
		id = 0; x = (2.0*x-one)/(2.0+x);
80
28
	    } else {			/* 11/16<=|x|< 19/16 */
81
28
		id = 1; x  = (x-one)/(x+one);
82
	    }
83
	} else {
84
112
	    if (expman < ((BIAS + 1) << 8) + 0x38) {	/* |x| < 2.4375 */
85
28
		id = 2; x  = (x-1.5)/(one+1.5*x);
86
28
	    } else {			/* 2.4375 <= |x| < 2^ATAN_CONST */
87
84
		id = 3; x  = -1.0/x;
88
	    }
89
	}}
90
    /* end of argument reduction */
91
196
	z = x*x;
92
196
	w = z*z;
93
    /* break sum aT[i]z**(i+1) into odd and even poly */
94
196
	s1 = z*T_even(w);
95
196
	s2 = w*T_odd(w);
96
224
	if (id<0) return x - x*(s1+s2);
97
	else {
98
168
	    z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
99
168
	    return (expsign<0)? -z:z;
100
	}
101
210
}
102
DEF_STD(atanl);