- Fix snprintf() to work with nan and inf properly

This commit is contained in:
Andi Gutmans 2001-05-01 16:29:52 +00:00
parent 78b54eaa8b
commit d04562e845

View File

@ -112,7 +112,8 @@ static char *
*/
if (fi != 0) {
p1 = &buf[NDIG];
while (fi != 0) {
// while (fi != 0) {
while (p1 > &buf[0] && fi != 0) {
fj = modf(fi / 10, &fi);
*--p1 = (int) ((fj + .03) * 10) + '0';
r2++;
@ -743,15 +744,23 @@ static int format_converter(register buffy * odp, const char *fmt,
case 'E':
fp_num = va_arg(ap, double);
s = conv_fp(*fmt, fp_num, alternate_form,
(adjust_precision == NO) ? FLOAT_DIGITS : precision,
&is_negative, &num_buf[1], &s_len);
if (is_negative)
prefix_char = '-';
else if (print_sign)
prefix_char = '+';
else if (print_blank)
prefix_char = ' ';
if (zend_isnan(fp_num)) {
s = "nan";
s_len = 3;
} else if (zend_isinf(fp_num)) {
s = "inf";
s_len = 3;
} else {
s = conv_fp(*fmt, fp_num, alternate_form,
(adjust_precision == NO) ? FLOAT_DIGITS : precision,
&is_negative, &num_buf[1], &s_len);
if (is_negative)
prefix_char = '-';
else if (print_sign)
prefix_char = '+';
else if (print_blank)
prefix_char = ' ';
}
break;