[libc-commits] [libc] [libc] Add sinpif16 function (PR #110994)

via libc-commits libc-commits at lists.llvm.org
Thu Oct 10 07:25:47 PDT 2024


================
@@ -21,114 +21,70 @@
 // HELPER_START
 namespace LIBC_NAMESPACE_DECL {
 
-constexpr float PI_OVER_32 = M_PI / 32;
+constexpr float PI_OVER_32 = 0x1.921fb6p-4f;
 
 // In Sollya generate 10 coeffecients for a degree-9 chebyshev polynomial
 // approximating the sine function in [-pi / 32, pi / 32] with the following
 // commands:
-// > prec=23;
+// > prec=24;
 // > TL = chebyshevform(sin(x), 9, [-pi / 32, pi / 32]);
 // > TL[0];
 const float SIN_COEFF[10] = {
-    0x1.801p-27, 0x1.000078p0, -0x1.7e98p-14, -0x1.6bf4p-3, 0x1.95ccp-5,
-    0x1.1baep2,  -0x1.030ap3,  -0x1.3dap9,    0x1.98e4p8,   0x1.d3d8p14};
-
+  0x1.d333p-26, 0x1.000048p0, -0x1.a5d2p-14, -0x1.628588p-3, 0x1.c1eep-5,
+  0x1.4455p1, -0x1.317a8p3, -0x1.6bb9p8, 0x1.00ef8p9, 0x1.0edcp14
+};
 // In Sollya generate 10 coefficients for a degree-9 chebyshev polynomial
 // approximating the sine function in [-pi/32, pi/32] with the following
 // commands:
-// > prec = 23;
+// > prec = 24;
 // > TL = chebyshevform(cos(x), 9, [-pi / 32, pi / 32]);
 // > TL[0];
 const float COS_COEFF[10] = {
-    0x1.00001p0, -0x1.48p-17, -0x1.01259cp-1, -0x1.17fp-6, 0x1.283p0,
-    0x1.5d1p3,   -0x1.6278p7, -0x1.c23p10,    0x1.1444p13, 0x1.5fcp16};
-
+  0x1.000006p0, 0x1.e1eap-15, -0x1.0071p-1, -0x1.3b56p-4, 0x1.f3dfp-2,
+  0x1.ccbap4, -0x1.3034p6, -0x1.f817p11, 0x1.fc59p11, 0x1.7079p17
+};
 // Lookup table for sin(k * pi / 32) with k = 0, ..., 63.
 // Table is generated with Sollya as follows:
 // > display = hexadecimmal;
-// > prec = 23;
+// > prec = 24;
 // > for k from 0 to 63 do {sin(k * pi/32);};
----------------
lntue wrote:

instead of setting the global `prec`, you can do:
```
> for k from 0 to 63, do { round(sin(k * pi/32), SG, RN); };
```

https://github.com/llvm/llvm-project/pull/110994


More information about the libc-commits mailing list