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

📄 k_standard.c

📁 标准c库代码,可以应用于各个系统提供了大量的基本函数
💻 C
📖 第 1 页 / 共 2 页
字号:
/* @(#)k_standard.c 5.1 93/09/24 *//* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice  * is preserved. * ==================================================== * */#include "fdlibm.h"#include <errno.h>#ifndef _USE_WRITE#include <stdio.h>			/* fputs(), stderr */#define	WRITE2(u,v)	fputs(u, _stderr_r(p))#else	/* !defined(_USE_WRITE) */#include <unistd.h>			/* write */#define	WRITE2(u,v)	_write_r(p, 2, u, v)#undef fflush#endif	/* !defined(_USE_WRITE) */#ifdef __STDC__static const double zero = 0.0;	/* used as const */#elsestatic double zero = 0.0;	/* used as const */#endif/*  * Standard conformance (non-IEEE) on exception cases. * Mapping: *	1 -- acos(|x|>1) *	2 -- asin(|x|>1) *	3 -- atan2(+-0,+-0) *	4 -- hypot overflow *	5 -- cosh overflow *	6 -- exp overflow *	7 -- exp underflow *	8 -- y0(0) *	9 -- y0(-ve) *	10-- y1(0) *	11-- y1(-ve) *	12-- yn(0) *	13-- yn(-ve) *	14-- lgamma(finite) overflow *	15-- lgamma(-integer) *	16-- log(0) *	17-- log(x<0) *	18-- log10(0) *	19-- log10(x<0) *	20-- pow(0.0,0.0) *	21-- pow(x,y) overflow *	22-- pow(x,y) underflow *	23-- pow(0,negative)  *	24-- pow(neg,non-integral) *	25-- sinh(finite) overflow *	26-- sqrt(negative) *      27-- fmod(x,0) *      28-- remainder(x,0) *	29-- acosh(x<1) *	30-- atanh(|x|>1) *	31-- atanh(|x|=1) *	32-- scalb overflow *	33-- scalb underflow *	34-- j0(|x|>X_TLOSS) *	35-- y0(x>X_TLOSS) *	36-- j1(|x|>X_TLOSS) *	37-- y1(x>X_TLOSS) *	38-- jn(|x|>X_TLOSS, n) *	39-- yn(x>X_TLOSS, n) *	40-- gamma(finite) overflow *	41-- gamma(-integer) *	42-- pow(NaN,0.0) */#ifdef __STDC__	double __kernel_standard(struct _reent *p, double x, double y,				 int type) #else	double __kernel_standard(p,x,y,type) 	struct _reent *p; double x,y; int type;#endif{	struct exception exc;#ifndef HUGE_VAL	/* this is the only routine that uses HUGE_VAL */ #define HUGE_VAL inf	double inf = 0.0;	SET_HIGH_WORD(inf,0x7ff00000);	/* set inf to infinite */#endif#ifdef _USE_WRITE	(void) fflush(_stdout_r(p));#endif	exc.arg1 = x;	exc.arg2 = y;	exc.err = 0;	switch(type) {	    case 1:	    case 101:		/* acos(|x|>1) */		exc.type = DOMAIN;		exc.name = type < 100 ? "acos" : "acosf";		exc.retval = zero;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if(_LIB_VERSION == _SVID_) {		    (void) WRITE2("acos: DOMAIN error\n", 19);		  }		  p->_errno = EDOM;		}		break;	    case 2:	    case 102:		/* asin(|x|>1) */		exc.type = DOMAIN;		exc.name = type < 100 ? "asin" : "asinf";		exc.retval = zero;		if(_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if(_LIB_VERSION == _SVID_) {		    	(void) WRITE2("asin: DOMAIN error\n", 19);		  }		  p->_errno = EDOM;		}		break;	    case 3:	    case 103:		/* atan2(+-0,+-0) */		exc.arg1 = y;		exc.arg2 = x;		exc.type = DOMAIN;		exc.name = type < 100 ? "atan2" : "atan2f";		exc.retval = zero;		if(_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if(_LIB_VERSION == _SVID_) {			(void) WRITE2("atan2: DOMAIN error\n", 20);		      }		  p->_errno = EDOM;		}		break;	    case 4:	    case 104:		/* hypot(finite,finite) overflow */		exc.type = OVERFLOW;		exc.name = type < 100 ? "hypot" : "hypotf";		if (_LIB_VERSION == _SVID_)		  exc.retval = HUGE;		else		  exc.retval = HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = ERANGE;		else if (!matherr(&exc)) {			p->_errno = ERANGE;		}		break;	    case 5:	    case 105:		/* cosh(finite) overflow */		exc.type = OVERFLOW;		exc.name = type < 100 ? "cosh" : "coshf";		if (_LIB_VERSION == _SVID_)		  exc.retval = HUGE;		else		  exc.retval = HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = ERANGE;		else if (!matherr(&exc)) {			p->_errno = ERANGE;		}		break;	    case 6:	    case 106:		/* exp(finite) overflow */		exc.type = OVERFLOW;		exc.name = type < 100 ? "exp" : "expf";		if (_LIB_VERSION == _SVID_)		  exc.retval = HUGE;		else		  exc.retval = HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = ERANGE;		else if (!matherr(&exc)) {			p->_errno = ERANGE;		}		break;	    case 7:	    case 107:		/* exp(finite) underflow */		exc.type = UNDERFLOW;		exc.name = type < 100 ? "exp" : "expf";		exc.retval = zero;		if (_LIB_VERSION == _POSIX_)		  p->_errno = ERANGE;		else if (!matherr(&exc)) {			p->_errno = ERANGE;		}		break;	    case 8:	    case 108:		/* y0(0) = -inf */		exc.type = DOMAIN;	/* should be SING for IEEE */		exc.name = type < 100 ? "y0" : "y0f";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("y0: DOMAIN error\n", 17);		      }		  p->_errno = EDOM;		}		break;	    case 9:	    case 109:		/* y0(x<0) = NaN */		exc.type = DOMAIN;		exc.name = type < 100 ? "y0" : "y0f";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("y0: DOMAIN error\n", 17);		      }		  p->_errno = EDOM;		}		break;	    case 10:	    case 110:		/* y1(0) = -inf */		exc.type = DOMAIN;	/* should be SING for IEEE */		exc.name = type < 100 ? "y1" : "y1f";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("y1: DOMAIN error\n", 17);		      }		  p->_errno = EDOM;		}		break;	    case 11:	    case 111:		/* y1(x<0) = NaN */		exc.type = DOMAIN;		exc.name = type < 100 ? "y1" : "y1f";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("y1: DOMAIN error\n", 17);		      }		  p->_errno = EDOM;		}		break;	    case 12:	    case 112:		/* yn(n,0) = -inf */		exc.type = DOMAIN;	/* should be SING for IEEE */		exc.name = type < 100 ? "yn" : "ynf";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("yn: DOMAIN error\n", 17);		      }		  p->_errno = EDOM;		}		break;	    case 13:	    case 113:		/* yn(x<0) = NaN */		exc.type = DOMAIN;		exc.name = type < 100 ? "yn" : "ynf";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("yn: DOMAIN error\n", 17);		      }		  p->_errno = EDOM;		}		break;	    case 14:	    case 114:		/* lgamma(finite) overflow */		exc.type = OVERFLOW;		exc.name = type < 100 ? "lgamma" : "lgammaf";                if (_LIB_VERSION == _SVID_)                  exc.retval = HUGE;                else                  exc.retval = HUGE_VAL;                if (_LIB_VERSION == _POSIX_)			p->_errno = ERANGE;                else if (!matherr(&exc)) {                        p->_errno = ERANGE;		}		break;	    case 15:	    case 115:		/* lgamma(-integer) or lgamma(0) */		exc.type = SING;		exc.name = type < 100 ? "lgamma" : "lgammaf";                if (_LIB_VERSION == _SVID_)                  exc.retval = HUGE;                else                  exc.retval = HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("lgamma: SING error\n", 19);		      }		  p->_errno = EDOM;		}		break;	    case 16:	    case 116:		/* log(0) */		exc.type = SING;		exc.name = type < 100 ? "log" : "logf";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = ERANGE;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("log: SING error\n", 16);		      }		  p->_errno = EDOM;		}		break;	    case 17:	    case 117:		/* log(x<0) */		exc.type = DOMAIN;		exc.name = type < 100 ? "log" : "logf";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else		  exc.retval = -HUGE_VAL;		if (_LIB_VERSION == _POSIX_)		  p->_errno = EDOM;		else if (!matherr(&exc)) {		  if (_LIB_VERSION == _SVID_) {			(void) WRITE2("log: DOMAIN error\n", 18);		      }		  p->_errno = EDOM;		}		break;	    case 18:	    case 118:		/* log10(0) */		exc.type = SING;		exc.name = type < 100 ? "log10" : "log10f";		if (_LIB_VERSION == _SVID_)		  exc.retval = -HUGE;		else

⌨️ 快捷键说明

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