@xort/rcmg 0.0.0-stage → 0.1.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +21 -0
  3. package/PROVENANCE.json +1601 -0
  4. package/README.md +152 -2
  5. package/licenses/registry/allocator-api2-0.2.22-c19b7c6f923b/LICENSE-APACHE +176 -0
  6. package/licenses/registry/allocator-api2-0.2.22-c19b7c6f923b/LICENSE-MIT +23 -0
  7. package/licenses/registry/autocfg-1.5.1-c19b7c6f923b/LICENSE-APACHE +201 -0
  8. package/licenses/registry/autocfg-1.5.1-c19b7c6f923b/LICENSE-MIT +25 -0
  9. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/LICENSE-APACHE +201 -0
  10. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/LICENSE-MIT +25 -0
  11. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/alloc.rs +794 -0
  12. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/mod.rs +93 -0
  13. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/raw_vec.rs +781 -0
  14. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/str/lossy.rs +209 -0
  15. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/str/mod.rs +43 -0
  16. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/string.rs +2191 -0
  17. package/licenses/registry/bumpalo-3.20.4-c19b7c6f923b/src/collections/vec.rs +3051 -0
  18. package/licenses/registry/cfg-if-1.0.5-c19b7c6f923b/LICENSE-APACHE +201 -0
  19. package/licenses/registry/cfg-if-1.0.5-c19b7c6f923b/LICENSE-MIT +25 -0
  20. package/licenses/registry/equivalent-1.0.3-c19b7c6f923b/LICENSE-APACHE +201 -0
  21. package/licenses/registry/equivalent-1.0.3-c19b7c6f923b/LICENSE-MIT +25 -0
  22. package/licenses/registry/foldhash-0.2.0-c19b7c6f923b/LICENSE +19 -0
  23. package/licenses/registry/hashbrown-0.16.1-c19b7c6f923b/LICENSE-APACHE +201 -0
  24. package/licenses/registry/hashbrown-0.16.1-c19b7c6f923b/LICENSE-MIT +25 -0
  25. package/licenses/registry/libm-0.2.16-c19b7c6f923b/LICENSE.txt +258 -0
  26. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/acos.rs +112 -0
  27. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/acosf.rs +79 -0
  28. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/asin.rs +115 -0
  29. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/asinf.rs +68 -0
  30. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atan.rs +180 -0
  31. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atan2.rs +131 -0
  32. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atan2f.rs +90 -0
  33. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/atanf.rs +108 -0
  34. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cbrt.rs +219 -0
  35. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cbrtf.rs +73 -0
  36. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cos.rs +77 -0
  37. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/cosf.rs +86 -0
  38. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/erf.rs +314 -0
  39. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/erff.rs +226 -0
  40. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/exp.rs +156 -0
  41. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/exp2.rs +400 -0
  42. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/exp2f.rs +141 -0
  43. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/expf.rs +103 -0
  44. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/expm1.rs +142 -0
  45. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/expm1f.rs +134 -0
  46. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/fma.rs +171 -0
  47. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/ceil.rs +174 -0
  48. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/floor.rs +157 -0
  49. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fma.rs +278 -0
  50. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmax.rs +23 -0
  51. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmaximum.rs +27 -0
  52. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmaximum_num.rs +29 -0
  53. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmin.rs +23 -0
  54. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fminimum.rs +27 -0
  55. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fminimum_num.rs +29 -0
  56. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/fmod.rs +116 -0
  57. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/rint.rs +130 -0
  58. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/sqrt.rs +541 -0
  59. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/generic/trunc.rs +148 -0
  60. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j0.rs +426 -0
  61. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j0f.rs +363 -0
  62. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j1.rs +418 -0
  63. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/j1f.rs +383 -0
  64. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/jn.rs +339 -0
  65. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/jnf.rs +253 -0
  66. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_cos.rs +62 -0
  67. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_cosf.rs +29 -0
  68. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_sin.rs +57 -0
  69. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_sinf.rs +30 -0
  70. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_tan.rs +105 -0
  71. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/k_tanf.rs +46 -0
  72. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/lgamma_r.rs +321 -0
  73. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/lgammaf_r.rs +256 -0
  74. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log.rs +118 -0
  75. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log10.rs +116 -0
  76. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log10f.rs +90 -0
  77. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log1p.rs +142 -0
  78. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log1pf.rs +97 -0
  79. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log2.rs +105 -0
  80. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/log2f.rs +86 -0
  81. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/logf.rs +66 -0
  82. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/pow.rs +624 -0
  83. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/powf.rs +343 -0
  84. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/rem_pio2.rs +235 -0
  85. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/rem_pio2_large.rs +476 -0
  86. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/rem_pio2f.rs +65 -0
  87. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sin.rs +95 -0
  88. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sincos.rs +137 -0
  89. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sincosf.rs +176 -0
  90. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/sinf.rs +96 -0
  91. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/support/int_traits/narrowing_div.rs +175 -0
  92. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/support/modular.rs +304 -0
  93. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/tan.rs +74 -0
  94. package/licenses/registry/libm-0.2.16-c19b7c6f923b/src/math/tanf.rs +81 -0
  95. package/licenses/registry/num-traits-0.2.19-c19b7c6f923b/LICENSE-APACHE +201 -0
  96. package/licenses/registry/num-traits-0.2.19-c19b7c6f923b/LICENSE-MIT +25 -0
  97. package/licenses/registry/num-traits-0.2.19-c19b7c6f923b/src/lib.rs +635 -0
  98. package/licenses/registry/once_cell-1.21.4-c19b7c6f923b/LICENSE-APACHE +201 -0
  99. package/licenses/registry/once_cell-1.21.4-c19b7c6f923b/LICENSE-MIT +23 -0
  100. package/licenses/registry/proc-macro2-1.0.107-c19b7c6f923b/LICENSE-APACHE +176 -0
  101. package/licenses/registry/proc-macro2-1.0.107-c19b7c6f923b/LICENSE-MIT +23 -0
  102. package/licenses/registry/quote-1.0.47-c19b7c6f923b/LICENSE-APACHE +176 -0
  103. package/licenses/registry/quote-1.0.47-c19b7c6f923b/LICENSE-MIT +23 -0
  104. package/licenses/registry/robust-1.2.0-c19b7c6f923b/LICENSE-APACHE +201 -0
  105. package/licenses/registry/robust-1.2.0-c19b7c6f923b/LICENSE-MIT +26 -0
  106. package/licenses/registry/robust-1.2.0-c19b7c6f923b/src/lib.rs +2224 -0
  107. package/licenses/registry/rustversion-1.0.23-c19b7c6f923b/LICENSE-APACHE +176 -0
  108. package/licenses/registry/rustversion-1.0.23-c19b7c6f923b/LICENSE-MIT +23 -0
  109. package/licenses/registry/smallvec-1.16.6-c19b7c6f923b/LICENSE-APACHE +201 -0
  110. package/licenses/registry/smallvec-1.16.6-c19b7c6f923b/LICENSE-MIT +25 -0
  111. package/licenses/registry/spade-2.15.1-c19b7c6f923b/LICENSE-APACHE +202 -0
  112. package/licenses/registry/spade-2.15.1-c19b7c6f923b/LICENSE-MIT +25 -0
  113. package/licenses/registry/syn-2.0.119-c19b7c6f923b/LICENSE-APACHE +176 -0
  114. package/licenses/registry/syn-2.0.119-c19b7c6f923b/LICENSE-MIT +23 -0
  115. package/licenses/registry/unicode-ident-1.0.27-c19b7c6f923b/LICENSE-APACHE +176 -0
  116. package/licenses/registry/unicode-ident-1.0.27-c19b7c6f923b/LICENSE-MIT +23 -0
  117. package/licenses/registry/unicode-ident-1.0.27-c19b7c6f923b/LICENSE-UNICODE +39 -0
  118. package/licenses/registry/wasm-bindgen-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
  119. package/licenses/registry/wasm-bindgen-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
  120. package/licenses/registry/wasm-bindgen-macro-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
  121. package/licenses/registry/wasm-bindgen-macro-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
  122. package/licenses/registry/wasm-bindgen-macro-support-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
  123. package/licenses/registry/wasm-bindgen-macro-support-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
  124. package/licenses/registry/wasm-bindgen-shared-0.2.118-c19b7c6f923b/LICENSE-APACHE +201 -0
  125. package/licenses/registry/wasm-bindgen-shared-0.2.118-c19b7c6f923b/LICENSE-MIT +25 -0
  126. package/licenses/registry-licenses.json +1413 -0
  127. package/licenses/source/LICENSE-APACHE +176 -0
  128. package/licenses/source/LICENSE-MIT +21 -0
  129. package/licenses/source/crates/rcmg-mesh/src/isosurface/LICENSE-PyMCubes +27 -0
  130. package/licenses/source/crates/rcmg-mesh/src/isosurface/NOTICE.md +11 -0
  131. package/licenses/source/vendor/cadcraft-dxf/LICENSE-APACHE +177 -0
  132. package/licenses/source/vendor/cadcraft-dxf/LICENSE-MIT +21 -0
  133. package/node/index.mjs +2 -0
  134. package/node/package.json +3 -0
  135. package/node/rcmg_ffi.d.ts +51 -0
  136. package/node/rcmg_ffi.js +269 -0
  137. package/node/rcmg_ffi_bg.wasm +0 -0
  138. package/node/rcmg_ffi_bg.wasm.d.ts +32 -0
  139. package/package.json +57 -6
  140. package/web/rcmg_ffi.d.ts +108 -0
  141. package/web/rcmg_ffi.js +358 -0
  142. package/web/rcmg_ffi_bg.wasm +0 -0
  143. package/web/rcmg_ffi_bg.wasm.d.ts +32 -0
@@ -0,0 +1,314 @@
1
+ use super::{exp, fabs, get_high_word, with_set_low_word};
2
+ /* origin: FreeBSD /usr/src/lib/msun/src/s_erf.c */
3
+ /*
4
+ * ====================================================
5
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6
+ *
7
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
8
+ * Permission to use, copy, modify, and distribute this
9
+ * software is freely granted, provided that this notice
10
+ * is preserved.
11
+ * ====================================================
12
+ */
13
+ /* double erf(double x)
14
+ * double erfc(double x)
15
+ * x
16
+ * 2 |\
17
+ * erf(x) = --------- | exp(-t*t)dt
18
+ * sqrt(pi) \|
19
+ * 0
20
+ *
21
+ * erfc(x) = 1-erf(x)
22
+ * Note that
23
+ * erf(-x) = -erf(x)
24
+ * erfc(-x) = 2 - erfc(x)
25
+ *
26
+ * Method:
27
+ * 1. For |x| in [0, 0.84375]
28
+ * erf(x) = x + x*R(x^2)
29
+ * erfc(x) = 1 - erf(x) if x in [-.84375,0.25]
30
+ * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375]
31
+ * where R = P/Q where P is an odd poly of degree 8 and
32
+ * Q is an odd poly of degree 10.
33
+ * -57.90
34
+ * | R - (erf(x)-x)/x | <= 2
35
+ *
36
+ *
37
+ * Remark. The formula is derived by noting
38
+ * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....)
39
+ * and that
40
+ * 2/sqrt(pi) = 1.128379167095512573896158903121545171688
41
+ * is close to one. The interval is chosen because the fix
42
+ * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is
43
+ * near 0.6174), and by some experiment, 0.84375 is chosen to
44
+ * guarantee the error is less than one ulp for erf.
45
+ *
46
+ * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and
47
+ * c = 0.84506291151 rounded to single (24 bits)
48
+ * erf(x) = sign(x) * (c + P1(s)/Q1(s))
49
+ * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0
50
+ * 1+(c+P1(s)/Q1(s)) if x < 0
51
+ * |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06
52
+ * Remark: here we use the taylor series expansion at x=1.
53
+ * erf(1+s) = erf(1) + s*Poly(s)
54
+ * = 0.845.. + P1(s)/Q1(s)
55
+ * That is, we use rational approximation to approximate
56
+ * erf(1+s) - (c = (single)0.84506291151)
57
+ * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25]
58
+ * where
59
+ * P1(s) = degree 6 poly in s
60
+ * Q1(s) = degree 6 poly in s
61
+ *
62
+ * 3. For x in [1.25,1/0.35(~2.857143)],
63
+ * erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1)
64
+ * erf(x) = 1 - erfc(x)
65
+ * where
66
+ * R1(z) = degree 7 poly in z, (z=1/x^2)
67
+ * S1(z) = degree 8 poly in z
68
+ *
69
+ * 4. For x in [1/0.35,28]
70
+ * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0
71
+ * = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6<x<0
72
+ * = 2.0 - tiny (if x <= -6)
73
+ * erf(x) = sign(x)*(1.0 - erfc(x)) if x < 6, else
74
+ * erf(x) = sign(x)*(1.0 - tiny)
75
+ * where
76
+ * R2(z) = degree 6 poly in z, (z=1/x^2)
77
+ * S2(z) = degree 7 poly in z
78
+ *
79
+ * Note1:
80
+ * To compute exp(-x*x-0.5625+R/S), let s be a single
81
+ * precision number and s := x; then
82
+ * -x*x = -s*s + (s-x)*(s+x)
83
+ * exp(-x*x-0.5626+R/S) =
84
+ * exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S);
85
+ * Note2:
86
+ * Here 4 and 5 make use of the asymptotic series
87
+ * exp(-x*x)
88
+ * erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) )
89
+ * x*sqrt(pi)
90
+ * We use rational approximation to approximate
91
+ * g(s)=f(1/x^2) = log(erfc(x)*x) - x*x + 0.5625
92
+ * Here is the error bound for R1/S1 and R2/S2
93
+ * |R1/S1 - f(x)| < 2**(-62.57)
94
+ * |R2/S2 - f(x)| < 2**(-61.52)
95
+ *
96
+ * 5. For inf > x >= 28
97
+ * erf(x) = sign(x) *(1 - tiny) (raise inexact)
98
+ * erfc(x) = tiny*tiny (raise underflow) if x > 0
99
+ * = 2 - tiny if x<0
100
+ *
101
+ * 7. Special case:
102
+ * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1,
103
+ * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2,
104
+ * erfc/erf(NaN) is NaN
105
+ */
106
+
107
+ const ERX: f64 = 8.45062911510467529297e-01; /* 0x3FEB0AC1, 0x60000000 */
108
+ /*
109
+ * Coefficients for approximation to erf on [0,0.84375]
110
+ */
111
+ const EFX8: f64 = 1.02703333676410069053e+00; /* 0x3FF06EBA, 0x8214DB69 */
112
+ const PP0: f64 = 1.28379167095512558561e-01; /* 0x3FC06EBA, 0x8214DB68 */
113
+ const PP1: f64 = -3.25042107247001499370e-01; /* 0xBFD4CD7D, 0x691CB913 */
114
+ const PP2: f64 = -2.84817495755985104766e-02; /* 0xBF9D2A51, 0xDBD7194F */
115
+ const PP3: f64 = -5.77027029648944159157e-03; /* 0xBF77A291, 0x236668E4 */
116
+ const PP4: f64 = -2.37630166566501626084e-05; /* 0xBEF8EAD6, 0x120016AC */
117
+ const QQ1: f64 = 3.97917223959155352819e-01; /* 0x3FD97779, 0xCDDADC09 */
118
+ const QQ2: f64 = 6.50222499887672944485e-02; /* 0x3FB0A54C, 0x5536CEBA */
119
+ const QQ3: f64 = 5.08130628187576562776e-03; /* 0x3F74D022, 0xC4D36B0F */
120
+ const QQ4: f64 = 1.32494738004321644526e-04; /* 0x3F215DC9, 0x221C1A10 */
121
+ const QQ5: f64 = -3.96022827877536812320e-06; /* 0xBED09C43, 0x42A26120 */
122
+ /*
123
+ * Coefficients for approximation to erf in [0.84375,1.25]
124
+ */
125
+ const PA0: f64 = -2.36211856075265944077e-03; /* 0xBF6359B8, 0xBEF77538 */
126
+ const PA1: f64 = 4.14856118683748331666e-01; /* 0x3FDA8D00, 0xAD92B34D */
127
+ const PA2: f64 = -3.72207876035701323847e-01; /* 0xBFD7D240, 0xFBB8C3F1 */
128
+ const PA3: f64 = 3.18346619901161753674e-01; /* 0x3FD45FCA, 0x805120E4 */
129
+ const PA4: f64 = -1.10894694282396677476e-01; /* 0xBFBC6398, 0x3D3E28EC */
130
+ const PA5: f64 = 3.54783043256182359371e-02; /* 0x3FA22A36, 0x599795EB */
131
+ const PA6: f64 = -2.16637559486879084300e-03; /* 0xBF61BF38, 0x0A96073F */
132
+ const QA1: f64 = 1.06420880400844228286e-01; /* 0x3FBB3E66, 0x18EEE323 */
133
+ const QA2: f64 = 5.40397917702171048937e-01; /* 0x3FE14AF0, 0x92EB6F33 */
134
+ const QA3: f64 = 7.18286544141962662868e-02; /* 0x3FB2635C, 0xD99FE9A7 */
135
+ const QA4: f64 = 1.26171219808761642112e-01; /* 0x3FC02660, 0xE763351F */
136
+ const QA5: f64 = 1.36370839120290507362e-02; /* 0x3F8BEDC2, 0x6B51DD1C */
137
+ const QA6: f64 = 1.19844998467991074170e-02; /* 0x3F888B54, 0x5735151D */
138
+ /*
139
+ * Coefficients for approximation to erfc in [1.25,1/0.35]
140
+ */
141
+ const RA0: f64 = -9.86494403484714822705e-03; /* 0xBF843412, 0x600D6435 */
142
+ const RA1: f64 = -6.93858572707181764372e-01; /* 0xBFE63416, 0xE4BA7360 */
143
+ const RA2: f64 = -1.05586262253232909814e+01; /* 0xC0251E04, 0x41B0E726 */
144
+ const RA3: f64 = -6.23753324503260060396e+01; /* 0xC04F300A, 0xE4CBA38D */
145
+ const RA4: f64 = -1.62396669462573470355e+02; /* 0xC0644CB1, 0x84282266 */
146
+ const RA5: f64 = -1.84605092906711035994e+02; /* 0xC067135C, 0xEBCCABB2 */
147
+ const RA6: f64 = -8.12874355063065934246e+01; /* 0xC0545265, 0x57E4D2F2 */
148
+ const RA7: f64 = -9.81432934416914548592e+00; /* 0xC023A0EF, 0xC69AC25C */
149
+ const SA1: f64 = 1.96512716674392571292e+01; /* 0x4033A6B9, 0xBD707687 */
150
+ const SA2: f64 = 1.37657754143519042600e+02; /* 0x4061350C, 0x526AE721 */
151
+ const SA3: f64 = 4.34565877475229228821e+02; /* 0x407B290D, 0xD58A1A71 */
152
+ const SA4: f64 = 6.45387271733267880336e+02; /* 0x40842B19, 0x21EC2868 */
153
+ const SA5: f64 = 4.29008140027567833386e+02; /* 0x407AD021, 0x57700314 */
154
+ const SA6: f64 = 1.08635005541779435134e+02; /* 0x405B28A3, 0xEE48AE2C */
155
+ const SA7: f64 = 6.57024977031928170135e+00; /* 0x401A47EF, 0x8E484A93 */
156
+ const SA8: f64 = -6.04244152148580987438e-02; /* 0xBFAEEFF2, 0xEE749A62 */
157
+ /*
158
+ * Coefficients for approximation to erfc in [1/.35,28]
159
+ */
160
+ const RB0: f64 = -9.86494292470009928597e-03; /* 0xBF843412, 0x39E86F4A */
161
+ const RB1: f64 = -7.99283237680523006574e-01; /* 0xBFE993BA, 0x70C285DE */
162
+ const RB2: f64 = -1.77579549177547519889e+01; /* 0xC031C209, 0x555F995A */
163
+ const RB3: f64 = -1.60636384855821916062e+02; /* 0xC064145D, 0x43C5ED98 */
164
+ const RB4: f64 = -6.37566443368389627722e+02; /* 0xC083EC88, 0x1375F228 */
165
+ const RB5: f64 = -1.02509513161107724954e+03; /* 0xC0900461, 0x6A2E5992 */
166
+ const RB6: f64 = -4.83519191608651397019e+02; /* 0xC07E384E, 0x9BDC383F */
167
+ const SB1: f64 = 3.03380607434824582924e+01; /* 0x403E568B, 0x261D5190 */
168
+ const SB2: f64 = 3.25792512996573918826e+02; /* 0x40745CAE, 0x221B9F0A */
169
+ const SB3: f64 = 1.53672958608443695994e+03; /* 0x409802EB, 0x189D5118 */
170
+ const SB4: f64 = 3.19985821950859553908e+03; /* 0x40A8FFB7, 0x688C246A */
171
+ const SB5: f64 = 2.55305040643316442583e+03; /* 0x40A3F219, 0xCEDF3BE6 */
172
+ const SB6: f64 = 4.74528541206955367215e+02; /* 0x407DA874, 0xE79FE763 */
173
+ const SB7: f64 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
174
+
175
+ fn erfc1(x: f64) -> f64 {
176
+ let s: f64;
177
+ let p: f64;
178
+ let q: f64;
179
+
180
+ s = fabs(x) - 1.0;
181
+ p = PA0 + s * (PA1 + s * (PA2 + s * (PA3 + s * (PA4 + s * (PA5 + s * PA6)))));
182
+ q = 1.0 + s * (QA1 + s * (QA2 + s * (QA3 + s * (QA4 + s * (QA5 + s * QA6)))));
183
+
184
+ 1.0 - ERX - p / q
185
+ }
186
+
187
+ fn erfc2(ix: u32, mut x: f64) -> f64 {
188
+ let s: f64;
189
+ let r: f64;
190
+ let big_s: f64;
191
+ let z: f64;
192
+
193
+ if ix < 0x3ff40000 {
194
+ /* |x| < 1.25 */
195
+ return erfc1(x);
196
+ }
197
+
198
+ x = fabs(x);
199
+ s = 1.0 / (x * x);
200
+ if ix < 0x4006db6d {
201
+ /* |x| < 1/.35 ~ 2.85714 */
202
+ r = RA0 + s * (RA1 + s * (RA2 + s * (RA3 + s * (RA4 + s * (RA5 + s * (RA6 + s * RA7))))));
203
+ big_s = 1.0
204
+ + s * (SA1
205
+ + s * (SA2 + s * (SA3 + s * (SA4 + s * (SA5 + s * (SA6 + s * (SA7 + s * SA8)))))));
206
+ } else {
207
+ /* |x| > 1/.35 */
208
+ r = RB0 + s * (RB1 + s * (RB2 + s * (RB3 + s * (RB4 + s * (RB5 + s * RB6)))));
209
+ big_s =
210
+ 1.0 + s * (SB1 + s * (SB2 + s * (SB3 + s * (SB4 + s * (SB5 + s * (SB6 + s * SB7))))));
211
+ }
212
+ z = with_set_low_word(x, 0);
213
+
214
+ exp(-z * z - 0.5625) * exp((z - x) * (z + x) + r / big_s) / x
215
+ }
216
+
217
+ /// Error function (f64)
218
+ ///
219
+ /// Calculates an approximation to the “error function”, which estimates
220
+ /// the probability that an observation will fall within x standard
221
+ /// deviations of the mean (assuming a normal distribution).
222
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
223
+ pub fn erf(x: f64) -> f64 {
224
+ let r: f64;
225
+ let s: f64;
226
+ let z: f64;
227
+ let y: f64;
228
+ let mut ix: u32;
229
+ let sign: usize;
230
+
231
+ ix = get_high_word(x);
232
+ sign = (ix >> 31) as usize;
233
+ ix &= 0x7fffffff;
234
+ if ix >= 0x7ff00000 {
235
+ /* erf(nan)=nan, erf(+-inf)=+-1 */
236
+ return 1.0 - 2.0 * (sign as f64) + 1.0 / x;
237
+ }
238
+ if ix < 0x3feb0000 {
239
+ /* |x| < 0.84375 */
240
+ if ix < 0x3e300000 {
241
+ /* |x| < 2**-28 */
242
+ /* avoid underflow */
243
+ return 0.125 * (8.0 * x + EFX8 * x);
244
+ }
245
+ z = x * x;
246
+ r = PP0 + z * (PP1 + z * (PP2 + z * (PP3 + z * PP4)));
247
+ s = 1.0 + z * (QQ1 + z * (QQ2 + z * (QQ3 + z * (QQ4 + z * QQ5))));
248
+ y = r / s;
249
+ return x + x * y;
250
+ }
251
+ if ix < 0x40180000 {
252
+ /* 0.84375 <= |x| < 6 */
253
+ y = 1.0 - erfc2(ix, x);
254
+ } else {
255
+ let x1p_1022 = f64::from_bits(0x0010000000000000);
256
+ y = 1.0 - x1p_1022;
257
+ }
258
+
259
+ if sign != 0 { -y } else { y }
260
+ }
261
+
262
+ /// Complementary error function (f64)
263
+ ///
264
+ /// Calculates the complementary probability.
265
+ /// Is `1 - erf(x)`. Is computed directly, so that you can use it to avoid
266
+ /// the loss of precision that would result from subtracting
267
+ /// large probabilities (on large `x`) from 1.
268
+ pub fn erfc(x: f64) -> f64 {
269
+ let r: f64;
270
+ let s: f64;
271
+ let z: f64;
272
+ let y: f64;
273
+ let mut ix: u32;
274
+ let sign: usize;
275
+
276
+ ix = get_high_word(x);
277
+ sign = (ix >> 31) as usize;
278
+ ix &= 0x7fffffff;
279
+ if ix >= 0x7ff00000 {
280
+ /* erfc(nan)=nan, erfc(+-inf)=0,2 */
281
+ return 2.0 * (sign as f64) + 1.0 / x;
282
+ }
283
+ if ix < 0x3feb0000 {
284
+ /* |x| < 0.84375 */
285
+ if ix < 0x3c700000 {
286
+ /* |x| < 2**-56 */
287
+ return 1.0 - x;
288
+ }
289
+ z = x * x;
290
+ r = PP0 + z * (PP1 + z * (PP2 + z * (PP3 + z * PP4)));
291
+ s = 1.0 + z * (QQ1 + z * (QQ2 + z * (QQ3 + z * (QQ4 + z * QQ5))));
292
+ y = r / s;
293
+ if sign != 0 || ix < 0x3fd00000 {
294
+ /* x < 1/4 */
295
+ return 1.0 - (x + x * y);
296
+ }
297
+ return 0.5 - (x - 0.5 + x * y);
298
+ }
299
+ if ix < 0x403c0000 {
300
+ /* 0.84375 <= |x| < 28 */
301
+ if sign != 0 {
302
+ return 2.0 - erfc2(ix, x);
303
+ } else {
304
+ return erfc2(ix, x);
305
+ }
306
+ }
307
+
308
+ let x1p_1022 = f64::from_bits(0x0010000000000000);
309
+ if sign != 0 {
310
+ 2.0 - x1p_1022
311
+ } else {
312
+ x1p_1022 * x1p_1022
313
+ }
314
+ }
@@ -0,0 +1,226 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/s_erff.c */
2
+ /*
3
+ * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
4
+ */
5
+ /*
6
+ * ====================================================
7
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8
+ *
9
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
10
+ * Permission to use, copy, modify, and distribute this
11
+ * software is freely granted, provided that this notice
12
+ * is preserved.
13
+ * ====================================================
14
+ */
15
+
16
+ use super::{expf, fabsf};
17
+
18
+ const ERX: f32 = 8.4506291151e-01; /* 0x3f58560b */
19
+ /*
20
+ * Coefficients for approximation to erf on [0,0.84375]
21
+ */
22
+ const EFX8: f32 = 1.0270333290e+00; /* 0x3f8375d4 */
23
+ const PP0: f32 = 1.2837916613e-01; /* 0x3e0375d4 */
24
+ const PP1: f32 = -3.2504209876e-01; /* 0xbea66beb */
25
+ const PP2: f32 = -2.8481749818e-02; /* 0xbce9528f */
26
+ const PP3: f32 = -5.7702702470e-03; /* 0xbbbd1489 */
27
+ const PP4: f32 = -2.3763017452e-05; /* 0xb7c756b1 */
28
+ const QQ1: f32 = 3.9791721106e-01; /* 0x3ecbbbce */
29
+ const QQ2: f32 = 6.5022252500e-02; /* 0x3d852a63 */
30
+ const QQ3: f32 = 5.0813062117e-03; /* 0x3ba68116 */
31
+ const QQ4: f32 = 1.3249473704e-04; /* 0x390aee49 */
32
+ const QQ5: f32 = -3.9602282413e-06; /* 0xb684e21a */
33
+ /*
34
+ * Coefficients for approximation to erf in [0.84375,1.25]
35
+ */
36
+ const PA0: f32 = -2.3621185683e-03; /* 0xbb1acdc6 */
37
+ const PA1: f32 = 4.1485610604e-01; /* 0x3ed46805 */
38
+ const PA2: f32 = -3.7220788002e-01; /* 0xbebe9208 */
39
+ const PA3: f32 = 3.1834661961e-01; /* 0x3ea2fe54 */
40
+ const PA4: f32 = -1.1089469492e-01; /* 0xbde31cc2 */
41
+ const PA5: f32 = 3.5478305072e-02; /* 0x3d1151b3 */
42
+ const PA6: f32 = -2.1663755178e-03; /* 0xbb0df9c0 */
43
+ const QA1: f32 = 1.0642088205e-01; /* 0x3dd9f331 */
44
+ const QA2: f32 = 5.4039794207e-01; /* 0x3f0a5785 */
45
+ const QA3: f32 = 7.1828655899e-02; /* 0x3d931ae7 */
46
+ const QA4: f32 = 1.2617121637e-01; /* 0x3e013307 */
47
+ const QA5: f32 = 1.3637083583e-02; /* 0x3c5f6e13 */
48
+ const QA6: f32 = 1.1984500103e-02; /* 0x3c445aa3 */
49
+ /*
50
+ * Coefficients for approximation to erfc in [1.25,1/0.35]
51
+ */
52
+ const RA0: f32 = -9.8649440333e-03; /* 0xbc21a093 */
53
+ const RA1: f32 = -6.9385856390e-01; /* 0xbf31a0b7 */
54
+ const RA2: f32 = -1.0558626175e+01; /* 0xc128f022 */
55
+ const RA3: f32 = -6.2375331879e+01; /* 0xc2798057 */
56
+ const RA4: f32 = -1.6239666748e+02; /* 0xc322658c */
57
+ const RA5: f32 = -1.8460508728e+02; /* 0xc3389ae7 */
58
+ const RA6: f32 = -8.1287437439e+01; /* 0xc2a2932b */
59
+ const RA7: f32 = -9.8143291473e+00; /* 0xc11d077e */
60
+ const SA1: f32 = 1.9651271820e+01; /* 0x419d35ce */
61
+ const SA2: f32 = 1.3765776062e+02; /* 0x4309a863 */
62
+ const SA3: f32 = 4.3456588745e+02; /* 0x43d9486f */
63
+ const SA4: f32 = 6.4538726807e+02; /* 0x442158c9 */
64
+ const SA5: f32 = 4.2900814819e+02; /* 0x43d6810b */
65
+ const SA6: f32 = 1.0863500214e+02; /* 0x42d9451f */
66
+ const SA7: f32 = 6.5702495575e+00; /* 0x40d23f7c */
67
+ const SA8: f32 = -6.0424413532e-02; /* 0xbd777f97 */
68
+ /*
69
+ * Coefficients for approximation to erfc in [1/.35,28]
70
+ */
71
+ const RB0: f32 = -9.8649431020e-03; /* 0xbc21a092 */
72
+ const RB1: f32 = -7.9928326607e-01; /* 0xbf4c9dd4 */
73
+ const RB2: f32 = -1.7757955551e+01; /* 0xc18e104b */
74
+ const RB3: f32 = -1.6063638306e+02; /* 0xc320a2ea */
75
+ const RB4: f32 = -6.3756646729e+02; /* 0xc41f6441 */
76
+ const RB5: f32 = -1.0250950928e+03; /* 0xc480230b */
77
+ const RB6: f32 = -4.8351919556e+02; /* 0xc3f1c275 */
78
+ const SB1: f32 = 3.0338060379e+01; /* 0x41f2b459 */
79
+ const SB2: f32 = 3.2579251099e+02; /* 0x43a2e571 */
80
+ const SB3: f32 = 1.5367296143e+03; /* 0x44c01759 */
81
+ const SB4: f32 = 3.1998581543e+03; /* 0x4547fdbb */
82
+ const SB5: f32 = 2.5530502930e+03; /* 0x451f90ce */
83
+ const SB6: f32 = 4.7452853394e+02; /* 0x43ed43a7 */
84
+ const SB7: f32 = -2.2440952301e+01; /* 0xc1b38712 */
85
+
86
+ fn erfc1(x: f32) -> f32 {
87
+ let s: f32;
88
+ let p: f32;
89
+ let q: f32;
90
+
91
+ s = fabsf(x) - 1.0;
92
+ p = PA0 + s * (PA1 + s * (PA2 + s * (PA3 + s * (PA4 + s * (PA5 + s * PA6)))));
93
+ q = 1.0 + s * (QA1 + s * (QA2 + s * (QA3 + s * (QA4 + s * (QA5 + s * QA6)))));
94
+ return 1.0 - ERX - p / q;
95
+ }
96
+
97
+ fn erfc2(mut ix: u32, mut x: f32) -> f32 {
98
+ let s: f32;
99
+ let r: f32;
100
+ let big_s: f32;
101
+ let z: f32;
102
+
103
+ if ix < 0x3fa00000 {
104
+ /* |x| < 1.25 */
105
+ return erfc1(x);
106
+ }
107
+
108
+ x = fabsf(x);
109
+ s = 1.0 / (x * x);
110
+ if ix < 0x4036db6d {
111
+ /* |x| < 1/0.35 */
112
+ r = RA0 + s * (RA1 + s * (RA2 + s * (RA3 + s * (RA4 + s * (RA5 + s * (RA6 + s * RA7))))));
113
+ big_s = 1.0
114
+ + s * (SA1
115
+ + s * (SA2 + s * (SA3 + s * (SA4 + s * (SA5 + s * (SA6 + s * (SA7 + s * SA8)))))));
116
+ } else {
117
+ /* |x| >= 1/0.35 */
118
+ r = RB0 + s * (RB1 + s * (RB2 + s * (RB3 + s * (RB4 + s * (RB5 + s * RB6)))));
119
+ big_s =
120
+ 1.0 + s * (SB1 + s * (SB2 + s * (SB3 + s * (SB4 + s * (SB5 + s * (SB6 + s * SB7))))));
121
+ }
122
+ ix = x.to_bits();
123
+ z = f32::from_bits(ix & 0xffffe000);
124
+
125
+ expf(-z * z - 0.5625) * expf((z - x) * (z + x) + r / big_s) / x
126
+ }
127
+
128
+ /// Error function (f32)
129
+ ///
130
+ /// Calculates an approximation to the “error function”, which estimates
131
+ /// the probability that an observation will fall within x standard
132
+ /// deviations of the mean (assuming a normal distribution).
133
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
134
+ pub fn erff(x: f32) -> f32 {
135
+ let r: f32;
136
+ let s: f32;
137
+ let z: f32;
138
+ let y: f32;
139
+ let mut ix: u32;
140
+ let sign: usize;
141
+
142
+ ix = x.to_bits();
143
+ sign = (ix >> 31) as usize;
144
+ ix &= 0x7fffffff;
145
+ if ix >= 0x7f800000 {
146
+ /* erf(nan)=nan, erf(+-inf)=+-1 */
147
+ return 1.0 - 2.0 * (sign as f32) + 1.0 / x;
148
+ }
149
+ if ix < 0x3f580000 {
150
+ /* |x| < 0.84375 */
151
+ if ix < 0x31800000 {
152
+ /* |x| < 2**-28 */
153
+ /*avoid underflow */
154
+ return 0.125 * (8.0 * x + EFX8 * x);
155
+ }
156
+ z = x * x;
157
+ r = PP0 + z * (PP1 + z * (PP2 + z * (PP3 + z * PP4)));
158
+ s = 1.0 + z * (QQ1 + z * (QQ2 + z * (QQ3 + z * (QQ4 + z * QQ5))));
159
+ y = r / s;
160
+ return x + x * y;
161
+ }
162
+ if ix < 0x40c00000 {
163
+ /* |x| < 6 */
164
+ y = 1.0 - erfc2(ix, x);
165
+ } else {
166
+ let x1p_120 = f32::from_bits(0x03800000);
167
+ y = 1.0 - x1p_120;
168
+ }
169
+
170
+ if sign != 0 { -y } else { y }
171
+ }
172
+
173
+ /// Complementary error function (f32)
174
+ ///
175
+ /// Calculates the complementary probability.
176
+ /// Is `1 - erf(x)`. Is computed directly, so that you can use it to avoid
177
+ /// the loss of precision that would result from subtracting
178
+ /// large probabilities (on large `x`) from 1.
179
+ pub fn erfcf(x: f32) -> f32 {
180
+ let r: f32;
181
+ let s: f32;
182
+ let z: f32;
183
+ let y: f32;
184
+ let mut ix: u32;
185
+ let sign: usize;
186
+
187
+ ix = x.to_bits();
188
+ sign = (ix >> 31) as usize;
189
+ ix &= 0x7fffffff;
190
+ if ix >= 0x7f800000 {
191
+ /* erfc(nan)=nan, erfc(+-inf)=0,2 */
192
+ return 2.0 * (sign as f32) + 1.0 / x;
193
+ }
194
+
195
+ if ix < 0x3f580000 {
196
+ /* |x| < 0.84375 */
197
+ if ix < 0x23800000 {
198
+ /* |x| < 2**-56 */
199
+ return 1.0 - x;
200
+ }
201
+ z = x * x;
202
+ r = PP0 + z * (PP1 + z * (PP2 + z * (PP3 + z * PP4)));
203
+ s = 1.0 + z * (QQ1 + z * (QQ2 + z * (QQ3 + z * (QQ4 + z * QQ5))));
204
+ y = r / s;
205
+ if sign != 0 || ix < 0x3e800000 {
206
+ /* x < 1/4 */
207
+ return 1.0 - (x + x * y);
208
+ }
209
+ return 0.5 - (x - 0.5 + x * y);
210
+ }
211
+ if ix < 0x41e00000 {
212
+ /* |x| < 28 */
213
+ if sign != 0 {
214
+ return 2.0 - erfc2(ix, x);
215
+ } else {
216
+ return erfc2(ix, x);
217
+ }
218
+ }
219
+
220
+ let x1p_120 = f32::from_bits(0x03800000);
221
+ if sign != 0 {
222
+ 2.0 - x1p_120
223
+ } else {
224
+ x1p_120 * x1p_120
225
+ }
226
+ }
@@ -0,0 +1,156 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_exp.c */
2
+ /*
3
+ * ====================================================
4
+ * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
5
+ *
6
+ * Permission to use, copy, modify, and distribute this
7
+ * software is freely granted, provided that this notice
8
+ * is preserved.
9
+ * ====================================================
10
+ */
11
+ /* exp(x)
12
+ * Returns the exponential of x.
13
+ *
14
+ * Method
15
+ * 1. Argument reduction:
16
+ * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
17
+ * Given x, find r and integer k such that
18
+ *
19
+ * x = k*ln2 + r, |r| <= 0.5*ln2.
20
+ *
21
+ * Here r will be represented as r = hi-lo for better
22
+ * accuracy.
23
+ *
24
+ * 2. Approximation of exp(r) by a special rational function on
25
+ * the interval [0,0.34658]:
26
+ * Write
27
+ * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
28
+ * We use a special Remez algorithm on [0,0.34658] to generate
29
+ * a polynomial of degree 5 to approximate R. The maximum error
30
+ * of this polynomial approximation is bounded by 2**-59. In
31
+ * other words,
32
+ * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
33
+ * (where z=r*r, and the values of P1 to P5 are listed below)
34
+ * and
35
+ * | 5 | -59
36
+ * | 2.0+P1*z+...+P5*z - R(z) | <= 2
37
+ * | |
38
+ * The computation of exp(r) thus becomes
39
+ * 2*r
40
+ * exp(r) = 1 + ----------
41
+ * R(r) - r
42
+ * r*c(r)
43
+ * = 1 + r + ----------- (for better accuracy)
44
+ * 2 - c(r)
45
+ * where
46
+ * 2 4 10
47
+ * c(r) = r - (P1*r + P2*r + ... + P5*r ).
48
+ *
49
+ * 3. Scale back to obtain exp(x):
50
+ * From step 1, we have
51
+ * exp(x) = 2^k * exp(r)
52
+ *
53
+ * Special cases:
54
+ * exp(INF) is INF, exp(NaN) is NaN;
55
+ * exp(-INF) is 0, and
56
+ * for finite argument, only exp(0)=1 is exact.
57
+ *
58
+ * Accuracy:
59
+ * according to an error analysis, the error is always less than
60
+ * 1 ulp (unit in the last place).
61
+ *
62
+ * Misc. info.
63
+ * For IEEE double
64
+ * if x > 709.782712893383973096 then exp(x) overflows
65
+ * if x < -745.133219101941108420 then exp(x) underflows
66
+ */
67
+
68
+ use super::scalbn;
69
+
70
+ const HALF: [f64; 2] = [0.5, -0.5];
71
+ const LN2HI: f64 = 6.93147180369123816490e-01; /* 0x3fe62e42, 0xfee00000 */
72
+ const LN2LO: f64 = 1.90821492927058770002e-10; /* 0x3dea39ef, 0x35793c76 */
73
+ const INVLN2: f64 = 1.44269504088896338700e+00; /* 0x3ff71547, 0x652b82fe */
74
+ const P1: f64 = 1.66666666666666019037e-01; /* 0x3FC55555, 0x5555553E */
75
+ const P2: f64 = -2.77777777770155933842e-03; /* 0xBF66C16C, 0x16BEBD93 */
76
+ const P3: f64 = 6.61375632143793436117e-05; /* 0x3F11566A, 0xAF25DE2C */
77
+ const P4: f64 = -1.65339022054652515390e-06; /* 0xBEBBBD41, 0xC5D26BF1 */
78
+ const P5: f64 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
79
+
80
+ /// Exponential, base *e* (f64)
81
+ ///
82
+ /// Calculate the exponential of `x`, that is, *e* raised to the power `x`
83
+ /// (where *e* is the base of the natural system of logarithms, approximately 2.71828).
84
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
85
+ pub fn exp(mut x: f64) -> f64 {
86
+ select_implementation! {
87
+ name: x87_exp,
88
+ use_arch_required: x86_no_sse,
89
+ args: x,
90
+ }
91
+
92
+ let x1p1023 = f64::from_bits(0x7fe0000000000000); // 0x1p1023 === 2 ^ 1023
93
+ let x1p_149 = f64::from_bits(0x36a0000000000000); // 0x1p-149 === 2 ^ -149
94
+
95
+ let hi: f64;
96
+ let lo: f64;
97
+ let c: f64;
98
+ let xx: f64;
99
+ let y: f64;
100
+ let k: i32;
101
+ let sign: i32;
102
+ let mut hx: u32;
103
+
104
+ hx = (x.to_bits() >> 32) as u32;
105
+ sign = (hx >> 31) as i32;
106
+ hx &= 0x7fffffff; /* high word of |x| */
107
+
108
+ /* special cases */
109
+ if hx >= 0x4086232b {
110
+ /* if |x| >= 708.39... */
111
+ if x.is_nan() {
112
+ return x;
113
+ }
114
+ if x > 709.782712893383973096 {
115
+ /* overflow if x!=inf */
116
+ x *= x1p1023;
117
+ return x;
118
+ }
119
+ if x < -708.39641853226410622 {
120
+ /* underflow if x!=-inf */
121
+ force_eval!((-x1p_149 / x) as f32);
122
+ if x < -745.13321910194110842 {
123
+ return 0.;
124
+ }
125
+ }
126
+ }
127
+
128
+ /* argument reduction */
129
+ if hx > 0x3fd62e42 {
130
+ /* if |x| > 0.5 ln2 */
131
+ if hx >= 0x3ff0a2b2 {
132
+ /* if |x| >= 1.5 ln2 */
133
+ k = (INVLN2 * x + i!(HALF, sign as usize)) as i32;
134
+ } else {
135
+ k = 1 - sign - sign;
136
+ }
137
+ hi = x - k as f64 * LN2HI; /* k*ln2hi is exact here */
138
+ lo = k as f64 * LN2LO;
139
+ x = hi - lo;
140
+ } else if hx > 0x3e300000 {
141
+ /* if |x| > 2**-28 */
142
+ k = 0;
143
+ hi = x;
144
+ lo = 0.;
145
+ } else {
146
+ /* inexact if x!=0 */
147
+ force_eval!(x1p1023 + x);
148
+ return 1. + x;
149
+ }
150
+
151
+ /* x is now in primary range */
152
+ xx = x * x;
153
+ c = x - xx * (P1 + xx * (P2 + xx * (P3 + xx * (P4 + xx * P5))));
154
+ y = 1. + (x * c / (2. - c) - lo + hi);
155
+ if k == 0 { y } else { scalbn(y, k) }
156
+ }