diff options
| author | Paul Eggert | 2017-03-03 08:45:10 -0800 |
|---|---|---|
| committer | Paul Eggert | 2017-03-03 08:46:11 -0800 |
| commit | f1fe3fcfc568c1527714ff3a95e678816e2787d4 (patch) | |
| tree | bfe4792f57ae62222ba05b3c4d69706f3e83b212 /lib | |
| parent | aaf86f30f709b22e9bae8cdb23ec89342dcaa55f (diff) | |
| download | emacs-f1fe3fcfc568c1527714ff3a95e678816e2787d4.tar.gz emacs-f1fe3fcfc568c1527714ff3a95e678816e2787d4.zip | |
Merge from gnulib
This incorporates:
2017-02-25 maintainer-makefile: Fix AC_PROG_SED with autoconf cache.
2017-02-24 ftoastr: port to -Wdouble-promotion
* lib/ftoastr.c, m4/gnulib-common.m4: Copy from gnulib.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ftoastr.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/ftoastr.c b/lib/ftoastr.c index 826340c3f77..ef861e2237a 100644 --- a/lib/ftoastr.c +++ b/lib/ftoastr.c | |||
| @@ -39,6 +39,7 @@ | |||
| 39 | # define FLOAT_MIN LDBL_MIN | 39 | # define FLOAT_MIN LDBL_MIN |
| 40 | # define FLOAT_PREC_BOUND _GL_LDBL_PREC_BOUND | 40 | # define FLOAT_PREC_BOUND _GL_LDBL_PREC_BOUND |
| 41 | # define FTOASTR ldtoastr | 41 | # define FTOASTR ldtoastr |
| 42 | # define PROMOTED_FLOAT long double | ||
| 42 | # if HAVE_C99_STRTOLD | 43 | # if HAVE_C99_STRTOLD |
| 43 | # define STRTOF strtold | 44 | # define STRTOF strtold |
| 44 | # endif | 45 | # endif |
| @@ -48,6 +49,7 @@ | |||
| 48 | # define FLOAT_MIN DBL_MIN | 49 | # define FLOAT_MIN DBL_MIN |
| 49 | # define FLOAT_PREC_BOUND _GL_DBL_PREC_BOUND | 50 | # define FLOAT_PREC_BOUND _GL_DBL_PREC_BOUND |
| 50 | # define FTOASTR dtoastr | 51 | # define FTOASTR dtoastr |
| 52 | # define PROMOTED_FLOAT double | ||
| 51 | #else | 53 | #else |
| 52 | # define LENGTH 1 | 54 | # define LENGTH 1 |
| 53 | # define FLOAT float | 55 | # define FLOAT float |
| @@ -55,6 +57,7 @@ | |||
| 55 | # define FLOAT_MIN FLT_MIN | 57 | # define FLOAT_MIN FLT_MIN |
| 56 | # define FLOAT_PREC_BOUND _GL_FLT_PREC_BOUND | 58 | # define FLOAT_PREC_BOUND _GL_FLT_PREC_BOUND |
| 57 | # define FTOASTR ftoastr | 59 | # define FTOASTR ftoastr |
| 60 | # define PROMOTED_FLOAT double | ||
| 58 | # if HAVE_STRTOF | 61 | # if HAVE_STRTOF |
| 59 | # define STRTOF strtof | 62 | # define STRTOF strtof |
| 60 | # endif | 63 | # endif |
| @@ -77,20 +80,21 @@ static int | |||
| 77 | ftoastr_snprintf (char *buf, size_t bufsize, char const *format, | 80 | ftoastr_snprintf (char *buf, size_t bufsize, char const *format, |
| 78 | int width, int prec, FLOAT x) | 81 | int width, int prec, FLOAT x) |
| 79 | { | 82 | { |
| 83 | PROMOTED_FLOAT promoted_x = x; | ||
| 80 | char width_0_buffer[LENGTH == 1 ? FLT_BUFSIZE_BOUND | 84 | char width_0_buffer[LENGTH == 1 ? FLT_BUFSIZE_BOUND |
| 81 | : LENGTH == 2 ? DBL_BUFSIZE_BOUND | 85 | : LENGTH == 2 ? DBL_BUFSIZE_BOUND |
| 82 | : LDBL_BUFSIZE_BOUND]; | 86 | : LDBL_BUFSIZE_BOUND]; |
| 83 | int n = width; | 87 | int n = width; |
| 84 | if (bufsize < sizeof width_0_buffer) | 88 | if (bufsize < sizeof width_0_buffer) |
| 85 | { | 89 | { |
| 86 | n = sprintf (width_0_buffer, format, 0, prec, x); | 90 | n = sprintf (width_0_buffer, format, 0, prec, promoted_x); |
| 87 | if (n < 0) | 91 | if (n < 0) |
| 88 | return n; | 92 | return n; |
| 89 | if (n < width) | 93 | if (n < width) |
| 90 | n = width; | 94 | n = width; |
| 91 | } | 95 | } |
| 92 | if (n < bufsize) | 96 | if (n < bufsize) |
| 93 | n = sprintf (buf, format, width, prec, x); | 97 | n = sprintf (buf, format, width, prec, promoted_x); |
| 94 | return n; | 98 | return n; |
| 95 | } | 99 | } |
| 96 | #endif | 100 | #endif |
| @@ -106,6 +110,7 @@ FTOASTR (char *buf, size_t bufsize, int flags, int width, FLOAT x) | |||
| 106 | <http://dx.doi.org/10.1145/1809028.1806623>; also see the | 110 | <http://dx.doi.org/10.1145/1809028.1806623>; also see the |
| 107 | 2010-03-21 draft <http://florian.loitsch.com/tmp/article.pdf>. */ | 111 | 2010-03-21 draft <http://florian.loitsch.com/tmp/article.pdf>. */ |
| 108 | 112 | ||
| 113 | PROMOTED_FLOAT promoted_x = x; | ||
| 109 | char format[sizeof "%-+ 0*.*Lg"]; | 114 | char format[sizeof "%-+ 0*.*Lg"]; |
| 110 | FLOAT abs_x = x < 0 ? -x : x; | 115 | FLOAT abs_x = x < 0 ? -x : x; |
| 111 | int prec; | 116 | int prec; |
| @@ -128,7 +133,7 @@ FTOASTR (char *buf, size_t bufsize, int flags, int width, FLOAT x) | |||
| 128 | 133 | ||
| 129 | for (prec = abs_x < FLOAT_MIN ? 1 : FLOAT_DIG; ; prec++) | 134 | for (prec = abs_x < FLOAT_MIN ? 1 : FLOAT_DIG; ; prec++) |
| 130 | { | 135 | { |
| 131 | int n = snprintf (buf, bufsize, format, width, prec, x); | 136 | int n = snprintf (buf, bufsize, format, width, prec, promoted_x); |
| 132 | if (n < 0 | 137 | if (n < 0 |
| 133 | || FLOAT_PREC_BOUND <= prec | 138 | || FLOAT_PREC_BOUND <= prec |
| 134 | || (n < bufsize && STRTOF (buf, NULL) == x)) | 139 | || (n < bufsize && STRTOF (buf, NULL) == x)) |