| 1 | /* s_tanl.c -- long double version of s_tan.c. |
| 2 | * Conversion to long double by Ulrich Drepper, |
| 3 | * Cygnus Support, drepper@cygnus.com. |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * ==================================================== |
| 8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 9 | * |
| 10 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
| 11 | * Permission to use, copy, modify, and distribute this |
| 12 | * software is freely granted, provided that this notice |
| 13 | * is preserved. |
| 14 | * ==================================================== |
| 15 | */ |
| 16 | |
| 17 | #if defined(LIBM_SCCS) && !defined(lint) |
| 18 | static char rcsid[] = "$NetBSD: $" ; |
| 19 | #endif |
| 20 | |
| 21 | /* tanl(x) |
| 22 | * Return tangent function of x. |
| 23 | * |
| 24 | * kernel function: |
| 25 | * __kernel_tanl ... tangent function on [-pi/4,pi/4] |
| 26 | * __ieee754_rem_pio2l ... argument reduction routine |
| 27 | * |
| 28 | * Method. |
| 29 | * Let S,C and T denote the sin, cos and tan respectively on |
| 30 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 |
| 31 | * in [-pi/4 , +pi/4], and let n = k mod 4. |
| 32 | * We have |
| 33 | * |
| 34 | * n sin(x) cos(x) tan(x) |
| 35 | * ---------------------------------------------------------- |
| 36 | * 0 S C T |
| 37 | * 1 C -S -1/T |
| 38 | * 2 -S -C T |
| 39 | * 3 -C S -1/T |
| 40 | * ---------------------------------------------------------- |
| 41 | * |
| 42 | * Special cases: |
| 43 | * Let trig be any of sin, cos, or tan. |
| 44 | * trig(+-INF) is NaN, with signals; |
| 45 | * trig(NaN) is that NaN; |
| 46 | * |
| 47 | * Accuracy: |
| 48 | * TRIG(x) returns trig(x) nearly rounded |
| 49 | */ |
| 50 | |
| 51 | #include <errno.h> |
| 52 | #include <math.h> |
| 53 | #include <math_private.h> |
| 54 | #include <libm-alias-ldouble.h> |
| 55 | |
| 56 | long double __tanl(long double x) |
| 57 | { |
| 58 | long double y[2],z=0.0; |
| 59 | int32_t n, se, i0, i1; |
| 60 | |
| 61 | /* High word of x. */ |
| 62 | GET_LDOUBLE_WORDS(se,i0,i1,x); |
| 63 | |
| 64 | /* |x| ~< pi/4 */ |
| 65 | se &= 0x7fff; |
| 66 | if(se <= 0x3ffe) return __kernel_tanl(x,z,1); |
| 67 | |
| 68 | /* tan(Inf or NaN) is NaN */ |
| 69 | else if (se==0x7fff) { |
| 70 | if (i1 == 0 && i0 == 0x80000000) |
| 71 | __set_errno (EDOM); |
| 72 | return x-x; |
| 73 | } |
| 74 | |
| 75 | /* argument reduction needed */ |
| 76 | else { |
| 77 | n = __ieee754_rem_pio2l(x,y); |
| 78 | return __kernel_tanl(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even |
| 79 | -1 -- n odd */ |
| 80 | } |
| 81 | } |
| 82 | libm_alias_ldouble (__tan, tan) |
| 83 | |