Path: blob/main/contrib/arm-optimized-routines/math/aarch64/experimental/erfinvf_4u7.c
48375 views
/*1* Single-precision inverse error function.2*3* Copyright (c) 2023-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/6#include "poly_scalar_f32.h"7#include "math_config.h"8#include "test_sig.h"9#include "test_defs.h"1011const static struct12{13/* We use P_N and Q_N to refer to arrays of coefficients, where P_N is the14coeffs of the numerator in table N of Blair et al, and Q_N is the coeffs15of the denominator. */16float P_10[3], Q_10[4], P_29[4], Q_29[4], P_50[6], Q_50[3];17} data = { .P_10 = { -0x1.a31268p+3, 0x1.ac9048p+4, -0x1.293ff6p+3 },18.Q_10 = { -0x1.8265eep+3, 0x1.ef5eaep+4, -0x1.12665p+4, 0x1p+0 },19.P_2920= { -0x1.fc0252p-4, 0x1.119d44p+0, -0x1.f59ee2p+0, 0x1.b13626p-2 },21.Q_29 = { -0x1.69952p-4, 0x1.c7b7d2p-1, -0x1.167d7p+1, 0x1p+0 },22.P_50 = { 0x1.3d8948p-3, 0x1.61f9eap+0, 0x1.61c6bcp-1,23-0x1.20c9f2p+0, 0x1.5c704cp-1, -0x1.50c6bep-3 },24.Q_50 = { 0x1.3d7dacp-3, 0x1.629e5p+0, 0x1p+0 } };2526/* Inverse error function approximation, based on rational approximation as27described in28J. M. Blair, C. A. Edwards, and J. H. Johnson,29"Rational Chebyshev approximations for the inverse of the error function",30Math. Comp. 30, pp. 827--830 (1976).31https://doi.org/10.1090/S0025-5718-1976-0421040-732Largest error is 4.71 ULP, in the tail region:33erfinvf(0x1.f84e9ap-1) got 0x1.b8326ap+034want 0x1.b83274p+0. */35float36erfinvf (float x)37{38if (x == 1.0f)39return __math_oflowf (0);40if (x == -1.0f)41return __math_oflowf (1);4243float a = fabsf (x);44if (a > 1.0f)45return __math_invalidf (x);4647if (a <= 0.75f)48{49/* Greatest error in this region is 4.60 ULP:50erfinvf(0x1.0a98bap-5) got 0x1.d8a93ep-651want 0x1.d8a948p-6. */52float t = x * x - 0.5625f;53return x * horner_2_f32 (t, data.P_10) / horner_3_f32 (t, data.Q_10);54}55if (a < 0.9375f)56{57/* Greatest error in this region is 3.79 ULP:58erfinvf(0x1.ac82d6p-1) got 0x1.f8fc54p-159want 0x1.f8fc5cp-1. */60float t = x * x - 0.87890625f;61return x * horner_3_f32 (t, data.P_29) / horner_3_f32 (t, data.Q_29);62}6364/* Tail region, where error is greatest (and sensitive to sqrt and log1p65implementations. */66float t = 1.0 / sqrtf (-log1pf (-a));67return horner_5_f32 (t, data.P_50)68/ (copysignf (t, x) * horner_2_f32 (t, data.Q_50));69}7071#if USE_MPFR72# warning Not generating tests for erfinvf, as MPFR has no suitable reference73#else74TEST_SIG (S, F, 1, erfinv, -0.99, 0.99)75TEST_ULP (erfinvf, 4.09)76TEST_SYM_INTERVAL (erfinvf, 0, 1, 40000)77#endif787980