Skip to content

Commit c995db3

Browse files
[libc] Add exceptional values for sinhf16/coshf16 (#133002)
The rounding of the result when using an FMA instruction for hyperbolic sin/cos on float16 was off by 1 bit for a few cases. This patch adds extra exceptional cases to handle these.
1 parent d75a40a commit c995db3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

libc/src/math/generic/coshf16.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static constexpr fputil::ExceptValues<float16, 9> COSHF16_EXCEPTS_POS = {{
4242
{0x497cU, 0x7715U, 1U, 0U, 1U},
4343
}};
4444

45-
static constexpr fputil::ExceptValues<float16, 4> COSHF16_EXCEPTS_NEG = {{
45+
static constexpr fputil::ExceptValues<float16, 6> COSHF16_EXCEPTS_NEG = {{
4646
// x = -0x1.6ap-5, coshf16(x) = 0x1p+0 (RZ)
4747
{0xa9a8U, 0x3c00U, 1U, 0U, 1U},
4848
// x = -0x1.b6p+0, coshf16(x) = 0x1.6d8p+1 (RZ)
@@ -51,6 +51,10 @@ static constexpr fputil::ExceptValues<float16, 4> COSHF16_EXCEPTS_NEG = {{
5151
{0xc4a2U, 0x526dU, 1U, 0U, 0U},
5252
// x = -0x1.5fp+3, coshf16(x) = 0x1.c54p+14 (RZ)
5353
{0xc97cU, 0x7715U, 1U, 0U, 1U},
54+
// x = -0x1.8c4p+0, coshf16(x) = 0x1.3a8p+1 (RZ)
55+
{0xbe31U, 0x40eaU, 1U, 0U, 0U},
56+
// x = -0x1.994p+0, coshf16(x) = 0x1.498p+1 (RZ)
57+
{0xbe65U, 0x4126U, 1U, 0U, 0U},
5458
}};
5559
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
5660

libc/src/math/generic/sinhf16.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace LIBC_NAMESPACE_DECL {
2222

2323
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
24-
static constexpr fputil::ExceptValues<float16, 16> SINHF16_EXCEPTS_POS = {{
24+
static constexpr fputil::ExceptValues<float16, 17> SINHF16_EXCEPTS_POS = {{
2525
// x = 0x1.714p-5, sinhf16(x) = 0x1.714p-5 (RZ)
2626
{0x29c5U, 0x29c5U, 1U, 0U, 1U},
2727
// x = 0x1.25p-4, sinhf16(x) = 0x1.25p-4 (RZ)
@@ -54,9 +54,11 @@ static constexpr fputil::ExceptValues<float16, 16> SINHF16_EXCEPTS_POS = {{
5454
{0x4629U, 0x5b65U, 1U, 0U, 1U},
5555
// x = 0x1.5fp+3, sinhf16(x) = 0x1.c54p+14 (RZ)
5656
{0x497cU, 0x7715U, 1U, 0U, 1U},
57+
// x = 0x1.3c8p+1, sinhf16(x) = 0x1.78ap+2 (RZ)
58+
{0x40f2U, 0x45e2U, 1U, 0U, 1U},
5759
}};
5860

59-
static constexpr fputil::ExceptValues<float16, 12> SINHF16_EXCEPTS_NEG = {{
61+
static constexpr fputil::ExceptValues<float16, 13> SINHF16_EXCEPTS_NEG = {{
6062
// x = -0x1.714p-5, sinhf16(x) = -0x1.714p-5 (RZ)
6163
{0xa9c5U, 0xa9c5U, 0U, 1U, 1U},
6264
// x = -0x1.25p-4, sinhf16(x) = -0x1.25p-4 (RZ)
@@ -81,6 +83,8 @@ static constexpr fputil::ExceptValues<float16, 12> SINHF16_EXCEPTS_NEG = {{
8183
{0xc629U, 0xdb65U, 0U, 1U, 1U},
8284
// x = -0x1.5fp+3, sinhf16(x) = -0x1.c54p+14 (RZ)
8385
{0xc97cU, 0xf715U, 0U, 1U, 1U},
86+
// x = -0x1.3c8p+1, sinhf16(x) = -0x1.78ap+2 (RZ)
87+
{0xc0f2U, 0xc5e2U, 0U, 1U, 1U},
8488
}};
8589
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
8690

0 commit comments

Comments
 (0)