casaroli opened a new pull request, #21096:
URL: https://github.com/apache/nuttx/pull/21096

   ## Summary
   
   The XSI option of POSIX puts `j0()`, `j1()`, `jn()`, `y0()`, `y1()` and 
`yn()` in `<math.h>`. The other libm choices (newlib, LibmCS, openlibm, the 
toolchain) have them, but the built-in libm (`CONFIG_LIBM`) did not, so a 
program that uses them did not compile.
   
   This PR adds them to `libs/libm/libm` in three files: `lib_j0.c` (`j0()`, 
`y0()`), `lib_j1.c` (`j1()`, `y1()`) and `lib_jn.c` (`jn()`, `yn()`). The code 
comes from FreeBSD msun (`e_j0.c`, `e_j1.c`, `e_jn.c`) through musl 1.2.6. The 
files keep the Sun Microsystems notice in the same form as `lib_lgamma.c`, and 
`LICENSE` lists them with `lib_lgamma.c`. The changes are only the NuttX coding 
style and a small static function that reads the two 32-bit halves of a double 
in place of the musl macros. `include/nuttx/lib/math.h` declares the functions 
with `CONFIG_HAVE_DOUBLE`; `Make.defs`, `CMakeLists.txt` and `libm.csv` get the 
new files and functions.
   
   ## Impact
   
   New functions in the built-in libm. Existing code does not change. Only the 
double versions, as POSIX specifies. Generic C code for every build mode and 
architecture. For |x| >= 2 the functions use `sin()` and `cos()` of the libm, 
so the accuracy there is the accuracy of these functions (see Testing). 
`Documentation/standards/posix.rst` already lists the functions under XSI_MATH 
("depends on the libm implementation"), and no page lists the functions of the 
built-in libm, so there is no documentation change.
   
   ## Testing
   
   Tested on master aeab6fbf989 and on this PR rebased on it.
   
   Test program `bessel.c` (built with `-fno-builtin`): 65 values of the six 
functions against glibc 2.43 (n = -3, 0, 1, 2, 5, 20, 100; x from 1e-300 to 
1e10, negative x, the first zeros); the special cases (`j0(0)`, `j1(0)`, 
`y0(0)` = -inf, `y0(-1)` = NaN, +-inf, NaN, overflow of `yn(5, 1e-300)` to 
-inf); `jn(0, x)` and `jn(1, x)` against `j0()` and `j1()`; the signs for 
negative n and x. Tolerance: relative 1e-15 for |x| < 2, absolute 2e-15 for |x| 
>= 2 and at the zeros, relative 1e-5 at x = 1e10.
   
   | Test | master | this PR |
   |---|---|---|
   | `bessel` on `qemu-armv8a:knsh` (QEMU with HVF) | does not compile | 101 
cases PASS |
   | these files against the musl 1.2.6 code on the host, 2.3 million random 
arguments (n up to 2000; run once, the code did not change since) | - | the 
same bits for all six functions |
   | ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | status 0 | status 0 |
   
   The built-in `sin()` reduces x with `fmod(x, 2 * M_PI)`. This gives an error 
of about 6e-16 absolute up to x = 100 and of about 2e-6 relative at x = 1e10.
   
   Build, each OK, no new warnings: `qemu-armv8a:nsh` with `CONFIG_LIBM` (flat, 
arm64), `qemu-armv8a:knsh` (kernel, arm64), `rv-virt:nsh64` (flat, rv64), also 
with CMake, `rv-virt:pnsh64` (protected, rv64), `rv-virt:knsh64` (kernel, 
rv64), `lm3s6965-ek:qemu-protected` with `CONFIG_LIBM` (protected, armv7-m).
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to