WIP: add an initial skeleton for a real scsi.device based upon the ata device impleme...
[AROS.git] / compiler / stdc / math / s_atanl.c
blob727180fa2729d7710bcb38966df1b80aeee980fb
1 /* @(#)s_atan.c 5.1 93/09/24 */
2 /* FreeBSD: head/lib/msun/src/s_atan.c 176451 2008-02-22 02:30:36Z das */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
14 #ifndef lint
15 static char rcsid[] = "$FreeBSD: src/lib/msun/src/s_atanl.c,v 1.1 2008/07/31 22:41:26 das Exp $";
16 #endif
19 * See comments in s_atan.c.
20 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
23 #include <float.h>
24 #include "math.h"
26 #include "invtrig.h"
27 #include "math_private.h"
29 static const long double
30 one = 1.0,
31 huge = 1.0e300;
33 long double
34 atanl(long double x)
36 union IEEEl2bits u;
37 long double w,s1,s2,z;
38 int id;
39 int16_t expsign, expt;
40 int32_t expman;
42 u.e = x;
43 expsign = u.xbits.expsign;
44 expt = expsign & 0x7fff;
45 if(expt >= ATAN_CONST) { /* if |x| is large, atan(x)~=pi/2 */
46 if(expt == BIAS + LDBL_MAX_EXP &&
47 ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)!=0)
48 return x+x; /* NaN */
49 if(expsign>0) return atanhi[3]+atanlo[3];
50 else return -atanhi[3]-atanlo[3];
52 /* Extract the exponent and the first few bits of the mantissa. */
53 /* XXX There should be a more convenient way to do this. */
54 expman = (expt << 8) | ((u.bits.manh >> (MANH_SIZE - 9)) & 0xff);
55 if (expman < ((BIAS - 2) << 8) + 0xc0) { /* |x| < 0.4375 */
56 if (expt < ATAN_LINEAR) { /* if |x| is small, atanl(x)~=x */
57 if(huge+x>one) return x; /* raise inexact */
59 id = -1;
60 } else {
61 x = fabsl(x);
62 if (expman < (BIAS << 8) + 0x30) { /* |x| < 1.1875 */
63 if (expman < ((BIAS - 1) << 8) + 0x60) { /* 7/16 <=|x|<11/16 */
64 id = 0; x = (2.0*x-one)/(2.0+x);
65 } else { /* 11/16<=|x|< 19/16 */
66 id = 1; x = (x-one)/(x+one);
68 } else {
69 if (expman < ((BIAS + 1) << 8) + 0x38) { /* |x| < 2.4375 */
70 id = 2; x = (x-1.5)/(one+1.5*x);
71 } else { /* 2.4375 <= |x| < 2^ATAN_CONST */
72 id = 3; x = -1.0/x;
75 /* end of argument reduction */
76 z = x*x;
77 w = z*z;
78 /* break sum aT[i]z**(i+1) into odd and even poly */
79 s1 = z*T_even(w);
80 s2 = w*T_odd(w);
81 if (id<0) return x - x*(s1+s2);
82 else {
83 z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
84 return (expsign<0)? -z:z;