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

📄 _fpmaxtostr.c

📁 Axis 221 camera embedded programing interface
💻 C
📖 第 1 页 / 共 2 页
字号:
		}		j >>= 1;	} while (i);	if (x >= upper_bnd) {		/* Handle bad rounding case. */		x /= power_table[0];		++exp;	}	assert(x < upper_bnd); GENERATE_DIGITS:	s = buf + 2;				/* Leave space for '\0' and '0'. */	i = 0;	do {		digit_block = (uint_fast32_t) x;		assert(digit_block < upper_bnd);#ifdef __UCLIBC_MJN3_ONLY__#warning CONSIDER: Can rounding be a problem?#endif /* __UCLIBC_MJN3_ONLY__ */		x = (x - digit_block) * upper_bnd;		s += dpb;		j = 0;		do {			s[- ++j] = '0' + (digit_block % base);			digit_block /= base;		} while (j < dpb);	} while (++i < ndb);	/*************************************************************************/	if (mode < 'a') {		*exp_buf -= ('a' - 'A'); /* e->E and p->P */		mode += ('a' - 'A');	} 	o_mode = mode;	if ((mode == 'g') && (preci > 0)){		--preci;	}	round = preci;	if (mode == 'f') {		round += exp;		if (round < -1) {			memset(buf, '0', DECIMAL_DIG); /* OK, since 'f' -> decimal case. */		    exp = -1;		    round = -1;		}	}	s = buf;	*s++ = 0;					/* Terminator for rounding and 0-triming. */	*s = '0';					/* Space to round. */	i = 0;	e = s + nd + 1;	if (round < nd) {		e = s + round + 2;		if (*e >= '0' + (base/2)) {	/* NOTE: We always round away from 0! */			i = 1;		}	}	do {						/* Handle rounding and trim trailing 0s. */		*--e += i;				/* Add the carry. */	} while ((*e == '0') || (*e > '0' - 1 + base));#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__	if ((mode|0x20) == 'a') {		char *q;					for (q = e ; *q ; --q) {			if (*q > '9') {				*q += (*exp_buf - ('p' - 'a') - '9' - 1);			}		}		if (e > s) {			exp *= 4;			/* Change from base 16 to base 2. */		}	}#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */	o_exp = exp;	if (e <= s) {				/* We carried into an extra digit. */		++o_exp;		e = s;					/* Needed if all 0s. */	} else {		++s;	}	*++e = 0;					/* Terminating nul char. */	if ((mode == 'g') && ((o_exp >= -4) && (o_exp <= round))) {		mode = 'f';		preci = round - o_exp;	}	exp = o_exp;	if (mode != 'f') {		o_exp = 0;	}	if (o_exp < 0) {			/* Exponent is < 0, so */		*--s = '0';				/* fake the first 0 digit. */	}	pc_fwi[3] = FPO_ZERO_PAD;	pc_fwi[4] = 1;	pc_fwi[5] = (intptr_t)(sign_str + 4);	sign_str[4] = *s++;	sign_str[5] = 0;	ppc = pc_fwi + 6;	i = e - s;					/* Total digits is 'i'. */	if (o_exp >= 0) {#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__		const char *p;		if (PRINT_INFO_FLAG_VAL(info,group)			&& *(p = __UCLIBC_CURLOCALE_DATA.grouping)			) {			int nblk1;			nblk2 = nblk1 = *p;			if (*++p) {				nblk2 = *p;				assert(!*++p);			}			if (o_exp >= nblk1) {				num_groups = (o_exp - nblk1) / nblk2 + 1;				initial_group = (o_exp - nblk1) % nblk2;#ifdef __UCLIBC_HAS_WCHAR__				if (PRINT_INFO_FLAG_VAL(info,wide)) {					/* _fp_out_wide() will fix this up. */					ts = fmt + THOUSEP_OFFSET;					tslen = 1;				} else {#endif /* __UCLIBC_HAS_WCHAR__ */					ts = __UCLIBC_CURLOCALE_DATA.thousands_sep;					tslen = __UCLIBC_CURLOCALE_DATA.thousands_sep_len;#ifdef __UCLIBC_HAS_WCHAR__				}#endif /* __UCLIBC_HAS_WCHAR__ */				width -= num_groups * tslen;			}		}#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */		ppc[0] = FPO_STR_PREC;		ppc[2] = (intptr_t)(s);		if (o_exp >= i) {		/* all digit(s) left of decimal */			ppc[1] = i;			ppc += 3;			o_exp -= i;			i = 0;			if (o_exp>0) {		/* have 0s left of decimal */				ppc[0] = FPO_ZERO_PAD;				ppc[1] = o_exp;				ppc[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);				ppc += 3;			}		} else if (o_exp > 0) {	/* decimal between digits */			ppc[1] = o_exp;			ppc += 3;			s += o_exp;			i -= o_exp;		}		o_exp = -1;	}	if (PRINT_INFO_FLAG_VAL(info,alt)		|| (i)		|| ((o_mode != 'g')#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__			&& (o_mode != 'a')#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */			&& (preci > 0))		) {		ppc[0] = FPO_STR_PREC;#ifdef __LOCALE_C_ONLY		ppc[1] = 1;		ppc[2] = (intptr_t)(fmt + DECPT_OFFSET);#else  /* __LOCALE_C_ONLY */#ifdef __UCLIBC_HAS_WCHAR__			if (PRINT_INFO_FLAG_VAL(info,wide)) {				/* _fp_out_wide() will fix this up. */				ppc[1] = 1;				ppc[2] = (intptr_t)(fmt + DECPT_OFFSET);			} else {#endif /* __UCLIBC_HAS_WCHAR__ */				ppc[1] = __UCLIBC_CURLOCALE_DATA.decimal_point_len;				ppc[2] = (intptr_t)(__UCLIBC_CURLOCALE_DATA.decimal_point);#ifdef __UCLIBC_HAS_WCHAR__			}#endif /* __UCLIBC_HAS_WCHAR__ */#endif /* __LOCALE_C_ONLY */			ppc += 3;	}	if (++o_exp < 0) {			/* Have 0s right of decimal. */		ppc[0] = FPO_ZERO_PAD;		ppc[1] = -o_exp;		ppc[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);		ppc += 3;	}	if (i) {					/* Have digit(s) right of decimal. */		ppc[0] = FPO_STR_PREC;		ppc[1] = i;		ppc[2] = (intptr_t)(s);		ppc += 3;	}	if (((o_mode != 'g') || PRINT_INFO_FLAG_VAL(info,alt))#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__		&& !sufficient_precision#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */		) {		i -= o_exp;		if (i < preci) {		/* Have 0s right of digits. */			i = preci - i;			ppc[0] = FPO_ZERO_PAD;			ppc[1] = i;			ppc[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);			ppc += 3;		}	}	/* Build exponent string. */	if (mode != 'f') {		char *p = exp_buf + sizeof(exp_buf);		char exp_char = *exp_buf;		char exp_sign = '+';#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__		int min_exp_dig_plus_2 = ((o_mode != 'a') ? (2+2) : (2+1));#else  /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */#define min_exp_dig_plus_2  (2+2)#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */		if (exp < 0) {			exp_sign = '-';			exp = -exp;		}		*--p = 0;			/* nul-terminate */		j = 2;				/* Count exp_char and exp_sign. */		do {			*--p = '0' + (exp % 10);			exp /= 10;		} while ((++j < min_exp_dig_plus_2) || exp); /* char+sign+mindigits */		*--p = exp_sign;		*--p = exp_char;		ppc[0] = FPO_STR_PREC;		ppc[1] = j;		ppc[2] = (intptr_t)(p);		ppc += 3;	} EXIT_SPECIAL:	ppc_last = ppc;	ppc = pc_fwi + 4;	 /* Need width fields starting with second. */	do {		width -= *ppc;		ppc += 3;	} while (ppc < ppc_last);	ppc = pc_fwi;	ppc[0] = FPO_STR_WIDTH;	ppc[1] = i = ((*sign_str) != 0);	ppc[2] = (intptr_t) sign_str;#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__	if (((mode|0x20) == 'a') && (pc_fwi[3] >= 16)) { /* Hex sign handling. */		/* Hex and not inf or nan, so prefix with 0x. */		char *h = sign_str + i;		*h = '0';		*++h = 'x' - 'p' + *exp_buf;		*++h = 0;		ppc[1] = (i += 2);	}#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */	if ((width -= i) > 0) {		if (PRINT_INFO_FLAG_VAL(info,left)) { /* Left-justified. */			ppc_last[0] = FPO_STR_WIDTH;			ppc_last[1] = width;			ppc_last[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);			ppc_last += 3;		} else if (info->pad == '0') { /* 0 padding */			ppc[4] += width;	/* Pad second field. */		} else {			ppc[1] += width;	/* Pad first (sign) field. */		}	}	cnt = 0;	do {#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__		if ((ppc == pc_fwi + 6) && num_groups) {			const char *gp = (const char *) ppc[2];			int len = ppc[1];			int blk = initial_group;			cnt += num_groups * tslen; /* Adjust count now for sep chars. *//* 			printf("\n"); */			do {				if (!blk) {		/* Initial group could be 0 digits long! */					blk = nblk2;				} else if (len >= blk) { /* Enough digits for a group. *//* 					printf("norm:  len=%d blk=%d  \"%.*s\"\n", len, blk, blk, gp); */					fp_outfunc(fp, *ppc, blk, (intptr_t) gp);					assert(gp);					if (*gp) {						gp += blk;					}					len -= blk;				} else {		/* Transition to 0s. *//* 					printf("trans: len=%d blk=%d  \"%.*s\"\n", len, blk, len, gp); */					if (len) {/* 						printf("len\n"); */						fp_outfunc(fp, *ppc, len, (intptr_t) gp);						gp += len;					}					if (ppc[3] == FPO_ZERO_PAD) { /* Need to group 0s *//* 						printf("zeropad\n"); */						cnt += ppc[1];						ppc += 3;						gp = (const char *) ppc[2];						blk -= len;	/* blk > len, so blk still > 0. */						len = ppc[1];						continue; /* Don't decrement num_groups here. */					} else {						assert(num_groups == 0);						break;					}				}				if (num_groups <= 0) {					break;				}				--num_groups;				fp_outfunc(fp, FPO_STR_PREC, tslen, (intptr_t) ts);				blk = nblk2;/* 				printf("num_groups=%d   blk=%d\n", num_groups, blk); */			} while (1);		} else#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */		fp_outfunc(fp, *ppc, ppc[1], ppc[2]); /* NOTE: Remember 'else' above! */		cnt += ppc[1];		ppc += 3;	} while (ppc < ppc_last);	return cnt;}

⌨️ 快捷键说明

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