Annotation of 43BSDReno/lib/libm/common/sincos.c, revision 1.1.1.1

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[] = "@(#)sincos.c   5.4 (Berkeley) 6/1/90";
                     27: #endif /* not lint */
                     28: 
                     29: #include "trig.h"
                     30: double
                     31: sin(x)
                     32: double x;
                     33: {
                     34:        double a,c,z;
                     35: 
                     36:         if(!finite(x))         /* sin(NaN) and sin(INF) must be NaN */
                     37:                return x-x;
                     38:        x=drem(x,PI2);          /* reduce x into [-PI,PI] */
                     39:        a=copysign(x,one);
                     40:        if (a >= PIo4) {
                     41:                if(a >= PI3o4)          /* ... in [3PI/4,PI] */
                     42:                        x = copysign((a = PI-a),x);
                     43:                else {                  /* ... in [PI/4,3PI/4]  */
                     44:                        a = PIo2-a;             /* rtn. sign(x)*C(PI/2-|x|) */
                     45:                        z = a*a;
                     46:                        c = cos__C(z);
                     47:                        z *= half;
                     48:                        a = (z >= thresh ? half-((z-half)-c) : one-(z-c));
                     49:                        return copysign(a,x);
                     50:                }
                     51:        }
                     52: 
                     53:        if (a < small) {                /* rtn. S(x) */
                     54:                big+a;
                     55:                return x;
                     56:        }
                     57:        return x+x*sin__S(x*x);
                     58: }
                     59: 
                     60: double
                     61: cos(x) 
                     62: double x;
                     63: {
                     64:        double a,c,z,s = 1.0;
                     65: 
                     66:        if(!finite(x))          /* cos(NaN) and cos(INF) must be NaN */
                     67:                return x-x;
                     68:        x=drem(x,PI2);          /* reduce x into [-PI,PI] */
                     69:        a=copysign(x,one);
                     70:        if (a >= PIo4) {
                     71:                if (a >= PI3o4) {       /* ... in [3PI/4,PI] */
                     72:                        a = PI-a;
                     73:                        s = negone;
                     74:                }
                     75:                else {                  /* ... in [PI/4,3PI/4] */
                     76:                        a = PIo2-a;
                     77:                        return a+a*sin__S(a*a); /* rtn. S(PI/2-|x|) */ 
                     78:                }
                     79:        }
                     80:        if (a < small) {
                     81:                big+a;
                     82:                return s;               /* rtn. s*C(a) */
                     83:        }
                     84:        z = a*a;
                     85:        c = cos__C(z);
                     86:        z *= half;
                     87:        a = (z >= thresh ? half-((z-half)-c) : one-(z-c));
                     88:        return copysign(a,s);
                     89: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.