Mercurial > hg > octave-lyh > gnulib-hg
changeset 8655:9a272158fe43
Faster determination of the sign of a number.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 06 Apr 2007 21:22:02 +0000 |
parents | a2bc90a7b7aa |
children | bc8e9c442bdb |
files | ChangeLog lib/vasnprintf.c modules/fprintf-posix modules/snprintf-posix modules/sprintf-posix modules/vasnprintf modules/vasnprintf-posix modules/vasprintf-posix modules/vfprintf-posix modules/vsnprintf-posix modules/vsprintf-posix |
diffstat | 11 files changed, 26 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-04-06 Bruno Haible <bruno@clisp.org> + + * lib/vasnprintf.c: Include <math.h>. Don't include float+.h. + (VASNPRINTF): Use signbit for faster determination whether to print a + minus sign. + * modules/vasnprintf (Files): Remove lib/float+.h. + * modules/fprintf-posix (Depends-on): Add signbit. + * modules/snprintf-posix (Depends-on): Likewise. + * modules/sprintf-posix (Depends-on): Likewise. + * modules/vasnprintf-posix (Depends-on): Likewise. + * modules/vasprintf-posix (Depends-on): Likewise. + * modules/vfprintf-posix (Depends-on): Likewise. + * modules/vsnprintf-posix (Depends-on): Likewise. + * modules/vsprintf-posix (Depends-on): Likewise. + 2007-04-06 Bruno Haible <bruno@clisp.org> * tests/test-frexp.c (main): Test also the sign bit of zero results.
--- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -54,7 +54,7 @@ #include "xsize.h" #if NEED_PRINTF_DIRECTIVE_A && !defined IN_LIBINTL -# include "float+.h" +# include <math.h> # include "isnan.h" # include "printf-frexp.h" # include "isnanl-nolibm.h" @@ -445,22 +445,11 @@ BEGIN_LONG_DOUBLE_ROUNDING (); - if (arg < 0.0L) + if (signbit (arg)) /* arg < 0.0L or negative zero */ { sign = -1; arg = -arg; } - else if (arg == 0.0L) - { - /* Distinguish 0.0L and -0.0L. */ - static long double plus_zero = 0.0L; - long double arg_mem = arg; - if (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0) - { - sign = -1; - arg = -arg; - } - } if (sign < 0) *p++ = '-'; @@ -590,22 +579,11 @@ { int sign = 0; - if (arg < 0.0) + if (signbit (arg)) /* arg < 0.0 or negative zero */ { sign = -1; arg = -arg; } - else if (arg == 0.0) - { - /* Distinguish 0.0 and -0.0. */ - static double plus_zero = 0.0; - double arg_mem = arg; - if (memcmp (&plus_zero, &arg_mem, SIZEOF_DBL) != 0) - { - sign = -1; - arg = -arg; - } - } if (sign < 0) *p++ = '-';
--- a/modules/fprintf-posix +++ b/modules/fprintf-posix @@ -14,6 +14,7 @@ isnanl-nolibm printf-frexp printf-frexpl +signbit fpucw configure.ac:
--- a/modules/snprintf-posix +++ b/modules/snprintf-posix @@ -13,6 +13,7 @@ isnanl-nolibm printf-frexp printf-frexpl +signbit fpucw configure.ac:
--- a/modules/sprintf-posix +++ b/modules/sprintf-posix @@ -13,6 +13,7 @@ isnanl-nolibm printf-frexp printf-frexpl +signbit fpucw configure.ac:
--- a/modules/vasnprintf +++ b/modules/vasnprintf @@ -6,7 +6,6 @@ lib/printf-args.c lib/printf-parse.h lib/printf-parse.c -lib/float+.h lib/vasnprintf.h lib/vasnprintf.c lib/asnprintf.c
--- a/modules/vasnprintf-posix +++ b/modules/vasnprintf-posix @@ -12,6 +12,7 @@ isnanl-nolibm printf-frexp printf-frexpl +signbit fpucw configure.ac:
--- a/modules/vasprintf-posix +++ b/modules/vasprintf-posix @@ -12,6 +12,7 @@ isnanl-nolibm printf-frexp printf-frexpl +signbit fpucw configure.ac:
--- a/modules/vfprintf-posix +++ b/modules/vfprintf-posix @@ -14,6 +14,7 @@ isnanl-nolibm printf-frexp printf-frexpl +signbit fpucw configure.ac: