RFR: JDK-8302027: Port fdlibm trig functions (sin, cos, tan) to Java
Raffaello Giulietti
rgiulietti at openjdk.org
Wed Mar 1 16:16:22 UTC 2023
On Wed, 1 Mar 2023 05:28:34 GMT, Joe Darcy <darcy at openjdk.org> wrote:
> Last and certainly not least in the port of FDLIBM to Java, the transcendental methods for sin, cos, and tan.
>
> Some more tests are to be written in the StrictMath directory to verify that the StrictMath algorihtm for sin/cos/tan is being used rather than a different one. However, I wanted to get the rest of the change out for review first.
>
> The sin/cos/tan methods are grouped together since they share the same argument reduction logic. Argument reduction is the process of mapping an argument of a function to an argument in a restricted range (and possibly returning some function of the reduced argument). For sin, cos, and tan, since they are fundamentally periodic with respect to a multiple of pi, argument reduction is done to find the remainder of the original argument with respect to pi/2.
src/java.base/share/classes/java/lang/FdLibm.java line 816:
> 814: twon24 = 0x1.0p-24; // 5.96046447753906250000e-08
> 815:
> 816: static int __kernel_rem_pio2(double[] x, double[] y, int e0, int nx, int prec, final int[] ipio2) {
See comment on translit about the value of `final` here.
src/java.base/share/classes/java/lang/FdLibm.java line 852:
> 850:
> 851: jz = jk;
> 852: while(true) {
See comment in translit.
test/jdk/java/lang/StrictMath/FdlibmTranslit.java line 839:
> 837: twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
> 838:
> 839: static int __kernel_rem_pio2(double[] x, double[] y, int e0, int nx, int prec, final int[] ipio2) {
`final int[]` in Java has a different semantics than `const int*` in C. The latter denotes a pointer to constant `int`s.
I don't think that the `final` keywords conveys any benefit here.
test/jdk/java/lang/StrictMath/FdlibmTranslit.java line 867:
> 865:
> 866: jz = jk;
> 867: while(true) {
Would it be worthwhile to add some remarks about how the C `goto` + label has been "translitted"?
Or even add the `recompute:` label explicitly and adapt the `continue` and `break` statements inside the `while`?
-------------
PR: https://git.openjdk.org/jdk/pull/12800
More information about the core-libs-dev
mailing list