|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1987 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: * ! 19: * All recipients should regard themselves as participants in an ongoing ! 20: * research project and hence should feel obligated to report their ! 21: * experiences (good or bad) with these elementary function codes, using ! 22: * the sendbug(8) program, to the authors. ! 23: */ ! 24: ! 25: #ifndef lint ! 26: static char sccsid[] = "@(#)tan.c 5.4 (Berkeley) 6/1/90"; ! 27: #endif /* not lint */ ! 28: ! 29: #include "trig.h" ! 30: double ! 31: tan(x) ! 32: double x; ! 33: { ! 34: double a,z,ss,cc,c; ! 35: int k; ! 36: ! 37: if(!finite(x)) /* tan(NaN) and tan(INF) must be NaN */ ! 38: return x-x; ! 39: x = drem(x,PI); /* reduce x into [-PI/2, PI/2] */ ! 40: a = copysign(x,one); /* ... = abs(x) */ ! 41: if (a >= PIo4) { ! 42: k = 1; ! 43: x = copysign(PIo2-a,x); ! 44: } ! 45: else { ! 46: k = 0; ! 47: if (a < small) { ! 48: big+a; ! 49: return x; ! 50: } ! 51: } ! 52: z = x*x; ! 53: cc = cos__C(z); ! 54: ss = sin__S(z); ! 55: z *= half; /* Next get c = cos(x) accurately */ ! 56: c = (z >= thresh ? half-((z-half)-cc) : one-(z-cc)); ! 57: if (k == 0) ! 58: return x+(x*(z-(cc-ss)))/c; /* ... sin/cos */ ! 59: #ifdef national ! 60: else if (x == zero) ! 61: return copysign(fmax,x); /* no inf on 32k */ ! 62: #endif /* national */ ! 63: else ! 64: return c/(x+x*ss); /* ... cos/sin */ ! 65: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.