Path: blob/main/contrib/arm-optimized-routines/math/aarch64/experimental/sinh_3u.c
48378 views
/*1* Double-precision sinh(x) function.2*3* Copyright (c) 2022-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "math_config.h"8#include "test_sig.h"9#include "test_defs.h"10#include "exp_inline.h"1112#define AbsMask 0x7fffffffffffffff13#define Half 0x3fe000000000000014/* 0x1.62e42fefa39fp+9, above which using expm1 results in NaN. */15#define OFlowBound 0x40862e42fefa39f01617/* Approximation for double-precision sinh(x) using expm1.18sinh(x) = (exp(x) - exp(-x)) / 2.19The greatest observed error is 2.57 ULP:20__v_sinh(0x1.9fb1d49d1d58bp-2) got 0x1.ab34e59d678dcp-221want 0x1.ab34e59d678d9p-2. */22double23sinh (double x)24{25uint64_t ix = asuint64 (x);26uint64_t iax = ix & AbsMask;27double ax = asdouble (iax);28uint64_t sign = ix & ~AbsMask;29double halfsign = asdouble (Half | sign);3031if (unlikely (iax >= OFlowBound))32{33/* Special values and overflow. */34if (unlikely (iax > 0x7ff0000000000000))35return __math_invalidf (x);36/* expm1 overflows a little before sinh. We have to fill this37gap by using a different algorithm, in this case we use a38double-precision exp helper. For large x sinh(x) is dominated39by exp(x), however we cannot compute exp without overflow40either. We use the identity: exp(a) = (exp(a / 2)) ^ 241to compute sinh(x) ~= (exp(|x| / 2)) ^ 2 / 2 for x > 042~= (exp(|x| / 2)) ^ 2 / -2 for x < 0. */43double e = exp_inline (ax / 2, 0);44return (e * halfsign) * e;45}4647/* Use expm1f to retain acceptable precision for small numbers.48Let t = e^(|x|) - 1. */49double t = expm1 (ax);50/* Then sinh(x) = (t + t / (t + 1)) / 2 for x > 051(t + t / (t + 1)) / -2 for x < 0. */52return (t + t / (t + 1)) * halfsign;53}5455TEST_SIG (S, D, 1, sinh, -10.0, 10.0)56TEST_ULP (sinh, 2.08)57TEST_SYM_INTERVAL (sinh, 0, 0x1p-51, 100)58TEST_SYM_INTERVAL (sinh, 0x1p-51, 0x1.62e42fefa39fp+9, 100000)59TEST_SYM_INTERVAL (sinh, 0x1.62e42fefa39fp+9, inf, 1000)606162