Bug 216862 - C11 conformance: cexpl() is missing
Summary: C11 conformance: cexpl() is missing
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on: 235413
Blocks:
  Show dependency treegraph
 
Reported: 2017-02-06 19:45 UTC by sgk
Modified: 2022-04-02 12:08 UTC (History)
6 users (show)

See Also:


Attachments
Implementations of cexpl(). (4.77 KB, patch)
2021-11-05 01:04 UTC, Steve Kargl
no flags Details | Diff
new diff (4.77 KB, patch)
2021-11-05 02:27 UTC, Steve Kargl
no flags Details | Diff
next new diff (15.55 KB, patch)
2021-11-05 04:22 UTC, Steve Kargl
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description sgk 2017-02-06 19:45:22 UTC
#include <complex.h>
long double complex
foo(long double complex z)
{
   return (cexpl(z));
}

cc -c foo.c
foo.c:7:12: warning: implicitly declaring library function 'cexpl' with type
      '_Complex long double (_Complex long double)'
      [-Wimplicit-function-declaration]
   return (cexpl(z));
           ^
foo.c:7:12: note: include the header <complex.h> or explicitly provide a
      declaration for 'cexpl'
1 warning generated.
Comment 1 Sebastian Schwarz 2017-06-25 14:25:05 UTC
Isn't cexpl() already mandated by C99?  There are also a number of other functions missing from complex.h.  See bug #175811.

It looks like Dragonfly-, Net- and OpenBSD already have implementations of cexpl().  Maybe their code could be imported?
Comment 2 Steve Kargl freebsd_committer freebsd_triage 2021-11-05 01:04:43 UTC
Created attachment 229279 [details]
Implementations of cexpl().

The attached diff implements cexpl() for both ld80 and ld128 architectures.
Testing was done on x86_64 and aarch64 systems.

Along the way sincos[fl]() use an optimization that reduces the argument
to being done one rather than twice.  This optimization actually pointed
to a bug in the ld128 version of sincosl(), which is now fixed.  In 
addition, the minmax polynomial coefficients for sincosl() have been
updated.

A concise log of the file-by-file changes follows.


* include/complex.h:
  . Add a prototype for cexpl().

* lib/msun/Makefile:
  . Add s_cexpl.c to the build.
  . Setup a link for cexpl.3 to cexp.3.

* lib/msun/Symbol.map:
  . Expose cexpl symbol in libm shared library.

* lib/msun/ld128/s_cexpl.c:
  * Implementation of cexpl() for 128-bit long double architectures.
    Tested on an aarch64 system.

* lib/msun/ld80/s_cexpl.c:
  * Implementation of cexpl() for Intel 80-bit long double.

* lib/msun/man/cexp.3:
  . Document cexpl().

* lib/msun/man/complex.3:
  . Add a BUGS section about cpow[fl].

* lib/msun/src/s_cexp.c:
  . Include float.h for weak references on 53-bit long double targets.
  . Use sincos() to reduce argument reduction cost.

* lib/msun/src/s_cexpf.c:
  . Use sincosf() to reduce argument reduction cost.

* lib/msun/src/k_sincosl.h:
  . Catch up with the new minmax polynomial coefficients for the kernel for
    the 128-bit cosl() implementation.
  . BUG FIX: *cs was used where *sn should have been.  This means that sinl()
    was no computed correctly when iy != 0.

* lib/msun/src/s_cosl.c:
  . Include fpmath.h to get access to IEEEl2bits.
  . Replace M_PI_4 with pio4,  a 64-bit or 113-bit approximation for pi / 4.
Comment 3 Konstantin Belousov freebsd_committer freebsd_triage 2021-11-05 02:03:18 UTC
(In reply to Steve Kargl from comment #2)
For me it looks like s_cexpl.c is missed from the diff.
Comment 4 Steve Kargl freebsd_committer freebsd_triage 2021-11-05 02:27:15 UTC
Created attachment 229281 [details]
new diff

That's what happens when 15 years of corporate
knowledge are tossed to the wayside for new 
shine technology.  Blame it on git.

Apparently, git does pick up new files

% git add ld80/s_cexpl.c
% git add ld128/s_cexpl.c
% git diff > cexpl.diff

like

% svn add ld80/s_cexpl.c
% svn add ld128/s_cexpl.c
% svn diff > cexpl.diff


Hopefully, the hand edited diff to remove unrelated diffs is okay.
Comment 5 Steve Kargl freebsd_committer freebsd_triage 2021-11-05 02:29:48 UTC
Whoops.  Should read "git does NOT pick up new files."
Comment 6 Warner Losh freebsd_committer freebsd_triage 2021-11-05 03:03:05 UTC
(In reply to Steve Kargl from comment #5)
It does pickup new files....

However, it's complicated. 'git add' puts the file into a logical staging area, and git diff excludes those not-yet-committed-but-in-the-staging-area files by defualt.

git diff --staged will get them, but it's not so straight forward to use.

But 'git diff HEAD' often will as well, but there's some edge cases that I can't recall right now.

You're better off doing a 'git checkout -b new-bug' and committing it. Then you can create your diff with 'git diff main' or better yet, you can create a patch with all the commit data: your name, the commit message, etc' with 'git format-patch --stdout main..new-bug > patch-file-to-upload-to-bugizlla'. This will produce output that's suitable for others to use 'git am' to just snarf it it into the tree. Without the --stdout, it will create a bunch of numbered files, one per commit which is something you might not want.

Then, you can do a 'git checkout main' and get back to the pristine tree. If time passes and you need to make a change, you can update your local main, then use 'git rebase -i main new-bug' and it will move the change forward to the tip of the FreeBSD tree, which will let you resolve any conflicts that may have cropped up. git rebase also lets you curate patches since you can reword the commit message, split apart commits, or combine different ones depending on what's needed.

The other option is to create a pull request on github, which some find easier, though the first time setup can be a bit weird.
Comment 7 Konstantin Belousov freebsd_committer freebsd_triage 2021-11-05 03:24:18 UTC
(In reply to Steve Kargl from comment #5)
There is still no new file in the diff.  Please attach it directly to the PR.
Comment 8 Steve Kargl freebsd_committer freebsd_triage 2021-11-05 04:22:49 UTC
Created attachment 229283 [details]
next new diff

Third times a charm?
Comment 9 commit-hook freebsd_committer freebsd_triage 2021-11-05 11:53:43 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=046e2d5db1e8afd2d09ea28e5d2a7550535d4b77

commit 046e2d5db1e8afd2d09ea28e5d2a7550535d4b77
Author:     Steve Kargl <kargl@FreeBSD.org>
AuthorDate: 2021-11-05 02:04:01 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-11-05 11:51:42 +0000

    Implementations of cexpl()

    The change implements cexpl() for both ld80 and ld128 architectures.
    Testing was done on x86_64 and aarch64 systems.

    Along the way sincos[fl]() use an optimization that reduces the argument
    to being done one rather than twice.  This optimization actually pointed
    to a bug in the ld128 version of sincosl(), which is now fixed.  In
    addition, the minmax polynomial coefficients for sincosl() have been
    updated.

    A concise log of the file-by-file changes follows.

    * include/complex.h:
      . Add a prototype for cexpl().

    * lib/msun/Makefile:
      . Add s_cexpl.c to the build.
      . Setup a link for cexpl.3 to cexp.3.

    * lib/msun/Symbol.map:
      . Expose cexpl symbol in libm shared library.

    * lib/msun/ld128/s_cexpl.c:
      * Implementation of cexpl() for 128-bit long double architectures.
        Tested on an aarch64 system.

    * lib/msun/ld80/s_cexpl.c:
      * Implementation of cexpl() for Intel 80-bit long double.

    * lib/msun/man/cexp.3:
      . Document cexpl().

    * lib/msun/man/complex.3:
      . Add a BUGS section about cpow[fl].

    * lib/msun/src/s_cexp.c:
      . Include float.h for weak references on 53-bit long double targets.
      . Use sincos() to reduce argument reduction cost.

    * lib/msun/src/s_cexpf.c:
      . Use sincosf() to reduce argument reduction cost.

    * lib/msun/src/k_sincosl.h:
      . Catch up with the new minmax polynomial coefficients for the kernel for
        the 128-bit cosl() implementation.
      . BUG FIX: *cs was used where *sn should have been.  This means that sinl()
        was no computed correctly when iy != 0.

    * lib/msun/src/s_cosl.c:
      . Include fpmath.h to get access to IEEEl2bits.
      . Replace M_PI_4 with pio4,  a 64-bit or 113-bit approximation for pi / 4.

    PR:     216862
    MFC after:      1 week

 include/complex.h              |   2 +
 lib/msun/Makefile              |   4 +-
 lib/msun/Symbol.map            |   1 +
 lib/msun/ld128/s_cexpl.c (new) |  94 ++++++++++++++++++++++++++++++++++++
 lib/msun/ld80/s_cexpl.c (new)  | 107 +++++++++++++++++++++++++++++++++++++++++
 lib/msun/man/cexp.3            |  17 ++++---
 lib/msun/man/complex.3         |   8 ++-
 lib/msun/src/k_sincosl.h       |  29 ++++++-----
 lib/msun/src/s_cexp.c          |  16 ++++--
 lib/msun/src/s_cexpf.c         |  11 +++--
 lib/msun/src/s_cosl.c          |   7 ++-
 11 files changed, 265 insertions(+), 31 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2021-11-10 19:37:20 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4ac2d43111f005ea8a326dc30fcf4df522bcf661

commit 4ac2d43111f005ea8a326dc30fcf4df522bcf661
Author:     Steve Kargl <kargl@FreeBSD.org>
AuthorDate: 2021-11-05 02:04:01 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-11-10 19:36:20 +0000

    Implementations of cexpl()

    PR:     216862

    (cherry picked from commit 046e2d5db1e8afd2d09ea28e5d2a7550535d4b77)

 include/complex.h              |   2 +
 lib/msun/Makefile              |   4 +-
 lib/msun/Symbol.map            |   1 +
 lib/msun/ld128/s_cexpl.c (new) |  94 ++++++++++++++++++++++++++++++++++++
 lib/msun/ld80/s_cexpl.c (new)  | 107 +++++++++++++++++++++++++++++++++++++++++
 lib/msun/man/cexp.3            |  17 ++++---
 lib/msun/man/complex.3         |   8 ++-
 lib/msun/src/k_sincosl.h       |  29 ++++++-----
 lib/msun/src/s_cexp.c          |  16 ++++--
 lib/msun/src/s_cexpf.c         |  11 +++--
 lib/msun/src/s_cosl.c          |   7 ++-
 11 files changed, 265 insertions(+), 31 deletions(-)
Comment 11 Minsoo Choo 2022-04-02 12:08:13 UTC
This Bugzilla should be closed.