⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ansimath.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
* return value.  A domain error may occur if both arguments are zero.** INTERNAL:* (1) Reduce <y> to positive by:* *     atan2(y,x)=-atan2(-y,x)* * (2) Reduce <x> to positive by (if <x> and <y> are unexceptional):* *     ARG (x+iy) = arctan(y/x)   	 ... if x > 0*     ARG (x+iy) = pi - arctan[y/(-x)]   ... if x < 0** (3) According to the integer k=4t+0.25 truncated , t=y/x, the argument*     is further reduced to one of the following intervals and the*     arc tangent of y/x is evaluated by the corresponding formula:**     [0,7/16]	      atan(y/x) = t - t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)*     [7/16,11/16]    atan(y/x) = atan(1/2) + atan( (y-x/2)/(x+y/2) )*     [11/16.19/16]   atan(y/x) = atan( 1 ) + atan( (y-x)/(x+y) )*     [19/16,39/16]   atan(y/x) = atan(3/2) + atan( (y-1.5x)/(x+1.5y) )*     [39/16,INF]     atan(y/x) = atan(INF) + atan( -x/y )** INCLUDE FILES: math.h** RETURNS:* The double-precision arc tangent of <y>/<x>, in the range [-pi,pi] radians.** Special cases:*     Notations: atan2(y,x) == ARG (x+iy) == ARG(x,y).* * .TS* tab(|);* l0 c0 l.*     ARG(NAN, (anything))                      | is | NaN*     ARG((anything), NaN)                      | is | NaN*     ARG(+(anything but NaN), +-0)             | is | +-0*     ARG(-(anything but NaN), +-0)             | is | +-PI*     ARG(0, +-(anything but 0 and NaN))        | is | +-PI/2*     ARG(+INF, +-(anything but INF and NaN))   | is | +-0*     ARG(-INF, +-(anything but INF and NaN))   | is | +-PI*     ARG(+INF, +-INF)                          | is | +-PI/4*     ARG(-INF, +-INF)                          | is | +-3PI/4*     ARG((anything but 0, NaN, and INF),+-INF) | is | +-PI/2* .TE** SEE ALSO: mathALib** INTERNAL:* Coded in C by K.C. Ng, 1/8/85;* Revised by K.C. Ng on 2/7/85, 2/13/85, 3/7/85, 3/30/85, 6/29/85.*/double atan2    (    double  y,	/* numerator   */    double  x	/* denominator */    )    {	static double zero=0, one=1, small=1.0E-9, big=1.0E18;	double copysign(),logb(),scalb(),t,z,signy,signx,hi,lo;	int finite(), k,m;#if !defined(vax)&&!defined(tahoe)    /* if x or y is NAN */	if(x!=x) return(x); if(y!=y) return(y);#endif	/* !defined(vax)&&!defined(tahoe) */    /* copy down the sign of y and x */	signy = copysign(one,y) ;	signx = copysign(one,x) ;    /* if x is 1.0, goto begin */	if(x==1) { y=copysign(y,one); t=y; if(finite(t)) goto begin;}    /* when y = 0 */	if(y==zero) return((signx==one)?y:copysign(PI,signy));    /* when x = 0 */	if(x==zero) return(copysign(PIo2,signy));    /* when x is INF */	if(!finite(x))	    if(!finite(y))		return(copysign((signx==one)?PIo4:3*PIo4,signy));	    else		return(copysign((signx==one)?zero:PI,signy));    /* when y is INF */	if(!finite(y)) return(copysign(PIo2,signy));    /* compute y/x */	x=copysign(x,one);	y=copysign(y,one);	if((m=(k=logb(y))-logb(x)) > 60) t=big+big;	    else if(m < -80 ) t=y/x;	    else { t = y/x ; y = scalb(y,-k); x=scalb(x,-k); }    /* begin argument reduction */begin:	if (t < 2.4375) {	/* truncate 4(t+1/16) to integer for branching */	    k = 4 * (t+0.0625);	    switch (k) {	    /* t is in [0,7/16] */	    case 0:	    case 1:		if (t < small)		    { big + small ;  /* raise inexact flag */		      return (copysign((signx>zero)?t:PI-t,signy)); }		hi = zero;  lo = zero;  break;	    /* t is in [7/16,11/16] */	    case 2:		hi = athfhi; lo = athflo;		z = x+x;		t = ( (y+y) - x ) / ( z +  y ); break;	    /* t is in [11/16,19/16] */	    case 3:	    case 4:		hi = PIo4; lo = zero;		t = ( y - x ) / ( x + y ); break;	    /* t is in [19/16,39/16] */	    default:		hi = at1fhi; lo = at1flo;		z = y-x; y=y+y+y; t = x+x;		t = ( (z+z)-x ) / ( t + y ); break;	    }	}	/* end of if (t < 2.4375) */	else	{	    hi = PIo2; lo = zero;	    /* t is in [2.4375, big] */	    if (t <= big)  t = - x / y;	    /* t is in [big, INF] */	    else	      { big+small;	/* raise inexact flag */		t = zero; }	}    /* end of argument reduction */    /* compute atan(t) for t in [-.4375, .4375] */	z = t*t;#if defined(vax)||defined(tahoe)	z = t*(z*(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*(a6+z*(a7+z*(a8+			z*(a9+z*(a10+z*(a11+z*a12))))))))))));#else	/* defined(vax)||defined(tahoe) */	z = t*(z*(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*(a6+z*(a7+z*(a8+			z*(a9+z*(a10+z*a11)))))))))));#endif	/* defined(vax)||defined(tahoe) */	z = lo - z; z += t; z += hi;	return(copysign((signx>zero)?z:PI-z,signy));    }/* ceil.c - ceil math routine *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01f,05feb93,jdi  doc changes based on kdl review.01e,02dec92,jdi  doc tweaks.01d,28oct92,jdi  documentation cleanup.01c,20sep92,smb  documentation additions01b,30jul92,kdl  changed _d_type() calls to fpTypeGet().01a,08jul92,smb  documentation.*//*DESCRIPTIONSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "math.h"#include "stddef.h"#include "errno.h"#include "private/mathP.h"/********************************************************************************* ceil - compute the smallest integer greater than or equal to a specified value (ANSI)** This routine returns the smallest integer greater than or equal to <v>,* in double precision.** INCLUDE FILES: math.h** RETURNS: The smallest integral value greater than or equal to <v>, in* double precision.** SEE ALSO: mathALib*/double ceil    (    double v	/* value to find the ceiling of */    )    {    double r;    switch (fpTypeGet (v, &r))		/* get the type of v */        {    	case ZERO:	/* ZERO */    	case INF:	/* INFINITY */            return (0.0);    	case NAN:	/* NOT A NUMBER */            return (v);    	case INTEGER:	/* INTEGER */            return (v);    	case REAL:	/* REAL */            return (((v < 0.0) || (v == r)) ? r : r + 1.0);	default:	    return (0.0);		/* this should never happen */        }    }/* cosh.c - hyperbolic routines *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01e,05feb93,jdi  doc changes based on kdl review.01d,02dec92,jdi  doc tweaks.01c,28oct92,jdi  documentation cleanup.01b,20sep92,smb  documentation additions01a,08jul92,smb  documentation*//*DESCRIPTION* Copyright (c) 1985 Regents of the University of California.* All rights reserved.** Redistribution and use in source and binary forms are permitted* provided that the above copyright notice and this paragraph are* duplicated in all such forms and that any documentation,* advertising materials, and other materials related to such* distribution and use acknowledge that the software was developed* by the University of California, Berkeley.  The name of the* University may not be used to endorse or promote products derived* from this software without specific prior written permission.* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.** All recipients should regard themselves as participants in an ongoing* research project and hence should feel obligated to report their* experiences (good or bad) with these elementary function codes, using* the sendbug(8) program, to the authors.*SEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "math.h"#if defined(vax)||defined(tahoe)#ifdef vax#define _0x(A,B)	0x/**/A/**/B#else	/* vax */#define _0x(A,B)	0x/**/B/**/A#endif	/* vax *//* static double  *//* mln2hi =  8.8029691931113054792E1     , Hex  2^  7   *  .B00F33C7E22BDB *//* mln2lo = -4.9650192275318476525E-16   , Hex  2^-50   * -.8F1B60279E582A *//* lnovfl =  8.8029691931113053016E1     ; Hex  2^  7   *  .B00F33C7E22BDA */static long    mln2hix[] = { _0x(0f33,43b0), _0x(2bdb,c7e2)};static long    mln2lox[] = { _0x(1b60,a70f), _0x(582a,279e)};static long    lnovflx[] = { _0x(0f33,43b0), _0x(2bda,c7e2)};#define   mln2hi    (*(double*)mln2hix)#define   mln2lo    (*(double*)mln2lox)#define   lnovfl    (*(double*)lnovflx)#else	/* defined(vax)||defined(tahoe) */static doublemln2hi =  7.0978271289338397310E2     , /*Hex  2^ 10   *  1.62E42FEFA39EF */mln2lo =  2.3747039373786107478E-14   , /*Hex  2^-45   *  1.ABC9E3B39803F */lnovfl =  7.0978271289338397310E2     ; /*Hex  2^  9   *  1.62E42FEFA39EF */#endif	/* defined(vax)||defined(tahoe) */#if defined(vax)||defined(tahoe)static max = 126                      ;#else	/* defined(vax)||defined(tahoe) */static max = 1023                     ;#endif	/* defined(vax)||defined(tahoe) *//********************************************************************************* cosh - compute a hyperbolic cosine (ANSI)** This routine returns the hyperbolic cosine of <x> in* double precision (IEEE double, 53 bits).** A range error occurs if <x> is too large.** INTERNAL:* Method:* (1) Replace <x> by |x|.* (2)*                                                 [ exp(x) - 1 ]^2*     0        <= x <= 0.3465  :  cosh(x) := 1 + -------------------*                                                    2*exp(x)**                                            exp(x) +  1/exp(x)*     0.3465   <= x <= 22      :  cosh(x) := -------------------*                                                    2*     22       <= x <= lnovfl  :  cosh(x) := exp(x)/2*     lnovfl   <= x <= lnovfl+log(2)*                              :  cosh(x) := exp(x)/2 (avoid overflow)*     log(2)+lnovfl <  x <  INF:  overflow to INF**         Note: .3465 is a number near one half of ln2.** INCLUDE FILES: math.h** RETURNS:* The double-precision hyperbolic cosine of <x>.** Special cases:*     If <x> is +INF, -INF, or NaN, cosh() returns <x>.** SEE ALSO: mathALib** INTERNAL:* Coded in C by K.C. Ng, 1/8/85;* Revised by K.C. Ng on 2/8/85, 2/23/85, 3/7/85, 3/29/85, 4/16/85.*/double cosh    (    double x	/* value to compute the hyperbolic cosine of */    )    {	static double half=1.0/2.0,one=1.0, small=1.0E-18; /* fl(1+small)==1 */	double scalb(),copysign(),exp(),exp__E(),t;#if !defined(vax)&&!defined(tahoe)	if(x!=x) return(x);	/* x is NaN */#endif	/* !defined(vax)&&!defined(tahoe) */	if((x=copysign(x,one)) <= 22)	    if(x<0.3465)		if(x<small) return(one+x);		else {t=x+exp__E(x,0.0);x=t+t; return(one+t*t/(2.0+x)); }	    else /* for x lies in [0.3465,22] */	        { t=exp(x); return((t+one/t)*half); }	if( lnovfl <= x && x <= (lnovfl+0.7))        /* for x lies in [lnovfl, lnovfl+ln2], decrease x by ln(2^(max+1))         * and return 2^max*exp(x) to avoid unnecessary overflow         */	    return(scalb(exp((x-mln2hi)-mln2lo), max));	else	    return(exp(x)*half);	/* for large x,  cosh(x)=exp(x)/2 */    }/* exp.c - math routines *//* Copyright 1992-1993 Wind River Systems, Inc. *//*modification history--------------------01e,05feb93,jdi  doc changes based on kdl review.01d,02dec92,jdi  doc tweaks.01c,28oct92,jdi  documentation cleanup.01b,20sep92,smb  documentation additions01a,08jul92,smb  documentation.*//*DESCRIPTION* Copyright (c) 1985 Regents of the University of California.* All rights reserved.** Redistribution and use in source and binary forms are permitted* provided that the above copyright notice and this paragraph are* duplicated in all such forms and that any documentation,* advertising materials, and other materials related to such* distribution and use acknowledge that the software was developed* by the University of California, Berkeley.  The name of the* University may not be used to endorse or promote products derived* from this software without specific prior written permission.* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.** All recipients should regard themselves as participants in an ongoing* research project and hence should feel obligated to report their* experiences (good or bad) with these elementary function codes, using* the sendbug(8) program, to the authors.*SEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "math.h"#if defined(vax)||defined(tahoe)	/* VAX D format */#ifdef vax#define _0x(A,B)	0x/**/A/**/B#else	/* vax */#define _0x(A,B)	0x/**/B/**/A#endif	/* vax *//* static double *//* ln2hi  =  6.9314718055829871446E-1    , Hex  2^  0   *  .B17217F7D00000 *//* ln2lo  =  1.6465949582897081279E-12   , Hex  2^-39   *  .E7BCD5E4F1D9CC *//* lnhuge =  9.4961163736712506989E1     , Hex  2^  7   *  .BDEC1DA73E9010 *//* lntiny = -9.5654310917272452386E1     , Hex  2^  7   * -.BF4F01D72E33AF *//* invln2 =  1.4426950408889634148E0     ; Hex  2^  1   *  .B8AA3B295C17F1 *//* p1     =  1.6666666666666602251E-1    , Hex  2^-2    *  .AAAAAAAAAAA9F1 *//* p2     = -2.7777777777015591216E-3    , Hex  2^-8    * -.B60B60B5F5EC94 *//* p3     =  6.6137563214379341918E-5    , Hex  2^-13   *  .8AB355792EF15F *//* p4     = -1.6533902205465250480E-6    , Hex  2^-19   * -.DDEA0E2E935F84 *//* p5     =  4.1381367970572387085E-8    , Hex  2^-24   *  .B1BB4B95F52683 */static long     ln2hix[] = { _0x(7217,4031), _0x(0000,f7d0)};static long     ln2lox[] = { _0x(bcd5,2ce7), _0x(d9cc,e4f1)};static long    lnhugex[] = { _0x(ec1d,43bd), _0x(9010,a73e)};static long    lntinyx[] = { _0x(4f01,c3bf), _0x(33af,d72e)};static long    invln2x[] = { _0x(aa3b,40b8), _0x(17f1,295c)};static long        p1x[] = { _0x(aaaa,3f2a), _0x(a9f1,aaaa)};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -