--- str_format.c 2001/04/27 12:12:28 1.21
+++ str_format.c 2001/04/27 12:22:21 1.22
@@ -864,42 +864,61 @@
case 'e':
case 'E':
fp_num = va_arg(ap, double);
- /* We use &num_buf[1], so that we have room for the sign */
- s = conv_fp(*fmt, fp_num, alternate_form,
- (adjust_precision == FALSE) ? 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 (isnan(fp_num)) {
+ s = "NaN";
+ s_len = 3;
+ }
+ else if (isinf(fp_num)) {
+ s = "Inf";
+ s_len = 3;
+ }
+ else {
+ /* use &num_buf[1], so that we have room for the sign */
+ s = conv_fp(*fmt, fp_num, alternate_form,
+ (adjust_precision == FALSE) ? 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;
-
/* Double Floating Point (style 2) */
case 'g':
case 'G':
- if (adjust_precision == FALSE)
- precision = FLOAT_DIGITS;
- else if (precision == 0)
- precision = 1;
- /* We use &num_buf[1], so that we have room for the sign */
- s = str_gcvt(va_arg(ap, double), precision, &num_buf[1],
- alternate_form);
- if (*s == '-')
- prefix_char = *s++;
- else if (print_sign)
- prefix_char = '+';
- else if (print_blank)
- prefix_char = ' ';
- s_len = str_len(s);
- if (alternate_form && (q = str_span(s, 0, ".", 0)) == NULL) {
- s[s_len++] = '.';
- s[s_len] = NUL; /* delimit for following str_span() */
+ fp_num = va_arg(ap, double);
+ if (isnan(fp_num)) {
+ s = "NaN";
+ s_len = 3;
+ }
+ else if (isinf(fp_num)) {
+ s = "Inf";
+ s_len = 3;
+ }
+ else {
+ if (adjust_precision == FALSE)
+ precision = FLOAT_DIGITS;
+ else if (precision == 0)
+ precision = 1;
+ /* use &num_buf[1], so that we have room for the sign */
+ s = str_gcvt(fp_num, precision, &num_buf[1], alternate_form);
+ if (*s == '-')
+ prefix_char = *s++;
+ else if (print_sign)
+ prefix_char = '+';
+ else if (print_blank)
+ prefix_char = ' ';
+ s_len = str_len(s);
+ if (alternate_form && (q = str_span(s, 0, ".", 0)) == NULL) {
+ s[s_len++] = '.';
+ s[s_len] = NUL; /* delimit for following str_span() */
+ }
+ if (*fmt == 'G' && (q = str_span(s, 0, "e", 0)) != NULL)
+ *q = 'E';
}
- if (*fmt == 'G' && (q = str_span(s, 0, "e", 0)) != NULL)
- *q = 'E';
break;
/* Single Character */
|