[PATCH v2] Replace copysign (0,-1) with -0.0 in initializer

H.J. Lu hjl.tools@gmail.com
Mon Dec 16 21:18:23 GMT 2024


On Sat, Dec 14, 2024 at 7:29 PM Sam James <sam@gentoo.org> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> > GCC 4.9 issues an error for copysign in initializer:
> >
> > In file included from tst-printf-format-p-double.c:20:0:
> > tst-printf-format-skeleton-double.c:29:3: error: initializer element is not a constant expression [-Werror]
> >    { -HUGE_VAL, -DBL_MAX, -DBL_MIN, copysign (0, -1), -NAN, NAN, 0, DBL_MIN,
> >    ^
> >
> > since it can't fold "copysign (0, -1)".  Replace copysign (0,-1) with -0.0.
> >
> > Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> > ---
> >  stdio-common/tst-printf-format-skeleton-double.c  | 2 +-
> >  stdio-common/tst-printf-format-skeleton-ldouble.c | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/stdio-common/tst-printf-format-skeleton-double.c b/stdio-common/tst-printf-format-skeleton-double.c
> > index 03ac594736..19d75bbcbf 100644
> > --- a/stdio-common/tst-printf-format-skeleton-double.c
> > +++ b/stdio-common/tst-printf-format-skeleton-double.c
> > @@ -26,7 +26,7 @@
> >  #define PREC DBL_MANT_DIG
> >  typedef double type_t;
> >  static const type_t vals[] =
> > -  { -HUGE_VAL, -DBL_MAX, -DBL_MIN, copysign (0, -1), -NAN, NAN, 0, DBL_MIN,
> > +  { -HUGE_VAL, -DBL_MAX, -DBL_MIN, -0.0, -NAN, NAN, 0, DBL_MIN,
> >      DBL_MAX, HUGE_VAL };
> >  static const char length[] = "";
> >
> > diff --git a/stdio-common/tst-printf-format-skeleton-ldouble.c b/stdio-common/tst-printf-format-skeleton-ldouble.c
> > index ed47e77963..cb58f1ab15 100644
> > --- a/stdio-common/tst-printf-format-skeleton-ldouble.c
> > +++ b/stdio-common/tst-printf-format-skeleton-ldouble.c
> > @@ -27,7 +27,7 @@
> >  #define PREC LDBL_MANT_DIG
> >  typedef long double type_t;
> >  static const type_t vals[] =
> > -  { -HUGE_VAL, -LDBL_MAX, -LDBL_MIN, copysign (0, -1), -NAN, NAN, 0, LDBL_MIN,
> > +  { -HUGE_VAL, -LDBL_MAX, -LDBL_MIN, -0.0, -NAN, NAN, 0, LDBL_MIN,
> >      LDBL_MAX, HUGE_VAL };
> >  static const char length[] = "L";
>
> OK but let's see what Maciej says.

There are other places where -0.0 is used:

stdlib/strtod_l.c:      RETURN (negative ? -0.0 : 0.0,
stdlib/strtod_l.c:       RETURN (negative ? -0.0 : 0.0, tp);
stdlib/strtod_l.c:          result = negative ? -0.0 : 0.0;
stdlib/strtod_l.c:    return negative ? -0.0 : 0.0;

If there are no objections, I will check it tomorrow.

Thanks.

-- 
H.J.


More information about the Libc-alpha mailing list