]> granicus.if.org Git - php/commitdiff
- Fix snprintf() to work with nan and inf properly
authorAndi Gutmans <andi@php.net>
Tue, 1 May 2001 16:29:52 +0000 (16:29 +0000)
committerAndi Gutmans <andi@php.net>
Tue, 1 May 2001 16:29:52 +0000 (16:29 +0000)
main/snprintf.c

index b3afec1146509f3f6898e6c2269b85d56b883ebf..e4d42d5fff4079457b5be6bd55964c6e55df73dc 100644 (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;