libc/include/complex.h: Add CMPLX, CMPLXF, and CMPLXL

Message ID 20240701205240.16456-1-joel@rtems.org
State New
Headers
Series libc/include/complex.h: Add CMPLX, CMPLXF, and CMPLXL |

Commit Message

Joel Sherrill July 1, 2024, 8:52 p.m. UTC
  ---
 newlib/libc/include/complex.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Comments

Andrew Pinski July 1, 2024, 8:58 p.m. UTC | #1
On Mon, Jul 1, 2024 at 1:53 PM Joel Sherrill <joel@rtems.org> wrote:
>
> ---
>  newlib/libc/include/complex.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
> index ad3028e4c..dbabdf67a 100644
> --- a/newlib/libc/include/complex.h
> +++ b/newlib/libc/include/complex.h
> @@ -16,6 +16,19 @@
>
>  __BEGIN_DECLS
>
> +/* Implementation from FreeBSD */
> +#if __ISO_C_VISIBLE >= 2011
> +#ifdef __clang__
> +#define        CMPLX(x, y)     ((double complex){ x, y })
> +#define        CMPLXF(x, y)    ((float complex){ x, y })
> +#define        CMPLXL(x, y)    ((long double complex){ x, y })
> +#elif __GNUC_PREREQ__(4, 7)
> +#define        CMPLX(x, y)     __builtin_complex((double)(x), (double)(y))
> +#define        CMPLXF(x, y)    __builtin_complex((float)(x), (float)(y))
> +#define        CMPLXL(x, y)    __builtin_complex((long double)(x), (long double)(y))

I only know this because I have been working with complex in the last
few weeks but __builtin_complex does not work with GCC's C++ front-end
(but it is not documented).
I don't know if you care about using this part of the header with C++
but I am just putting it out there.

Thanks,
Andrew Pinski

> +#endif
> +#endif /* __ISO_C_VISIBLE >= 2011 */
> +
>  /* 7.3.5 Trigonometric functions */
>  /* 7.3.5.1 The cacos functions */
>  double complex cacos(double complex);
> --
> 2.24.4
>
  
Joel Sherrill July 1, 2024, 9:51 p.m. UTC | #2
On Mon, Jul 1, 2024 at 3:58 PM Andrew Pinski <pinskia@gmail.com> wrote:

> On Mon, Jul 1, 2024 at 1:53 PM Joel Sherrill <joel@rtems.org> wrote:
> >
> > ---
> >  newlib/libc/include/complex.h | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> >
> > diff --git a/newlib/libc/include/complex.h
> b/newlib/libc/include/complex.h
> > index ad3028e4c..dbabdf67a 100644
> > --- a/newlib/libc/include/complex.h
> > +++ b/newlib/libc/include/complex.h
> > @@ -16,6 +16,19 @@
> >
> >  __BEGIN_DECLS
> >
> > +/* Implementation from FreeBSD */
> > +#if __ISO_C_VISIBLE >= 2011
> > +#ifdef __clang__
> > +#define        CMPLX(x, y)     ((double complex){ x, y })
> > +#define        CMPLXF(x, y)    ((float complex){ x, y })
> > +#define        CMPLXL(x, y)    ((long double complex){ x, y })
> > +#elif __GNUC_PREREQ__(4, 7)
> > +#define        CMPLX(x, y)     __builtin_complex((double)(x),
> (double)(y))
> > +#define        CMPLXF(x, y)    __builtin_complex((float)(x), (float)(y))
> > +#define        CMPLXL(x, y)    __builtin_complex((long double)(x),
> (long double)(y))
>
> I only know this because I have been working with complex in the last
> few weeks but __builtin_complex does not work with GCC's C++ front-end
> (but it is not documented).
> I don't know if you care about using this part of the header with C++
> but I am just putting it out there.


Will C++ see this since it is in __ISO_C_VISIBLE >= 2011?

Do you consider that an issue with GCC? I don't see these in a C++
standard.
Technically that means they shouldn't be visible.

And I am open to changing this if you think that there is an issue.

>
> Thanks,
> Andrew Pinski
>
> > +#endif
> > +#endif /* __ISO_C_VISIBLE >= 2011 */
> > +
> >  /* 7.3.5 Trigonometric functions */
> >  /* 7.3.5.1 The cacos functions */
> >  double complex cacos(double complex);
> > --
> > 2.24.4
> >
>
  
Andrew Pinski July 1, 2024, 9:56 p.m. UTC | #3
On Mon, Jul 1, 2024 at 2:51 PM Joel Sherrill <joel@rtems.org> wrote:
>
>
>
> On Mon, Jul 1, 2024 at 3:58 PM Andrew Pinski <pinskia@gmail.com> wrote:
>>
>> On Mon, Jul 1, 2024 at 1:53 PM Joel Sherrill <joel@rtems.org> wrote:
>> >
>> > ---
>> >  newlib/libc/include/complex.h | 13 +++++++++++++
>> >  1 file changed, 13 insertions(+)
>> >
>> > diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
>> > index ad3028e4c..dbabdf67a 100644
>> > --- a/newlib/libc/include/complex.h
>> > +++ b/newlib/libc/include/complex.h
>> > @@ -16,6 +16,19 @@
>> >
>> >  __BEGIN_DECLS
>> >
>> > +/* Implementation from FreeBSD */
>> > +#if __ISO_C_VISIBLE >= 2011
>> > +#ifdef __clang__
>> > +#define        CMPLX(x, y)     ((double complex){ x, y })
>> > +#define        CMPLXF(x, y)    ((float complex){ x, y })
>> > +#define        CMPLXL(x, y)    ((long double complex){ x, y })
>> > +#elif __GNUC_PREREQ__(4, 7)
>> > +#define        CMPLX(x, y)     __builtin_complex((double)(x), (double)(y))
>> > +#define        CMPLXF(x, y)    __builtin_complex((float)(x), (float)(y))
>> > +#define        CMPLXL(x, y)    __builtin_complex((long double)(x), (long double)(y))
>>
>> I only know this because I have been working with complex in the last
>> few weeks but __builtin_complex does not work with GCC's C++ front-end
>> (but it is not documented).
>> I don't know if you care about using this part of the header with C++
>> but I am just putting it out there.
>
>
> Will C++ see this since it is in __ISO_C_VISIBLE >= 2011?

I am not sure. I was more just warning about __builtin_complex rather
than anything else.

>
> Do you consider that an issue with GCC? I don't see these in a C++ standard.
> Technically that means they shouldn't be visible.

I did file https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107279 for
__builtin_complex support in the C++ front-end (a few years back
because I was working on the documentation at that point).

Thanks,
Andrew

>
> And I am open to changing this if you think that there is an issue.
>>
>>
>> Thanks,
>> Andrew Pinski
>>
>> > +#endif
>> > +#endif /* __ISO_C_VISIBLE >= 2011 */
>> > +
>> >  /* 7.3.5 Trigonometric functions */
>> >  /* 7.3.5.1 The cacos functions */
>> >  double complex cacos(double complex);
>> > --
>> > 2.24.4
>> >
  
Joel Sherrill July 1, 2024, 10:30 p.m. UTC | #4
On Mon, Jul 1, 2024 at 4:57 PM Andrew Pinski <pinskia@gmail.com> wrote:

> On Mon, Jul 1, 2024 at 2:51 PM Joel Sherrill <joel@rtems.org> wrote:
> >
> >
> >
> > On Mon, Jul 1, 2024 at 3:58 PM Andrew Pinski <pinskia@gmail.com> wrote:
> >>
> >> On Mon, Jul 1, 2024 at 1:53 PM Joel Sherrill <joel@rtems.org> wrote:
> >> >
> >> > ---
> >> >  newlib/libc/include/complex.h | 13 +++++++++++++
> >> >  1 file changed, 13 insertions(+)
> >> >
> >> > diff --git a/newlib/libc/include/complex.h
> b/newlib/libc/include/complex.h
> >> > index ad3028e4c..dbabdf67a 100644
> >> > --- a/newlib/libc/include/complex.h
> >> > +++ b/newlib/libc/include/complex.h
> >> > @@ -16,6 +16,19 @@
> >> >
> >> >  __BEGIN_DECLS
> >> >
> >> > +/* Implementation from FreeBSD */
> >> > +#if __ISO_C_VISIBLE >= 2011
> >> > +#ifdef __clang__
> >> > +#define        CMPLX(x, y)     ((double complex){ x, y })
> >> > +#define        CMPLXF(x, y)    ((float complex){ x, y })
> >> > +#define        CMPLXL(x, y)    ((long double complex){ x, y })
> >> > +#elif __GNUC_PREREQ__(4, 7)
> >> > +#define        CMPLX(x, y)     __builtin_complex((double)(x),
> (double)(y))
> >> > +#define        CMPLXF(x, y)    __builtin_complex((float)(x),
> (float)(y))
> >> > +#define        CMPLXL(x, y)    __builtin_complex((long double)(x),
> (long double)(y))
> >>
> >> I only know this because I have been working with complex in the last
> >> few weeks but __builtin_complex does not work with GCC's C++ front-end
> >> (but it is not documented).
> >> I don't know if you care about using this part of the header with C++
> >> but I am just putting it out there.
> >
> >
> > Will C++ see this since it is in __ISO_C_VISIBLE >= 2011?
>
> I am not sure. I was more just warning about __builtin_complex rather
> than anything else.
>

OK. I was just picking low hanging fruit as I was updating my Standards API
spreadsheet to include POSIX-2024 and see what RTEMS already supports.

Do you have an issue with this going in? If you don't, Jeff or Corinna
still need to bless it.

 don't see these in a C++ standard.
> > Technically that means they shouldn't be visible.
>
> I did file https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107279 for
> __builtin_complex support in the C++ front-end (a few years back
> because I was working on the documen


>

> > Do you consider that an issue with GCC? Itation at that point).
>

Maybe someone will implement it. It is open source. :)

--joel

>
> Thanks,
> Andrew
>
> >
> > And I am open to changing this if you think that there is an issue.
> >>
> >>
> >> Thanks,
> >> Andrew Pinski
> >>
> >> > +#endif
> >> > +#endif /* __ISO_C_VISIBLE >= 2011 */
> >> > +
> >> >  /* 7.3.5 Trigonometric functions */
> >> >  /* 7.3.5.1 The cacos functions */
> >> >  double complex cacos(double complex);
> >> > --
> >> > 2.24.4
> >> >
>
  
Corinna Vinschen July 3, 2024, 11:17 a.m. UTC | #5
On Jul  1 17:30, Joel Sherrill wrote:
> On Mon, Jul 1, 2024 at 4:57 PM Andrew Pinski <pinskia@gmail.com> wrote:
> 
> > On Mon, Jul 1, 2024 at 2:51 PM Joel Sherrill <joel@rtems.org> wrote:
> > >
> > >
> > >
> > > On Mon, Jul 1, 2024 at 3:58 PM Andrew Pinski <pinskia@gmail.com> wrote:
> > >>
> > >> On Mon, Jul 1, 2024 at 1:53 PM Joel Sherrill <joel@rtems.org> wrote:
> > >> >
> > >> > ---
> > >> >  newlib/libc/include/complex.h | 13 +++++++++++++
> > >> >  1 file changed, 13 insertions(+)
> > >> >
> > >> > diff --git a/newlib/libc/include/complex.h
> > b/newlib/libc/include/complex.h
> > >> > index ad3028e4c..dbabdf67a 100644
> > >> > --- a/newlib/libc/include/complex.h
> > >> > +++ b/newlib/libc/include/complex.h
> > >> > @@ -16,6 +16,19 @@
> > >> >
> > >> >  __BEGIN_DECLS
> > >> >
> > >> > +/* Implementation from FreeBSD */
> > >> > +#if __ISO_C_VISIBLE >= 2011
> > >> > +#ifdef __clang__
> > >> > +#define        CMPLX(x, y)     ((double complex){ x, y })
> > >> > +#define        CMPLXF(x, y)    ((float complex){ x, y })
> > >> > +#define        CMPLXL(x, y)    ((long double complex){ x, y })
> > >> > +#elif __GNUC_PREREQ__(4, 7)
> > >> > +#define        CMPLX(x, y)     __builtin_complex((double)(x),
> > (double)(y))
> > >> > +#define        CMPLXF(x, y)    __builtin_complex((float)(x),
> > (float)(y))
> > >> > +#define        CMPLXL(x, y)    __builtin_complex((long double)(x),
> > (long double)(y))
> > >>
> > >> I only know this because I have been working with complex in the last
> > >> few weeks but __builtin_complex does not work with GCC's C++ front-end
> > >> (but it is not documented).
> > >> I don't know if you care about using this part of the header with C++
> > >> but I am just putting it out there.
> > >
> > >
> > > Will C++ see this since it is in __ISO_C_VISIBLE >= 2011?
> >
> > I am not sure. I was more just warning about __builtin_complex rather
> > than anything else.
> >
> 
> OK. I was just picking low hanging fruit as I was updating my Standards API
> spreadsheet to include POSIX-2024 and see what RTEMS already supports.
> 
> Do you have an issue with this going in? If you don't, Jeff or Corinna
> still need to bless it.

GLibC uses the exact same feature test macros, so, LGTM, please push.

Andrew, if you have another change which you think is required for
newlib, just send a followup patch for discussion.


Thanks,
Corinna
  
Joel Sherrill July 3, 2024, 2 p.m. UTC | #6
Merged. Thanks.

On Wed, Jul 3, 2024 at 6:17 AM Corinna Vinschen <vinschen@redhat.com> wrote:

> On Jul  1 17:30, Joel Sherrill wrote:
> > On Mon, Jul 1, 2024 at 4:57 PM Andrew Pinski <pinskia@gmail.com> wrote:
> >
> > > On Mon, Jul 1, 2024 at 2:51 PM Joel Sherrill <joel@rtems.org> wrote:
> > > >
> > > >
> > > >
> > > > On Mon, Jul 1, 2024 at 3:58 PM Andrew Pinski <pinskia@gmail.com>
> wrote:
> > > >>
> > > >> On Mon, Jul 1, 2024 at 1:53 PM Joel Sherrill <joel@rtems.org>
> wrote:
> > > >> >
> > > >> > ---
> > > >> >  newlib/libc/include/complex.h | 13 +++++++++++++
> > > >> >  1 file changed, 13 insertions(+)
> > > >> >
> > > >> > diff --git a/newlib/libc/include/complex.h
> > > b/newlib/libc/include/complex.h
> > > >> > index ad3028e4c..dbabdf67a 100644
> > > >> > --- a/newlib/libc/include/complex.h
> > > >> > +++ b/newlib/libc/include/complex.h
> > > >> > @@ -16,6 +16,19 @@
> > > >> >
> > > >> >  __BEGIN_DECLS
> > > >> >
> > > >> > +/* Implementation from FreeBSD */
> > > >> > +#if __ISO_C_VISIBLE >= 2011
> > > >> > +#ifdef __clang__
> > > >> > +#define        CMPLX(x, y)     ((double complex){ x, y })
> > > >> > +#define        CMPLXF(x, y)    ((float complex){ x, y })
> > > >> > +#define        CMPLXL(x, y)    ((long double complex){ x, y })
> > > >> > +#elif __GNUC_PREREQ__(4, 7)
> > > >> > +#define        CMPLX(x, y)     __builtin_complex((double)(x),
> > > (double)(y))
> > > >> > +#define        CMPLXF(x, y)    __builtin_complex((float)(x),
> > > (float)(y))
> > > >> > +#define        CMPLXL(x, y)    __builtin_complex((long
> double)(x),
> > > (long double)(y))
> > > >>
> > > >> I only know this because I have been working with complex in the
> last
> > > >> few weeks but __builtin_complex does not work with GCC's C++
> front-end
> > > >> (but it is not documented).
> > > >> I don't know if you care about using this part of the header with
> C++
> > > >> but I am just putting it out there.
> > > >
> > > >
> > > > Will C++ see this since it is in __ISO_C_VISIBLE >= 2011?
> > >
> > > I am not sure. I was more just warning about __builtin_complex rather
> > > than anything else.
> > >
> >
> > OK. I was just picking low hanging fruit as I was updating my Standards
> API
> > spreadsheet to include POSIX-2024 and see what RTEMS already supports.
> >
> > Do you have an issue with this going in? If you don't, Jeff or Corinna
> > still need to bless it.
>
> GLibC uses the exact same feature test macros, so, LGTM, please push.
>
> Andrew, if you have another change which you think is required for
> newlib, just send a followup patch for discussion.
>
>
> Thanks,
> Corinna
>
>
  

Patch

diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
index ad3028e4c..dbabdf67a 100644
--- a/newlib/libc/include/complex.h
+++ b/newlib/libc/include/complex.h
@@ -16,6 +16,19 @@ 
 
 __BEGIN_DECLS
 
+/* Implementation from FreeBSD */
+#if __ISO_C_VISIBLE >= 2011
+#ifdef __clang__
+#define	CMPLX(x, y)	((double complex){ x, y })
+#define	CMPLXF(x, y)	((float complex){ x, y })
+#define	CMPLXL(x, y)	((long double complex){ x, y })
+#elif __GNUC_PREREQ__(4, 7)
+#define	CMPLX(x, y)	__builtin_complex((double)(x), (double)(y))
+#define	CMPLXF(x, y)	__builtin_complex((float)(x), (float)(y))
+#define	CMPLXL(x, y)	__builtin_complex((long double)(x), (long double)(y))
+#endif
+#endif /* __ISO_C_VISIBLE >= 2011 */
+
 /* 7.3.5 Trigonometric functions */
 /* 7.3.5.1 The cacos functions */
 double complex cacos(double complex);