#ifndef lint static char sccsid[] = "@(#)trigpi.c 1.1 92/07/30 SMI"; #endif /* * Copyright (c) 1989 by Sun Microsystems, Inc. */ /* sinpi(x), cospi(x), tanpi(x), sincospi(x,s,c) * return double precision trig(pi*x). */ #include static double pi = 3.14159265358979323846, /* 400921FB,54442D18 */ two52 = 4503599627370496.0, /* 43300000,00000000 */ two53 = 9007199254740992.0; /* 43400000,00000000 */ double sinpi(x) double x; { double y,z; int i,n; if(!finite(x)) return x-x; y = fabs(x); if(y<0.25) return sin(pi*x); i = signbit(x); /* * argument reduction, make sure inexact flag not raised if input * is an integer */ z = aint(y); if(z!=y) { /* inexact anyway */ y *= 0.5; y = 2.0*(y - aint(y)); /* y = |x| mod 2.0 */ n = (int) (y*4.0); } else { if(z>=two53) { y = 0.0; n = 0; /* y must be even */ } else { if(z1.0e-20) y*=pi; return cos(y);} /* * argument reduction, make sure inexact flag not raised if input * is an integer */ z = aint(y); if(z!=y) { /* inexact anyway */ y *= 0.5; y = 2.0*(y - aint(y)); /* y = |x| mod 2.0 */ n = (int) (y*4.0); } else { if(z>=two53) { y = 0.0; n = 0; /* y must be even */ } else { if(z=two53) { y = 0.0; n = 0; /* y must be even */ } else { if(z