Path: blob/main/contrib/arm-optimized-routines/math/aarch64/experimental/asinh_2u5.c
48375 views
/*1* Double-precision asinh(x) function2*3* Copyright (c) 2022-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/6#include "mathlib.h"7#include "poly_scalar_f64.h"8#include "math_config.h"9#include "test_sig.h"10#include "test_defs.h"1112#define AbsMask 0x7fffffffffffffff13#define ExpM26 0x3e50000000000000 /* asuint64(0x1.0p-26). */14#define One 0x3ff0000000000000 /* asuint64(1.0). */15#define Exp511 0x5fe0000000000000 /* asuint64(0x1.0p511). */16#define Ln2 0x1.62e42fefa39efp-11718/* Scalar double-precision asinh implementation. This routine uses different19approaches on different intervals:2021|x| < 2^-26: Return x. Function is exact in this region.2223|x| < 1: Use custom order-17 polynomial. This is least accurate close to 1.24The largest observed error in this region is 1.47 ULPs:25asinh(0x1.fdfcd00cc1e6ap-1) got 0x1.c1d6bf874019bp-126want 0x1.c1d6bf874019cp-1.2728|x| < 2^511: Upper bound of this region is close to sqrt(DBL_MAX). Calculate29the result directly using the definition asinh(x) = ln(x + sqrt(x*x + 1)).30The largest observed error in this region is 2.03 ULPs:31asinh(-0x1.00094e0f39574p+0) got -0x1.c3508eb6a681ep-132want -0x1.c3508eb6a682p-1.3334|x| >= 2^511: We cannot square x without overflow at a low35cost. At very large x, asinh(x) ~= ln(2x). At huge x we cannot36even double x without overflow, so calculate this as ln(x) +37ln(2). The largest observed error in this region is 0.98 ULPs at many38values, for instance:39asinh(0x1.5255a4cf10319p+975) got 0x1.52652f4cb26cbp+940want 0x1.52652f4cb26ccp+9. */41double42asinh (double x)43{44uint64_t ix = asuint64 (x);45uint64_t ia = ix & AbsMask;46double ax = asdouble (ia);47uint64_t sign = ix & ~AbsMask;4849if (ia < ExpM26)50{51return x;52}5354if (ia < One)55{56double x2 = x * x;57double z2 = x2 * x2;58double z4 = z2 * z2;59double z8 = z4 * z4;60double p = estrin_17_f64 (x2, z2, z4, z8, z8 * z8, __asinh_data.poly);61double y = fma (p, x2 * ax, ax);62return asdouble (asuint64 (y) | sign);63}6465if (unlikely (ia >= Exp511))66{67return asdouble (asuint64 (log (ax) + Ln2) | sign);68}6970return asdouble (asuint64 (log (ax + sqrt (ax * ax + 1))) | sign);71}7273TEST_SIG (S, D, 1, asinh, -10.0, 10.0)74TEST_ULP (asinh, 1.54)75TEST_INTERVAL (asinh, -0x1p-26, 0x1p-26, 50000)76TEST_INTERVAL (asinh, 0x1p-26, 1.0, 40000)77TEST_INTERVAL (asinh, -0x1p-26, -1.0, 10000)78TEST_INTERVAL (asinh, 1.0, 100.0, 40000)79TEST_INTERVAL (asinh, -1.0, -100.0, 10000)80TEST_INTERVAL (asinh, 100.0, inf, 50000)81TEST_INTERVAL (asinh, -100.0, -inf, 10000)828384