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

📄 decimal_bin.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
			bi.bsignificand[0] |= 1;	/* If non-zero found,							 * stick it. */		bi.blength += nmove;		bi.bexponent -= 16 * nmove;		goto punpack;	}punpack:	ptounpacked->bsignificand[0] |= pd->more;	/* Stick in any lost							 * digits. */#ifdef DEBUG	printf(" merged bi and bf: ");	_display_big_float(ptounpacked, 2);#endif	_big_binary_to_unpacked(ptounpacked, px);ret:	return;}/* PUBLIC FUNCTIONS *//* * decimal_to_floating routines convert the decimal record at *pd to the * floating type item at *px, observing the modes specified in *pm and * setting exceptions in *ps. *  * pd->sign and pd->fpclass are always taken into account.  pd->exponent and * pd->ds are used when pd->fpclass is fp_normal or fp_subnormal. In these * cases pd->ds is expected to contain one or more ascii digits followed by a * null. px is set to a correctly rounded approximation to * (sign)*(ds)*10**(exponent) If pd->more != 0 then additional nonzero digits * are assumed to follow those in ds; fp_inexact is set accordingly. *  * Thus if pd->exponent == -2 and pd->ds = "1234", *px will get 12.34 rounded to * storage precision. *  * px is correctly rounded according to the IEEE rounding modes in pm->rd.  *ps * is set to contain fp_inexact, fp_underflow, or fp_overflow if any of these * arise. *  * pd->ndigits, pm->df, and pm->ndigits are never used. *  */voiddecimal_to_single(px, pm, pd, ps)	single         *px;	decimal_mode   *pm;	decimal_record *pd;	fp_exception_field_type *ps;{	single_equivalence kluge;	unpacked        u;	*ps = 0;		/* Initialize to no floating-point				 * exceptions. */	kluge.f.msw.sign = pd->sign ? 1 : 0;	switch (pd->fpclass) {	case fp_zero:		kluge.f.msw.exponent = 0;		kluge.f.msw.significand = 0;		break;	case fp_infinity:		kluge.f.msw.exponent = 0xff;		kluge.f.msw.significand = 0;		break;	case fp_quiet:		kluge.f.msw.exponent = 0xff;		kluge.f.msw.significand = 0x7fffff;		break;	case fp_signaling:		kluge.f.msw.exponent = 0xff;		kluge.f.msw.significand = 0x3fffff;		break;	default:		if (pd->exponent > SINGLE_MAXE) {	/* Guaranteed overflow. */			u.sign = pd->sign == 0 ? 0 : 1;			u.fpclass = fp_normal;			u.exponent = 0x000fffff;			u.significand[0] = 0x80000000;		} else if (pd->exponent >= -SINGLE_MAXE) {	/* Guaranteed in range. */			goto inrange;		} else if (pd->exponent <= (-SINGLE_MAXE - DECIMAL_STRING_LENGTH)) {	/* Guaranteed deep											 * underflow. */			goto underflow;		} else {	/* Deep underflow possible, depending on				 * string length. */			int             i;			for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - SINGLE_MAXE)); i++);			if (i < (-pd->exponent - SINGLE_MAXE)) {	/* Deep underflow */		underflow:				u.sign = pd->sign == 0 ? 0 : 1;				u.fpclass = fp_normal;				u.exponent = -0x000fffff;				u.significand[0] = 0x80000000;			} else {/* In range. */		inrange:				decimal_to_unpacked(&u, pd, 24);			}		}		_fp_current_exceptions = 0;		_fp_current_direction = pm->rd;		_pack_single(&u, &kluge.x);		*ps = _fp_current_exceptions;	}	*px = kluge.x;}voiddecimal_to_double(px, pm, pd, ps)	double         *px;	decimal_mode   *pm;	decimal_record *pd;	fp_exception_field_type *ps;{	double_equivalence kluge;	unpacked        u;	*ps = 0;		/* Initialize to no floating-point				 * exceptions. */	kluge.f.msw.sign = pd->sign ? 1 : 0;	switch (pd->fpclass) {	case fp_zero:		kluge.f.msw.exponent = 0;		kluge.f.msw.significand = 0;		kluge.f.significand2 = 0;		break;	case fp_infinity:		kluge.f.msw.exponent = 0x7ff;		kluge.f.msw.significand = 0;		kluge.f.significand2 = 0;		break;	case fp_quiet:		kluge.f.msw.exponent = 0x7ff;		kluge.f.msw.significand = 0xfffff;		kluge.f.significand2 = 0xffffffff;		break;	case fp_signaling:		kluge.f.msw.exponent = 0x7ff;		kluge.f.msw.significand = 0x7ffff;		kluge.f.significand2 = 0xffffffff;		break;	default:		if (pd->exponent > DOUBLE_MAXE) {	/* Guaranteed overflow. */			u.sign = pd->sign == 0 ? 0 : 1;			u.fpclass = fp_normal;			u.exponent = 0x000fffff;			u.significand[0] = 0x80000000;		} else if (pd->exponent >= -DOUBLE_MAXE) {	/* Guaranteed in range. */			goto inrange;		} else if (pd->exponent <= (-DOUBLE_MAXE - DECIMAL_STRING_LENGTH)) {	/* Guaranteed deep											 * underflow. */			goto underflow;		} else {	/* Deep underflow possible, depending on				 * string length. */			int             i;			for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - DOUBLE_MAXE)); i++);			if (i < (-pd->exponent - DOUBLE_MAXE)) {	/* Deep underflow */		underflow:				u.sign = pd->sign == 0 ? 0 : 1;				u.fpclass = fp_normal;				u.exponent = -0x000fffff;				u.significand[0] = 0x80000000;			} else {/* In range. */		inrange:				decimal_to_unpacked(&u, pd, 53);			}		}		_fp_current_exceptions = 0;		_fp_current_direction = pm->rd;		_pack_double(&u, &kluge.x);		*ps = _fp_current_exceptions;	}	*px = kluge.x;}voiddecimal_to_extended(px, pm, pd, ps)	extended       *px;	decimal_mode   *pm;	decimal_record *pd;	fp_exception_field_type *ps;{	extended_equivalence kluge;	unpacked        u;	*ps = 0;		/* Initialize to no floating-point				 * exceptions. */	kluge.f.msw.sign = pd->sign ? 1 : 0;	switch (pd->fpclass) {	case fp_zero:		kluge.f.msw.exponent = 0;		kluge.f.significand = 0;		kluge.f.significand2 = 0;		break;	case fp_infinity:		kluge.f.msw.exponent = 0x7fff;		kluge.f.significand = 0;		kluge.f.significand2 = 0;		break;	case fp_quiet:		kluge.f.msw.exponent = 0x7fff;		kluge.f.significand = 0xffffffff;		kluge.f.significand2 = 0xffffffff;		break;	case fp_signaling:		kluge.f.msw.exponent = 0x7fff;		kluge.f.significand = 0x3fffffff;		kluge.f.significand2 = 0xffffffff;		break;	default:		if (pd->exponent > EXTENDED_MAXE) {	/* Guaranteed overflow. */			u.sign = pd->sign == 0 ? 0 : 1;			u.fpclass = fp_normal;			u.exponent = 0x000fffff;			u.significand[0] = 0x80000000;		} else if (pd->exponent >= -EXTENDED_MAXE) {	/* Guaranteed in range. */			goto inrange;		} else if (pd->exponent <= (-EXTENDED_MAXE - DECIMAL_STRING_LENGTH)) {	/* Guaranteed deep											 * underflow. */			goto underflow;		} else {	/* Deep underflow possible, depending on				 * string length. */			int             i;			for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - EXTENDED_MAXE)); i++);			if (i < (-pd->exponent - EXTENDED_MAXE)) {	/* Deep underflow */		underflow:				u.sign = pd->sign == 0 ? 0 : 1;				u.fpclass = fp_normal;				u.exponent = -0x000fffff;				u.significand[0] = 0x80000000;			} else {/* In range. */		inrange:				decimal_to_unpacked(&u, pd, 64);			}		}		_fp_current_exceptions = 0;		_fp_current_direction = pm->rd;		_fp_current_precision = fp_extended;		_pack_extended(&u, px);		*ps = _fp_current_exceptions;		return;	}	(*px)[0] = kluge.x[0];	(*px)[1] = kluge.x[1];	(*px)[2] = kluge.x[2];}voiddecimal_to_quadruple(px, pm, pd, ps)	quadruple      *px;	decimal_mode   *pm;	decimal_record *pd;	fp_exception_field_type *ps;{	quadruple_equivalence kluge;	unpacked        u;	int             i;	*ps = 0;		/* Initialize to no floating-point				 * exceptions. */	kluge.f.msw.sign = pd->sign ? 1 : 0;	switch (pd->fpclass) {	case fp_zero:		kluge.f.msw.exponent = 0;		kluge.f.msw.significand = 0;		kluge.f.significand2 = 0;		kluge.f.significand3 = 0;		kluge.f.significand4 = 0;		break;	case fp_infinity:		kluge.f.msw.exponent = 0x7fff;		kluge.f.msw.significand = 0;		kluge.f.significand2 = 0;		kluge.f.significand3 = 0;		kluge.f.significand4 = 0;		break;	case fp_quiet:		kluge.f.msw.exponent = 0x7fff;		kluge.f.msw.significand = 0xffff;		kluge.f.significand2 = 0xffffffff;		kluge.f.significand3 = 0xffffffff;		kluge.f.significand4 = 0xffffffff;		break;	case fp_signaling:		kluge.f.msw.exponent = 0x7fff;		kluge.f.msw.significand = 0x7fff;		kluge.f.significand2 = 0xffffffff;		kluge.f.significand3 = 0xffffffff;		kluge.f.significand4 = 0xffffffff;		break;	default:		if (pd->exponent > QUAD_MAXE) {	/* Guaranteed overflow. */			u.sign = pd->sign == 0 ? 0 : 1;			u.fpclass = fp_normal;			u.exponent = 0x000fffff;			u.significand[0] = 0x80000000;		} else if (pd->exponent >= -QUAD_MAXE) {	/* Guaranteed in range. */			goto inrange;		} else if (pd->exponent <= (-QUAD_MAXE - DECIMAL_STRING_LENGTH)) {	/* Guaranteed deep											 * underflow. */			goto underflow;		} else {	/* Deep underflow possible, depending on				 * string length. */			for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - QUAD_MAXE)); i++);			if (i < (-pd->exponent - QUAD_MAXE)) {	/* Deep underflow */		underflow:				u.sign = pd->sign == 0 ? 0 : 1;				u.fpclass = fp_normal;				u.exponent = -0x000fffff;				u.significand[0] = 0x80000000;			} else {/* In range. */		inrange:				decimal_to_unpacked(&u, pd, 113);			}		}		_fp_current_exceptions = 0;		_fp_current_direction = pm->rd;		_pack_quadruple(&u, px);		*ps = _fp_current_exceptions;		return;	}	for (i = 0; i < 4; i++)		px->u[i] = kluge.x.u[i];}

⌨️ 快捷键说明

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