9#ifndef FORTRAN_COMMON_ERFC_SCALED_H_
10#define FORTRAN_COMMON_ERFC_SCALED_H_
12#include "flang/Common/api-attrs.h"
17template <
typename T>
inline RT_API_ATTRS T ErfcScaled(T arg) {
19 static const T a[5] = {3.16112374387056560e00, 1.13864154151050156e02,
20 3.77485237685302021e02, 3.20937758913846947e03, 1.85777706184603153e-1};
21 static const T b[4] = {2.36012909523441209e01, 2.44024637934444173e02,
22 1.28261652607737228e03, 2.84423683343917062e03};
25 static const T c[9] = {5.64188496988670089e-1, 8.88314979438837594e00,
26 6.61191906371416295e01, 2.98635138197400131e02, 8.81952221241769090e02,
27 1.71204761263407058e03, 2.05107837782607147e03, 1.23033935479799725e03,
28 2.15311535474403846e-8};
29 static const T d[8] = {1.57449261107098347e01, 1.17693950891312499e02,
30 5.37181101862009858e02, 1.62138957456669019e03, 3.29079923573345963e03,
31 4.36261909014324716e03, 3.43936767414372164e03, 1.23033935480374942e03};
34 static const T p[6] = {3.05326634961232344e-1, 3.60344899949804439e-1,
35 1.25781726111229246e-1, 1.60837851487422766e-2, 6.58749161529837803e-4,
36 1.63153871373020978e-2};
37 static const T q[5] = {2.56852019228982242e00, 1.87295284992346047e00,
38 5.27905102951428412e-1, 6.05183413124413191e-2, 2.33520497626869185e-3};
40 constexpr T sqrtpi{1.7724538509078120380404576221783883301349L};
41 constexpr T rsqrtpi{0.5641895835477562869480794515607725858440L};
42 constexpr T epsilonby2{std::numeric_limits<T>::epsilon() * 0.5};
43 constexpr T xneg{-26.628e0};
44 constexpr T xhuge{6.71e7};
45 constexpr T thresh{0.46875e0};
46 constexpr T zero{0.0};
48 constexpr T four{4.0};
49 constexpr T sixteen{16.0};
50 constexpr T xmax{1.0 / (sqrtpi * std::numeric_limits<T>::min())};
51 static_assert(xmax > xhuge,
"xmax must be greater than xhuge");
70 for (
int i{0}; i < 3; i++) {
71 xnum = (xnum + a[i]) * ysq;
72 xden = (xden + b[i]) * ysq;
74 result = x * (xnum + a[3]) / (xden + b[3]);
75 result = one - result;
76 result = std::exp(ysq) * result;
78 }
else if (y <= four) {
82 for (
int i{0}; i < 7; ++i) {
83 xnum = (xnum + c[i]) * y;
84 xden = (xden + d[i]) * y;
86 result = (xnum + c[7]) / (xden + d[7]);
98 for (
int i{0}; i < 4; ++i) {
99 xnum = (xnum + p[i]) * ysq;
100 xden = (xden + q[i]) * ysq;
102 result = ysq * (xnum + p[4]) / (xden + q[4]);
103 result = (rsqrtpi - result) / y;
109 result = std::numeric_limits<T>::max();
111 ysq = trunc(x * sixteen) / sixteen;
112 del = (x - ysq) * (x + ysq);
113 y = std::exp((ysq * ysq)) * std::exp((del));
114 result = (y + y) - result;
Definition bit-population-count.h:20