@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,343 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_powf.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 core::cmp::Ordering;
17
+
18
+ use super::{fabsf, scalbnf, sqrtf};
19
+
20
+ const BP: [f32; 2] = [1.0, 1.5];
21
+ const DP_H: [f32; 2] = [0.0, 5.84960938e-01]; /* 0x3f15c000 */
22
+ const DP_L: [f32; 2] = [0.0, 1.56322085e-06]; /* 0x35d1cfdc */
23
+ const TWO24: f32 = 16777216.0; /* 0x4b800000 */
24
+ const HUGE: f32 = 1.0e30;
25
+ const TINY: f32 = 1.0e-30;
26
+ const L1: f32 = 6.0000002384e-01; /* 0x3f19999a */
27
+ const L2: f32 = 4.2857143283e-01; /* 0x3edb6db7 */
28
+ const L3: f32 = 3.3333334327e-01; /* 0x3eaaaaab */
29
+ const L4: f32 = 2.7272811532e-01; /* 0x3e8ba305 */
30
+ const L5: f32 = 2.3066075146e-01; /* 0x3e6c3255 */
31
+ const L6: f32 = 2.0697501302e-01; /* 0x3e53f142 */
32
+ const P1: f32 = 1.6666667163e-01; /* 0x3e2aaaab */
33
+ const P2: f32 = -2.7777778450e-03; /* 0xbb360b61 */
34
+ const P3: f32 = 6.6137559770e-05; /* 0x388ab355 */
35
+ const P4: f32 = -1.6533901999e-06; /* 0xb5ddea0e */
36
+ const P5: f32 = 4.1381369442e-08; /* 0x3331bb4c */
37
+ const LG2: f32 = 6.9314718246e-01; /* 0x3f317218 */
38
+ const LG2_H: f32 = 6.93145752e-01; /* 0x3f317200 */
39
+ const LG2_L: f32 = 1.42860654e-06; /* 0x35bfbe8c */
40
+ const OVT: f32 = 4.2995665694e-08; /* -(128-log2(ovfl+.5ulp)) */
41
+ const CP: f32 = 9.6179670095e-01; /* 0x3f76384f =2/(3ln2) */
42
+ const CP_H: f32 = 9.6191406250e-01; /* 0x3f764000 =12b cp */
43
+ const CP_L: f32 = -1.1736857402e-04; /* 0xb8f623c6 =tail of cp_h */
44
+ const IVLN2: f32 = 1.4426950216e+00;
45
+ const IVLN2_H: f32 = 1.4426879883e+00;
46
+ const IVLN2_L: f32 = 7.0526075433e-06;
47
+
48
+ /// Returns `x` to the power of `y` (f32).
49
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
50
+ pub fn powf(x: f32, y: f32) -> f32 {
51
+ let mut z: f32;
52
+ let mut ax: f32;
53
+ let z_h: f32;
54
+ let z_l: f32;
55
+ let mut p_h: f32;
56
+ let mut p_l: f32;
57
+ let y1: f32;
58
+ let mut t1: f32;
59
+ let t2: f32;
60
+ let mut r: f32;
61
+ let s: f32;
62
+ let mut sn: f32;
63
+ let mut t: f32;
64
+ let mut u: f32;
65
+ let mut v: f32;
66
+ let mut w: f32;
67
+ let i: i32;
68
+ let mut j: i32;
69
+ let mut k: i32;
70
+ let mut yisint: i32;
71
+ let mut n: i32;
72
+ let hx: i32;
73
+ let hy: i32;
74
+ let mut ix: i32;
75
+ let iy: i32;
76
+ let mut is: i32;
77
+
78
+ hx = x.to_bits() as i32;
79
+ hy = y.to_bits() as i32;
80
+
81
+ ix = hx & 0x7fffffff;
82
+ iy = hy & 0x7fffffff;
83
+
84
+ /* x**0 = 1, even if x is NaN */
85
+ if iy == 0 {
86
+ return 1.0;
87
+ }
88
+
89
+ /* 1**y = 1, even if y is NaN */
90
+ if hx == 0x3f800000 {
91
+ return 1.0;
92
+ }
93
+
94
+ /* NaN if either arg is NaN */
95
+ if ix > 0x7f800000 || iy > 0x7f800000 {
96
+ return x + y;
97
+ }
98
+
99
+ /* determine if y is an odd int when x < 0
100
+ * yisint = 0 ... y is not an integer
101
+ * yisint = 1 ... y is an odd int
102
+ * yisint = 2 ... y is an even int
103
+ */
104
+ yisint = 0;
105
+ if hx < 0 {
106
+ if iy >= 0x4b800000 {
107
+ yisint = 2; /* even integer y */
108
+ } else if iy >= 0x3f800000 {
109
+ k = (iy >> 23) - 0x7f; /* exponent */
110
+ j = iy >> (23 - k);
111
+ if (j << (23 - k)) == iy {
112
+ yisint = 2 - (j & 1);
113
+ }
114
+ }
115
+ }
116
+
117
+ /* special value of y */
118
+ if iy == 0x7f800000 {
119
+ /* y is +-inf */
120
+ match ix.cmp(&0x3f800000) {
121
+ /* (-1)**+-inf is 1 */
122
+ Ordering::Equal => return 1.0,
123
+ /* (|x|>1)**+-inf = inf,0 */
124
+ Ordering::Greater => return if hy >= 0 { y } else { 0.0 },
125
+ /* (|x|<1)**+-inf = 0,inf */
126
+ Ordering::Less => return if hy >= 0 { 0.0 } else { -y },
127
+ }
128
+ }
129
+ if iy == 0x3f800000 {
130
+ /* y is +-1 */
131
+ return if hy >= 0 { x } else { 1.0 / x };
132
+ }
133
+
134
+ if hy == 0x40000000 {
135
+ /* y is 2 */
136
+ return x * x;
137
+ }
138
+
139
+ if hy == 0x3f000000
140
+ /* y is 0.5 */
141
+ && hx >= 0
142
+ {
143
+ /* x >= +0 */
144
+ return sqrtf(x);
145
+ }
146
+
147
+ ax = fabsf(x);
148
+ /* special value of x */
149
+ if ix == 0x7f800000 || ix == 0 || ix == 0x3f800000 {
150
+ /* x is +-0,+-inf,+-1 */
151
+ z = ax;
152
+ if hy < 0 {
153
+ /* z = (1/|x|) */
154
+ z = 1.0 / z;
155
+ }
156
+
157
+ if hx < 0 {
158
+ if ((ix - 0x3f800000) | yisint) == 0 {
159
+ z = (z - z) / (z - z); /* (-1)**non-int is NaN */
160
+ } else if yisint == 1 {
161
+ z = -z; /* (x<0)**odd = -(|x|**odd) */
162
+ }
163
+ }
164
+ return z;
165
+ }
166
+
167
+ sn = 1.0; /* sign of result */
168
+ if hx < 0 {
169
+ if yisint == 0 {
170
+ /* (x<0)**(non-int) is NaN */
171
+ return (x - x) / (x - x);
172
+ }
173
+
174
+ if yisint == 1 {
175
+ /* (x<0)**(odd int) */
176
+ sn = -1.0;
177
+ }
178
+ }
179
+
180
+ /* |y| is HUGE */
181
+ if iy > 0x4d000000 {
182
+ /* if |y| > 2**27 */
183
+ /* over/underflow if x is not close to one */
184
+ if ix < 0x3f7ffff8 {
185
+ return if hy < 0 {
186
+ sn * HUGE * HUGE
187
+ } else {
188
+ sn * TINY * TINY
189
+ };
190
+ }
191
+
192
+ if ix > 0x3f800007 {
193
+ return if hy > 0 {
194
+ sn * HUGE * HUGE
195
+ } else {
196
+ sn * TINY * TINY
197
+ };
198
+ }
199
+
200
+ /* now |1-x| is TINY <= 2**-20, suffice to compute
201
+ log(x) by x-x^2/2+x^3/3-x^4/4 */
202
+ t = ax - 1.; /* t has 20 trailing zeros */
203
+ w = (t * t) * (0.5 - t * (0.333333333333 - t * 0.25));
204
+ u = IVLN2_H * t; /* IVLN2_H has 16 sig. bits */
205
+ v = t * IVLN2_L - w * IVLN2;
206
+ t1 = u + v;
207
+ is = t1.to_bits() as i32;
208
+ t1 = f32::from_bits(is as u32 & 0xfffff000);
209
+ t2 = v - (t1 - u);
210
+ } else {
211
+ let mut s2: f32;
212
+ let mut s_h: f32;
213
+ let s_l: f32;
214
+ let mut t_h: f32;
215
+ let mut t_l: f32;
216
+
217
+ n = 0;
218
+ /* take care subnormal number */
219
+ if ix < 0x00800000 {
220
+ ax *= TWO24;
221
+ n -= 24;
222
+ ix = ax.to_bits() as i32;
223
+ }
224
+ n += ((ix) >> 23) - 0x7f;
225
+ j = ix & 0x007fffff;
226
+ /* determine interval */
227
+ ix = j | 0x3f800000; /* normalize ix */
228
+ if j <= 0x1cc471 {
229
+ /* |x|<sqrt(3/2) */
230
+ k = 0;
231
+ } else if j < 0x5db3d7 {
232
+ /* |x|<sqrt(3) */
233
+ k = 1;
234
+ } else {
235
+ k = 0;
236
+ n += 1;
237
+ ix -= 0x00800000;
238
+ }
239
+ ax = f32::from_bits(ix as u32);
240
+
241
+ /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
242
+ u = ax - i!(BP, k as usize); /* bp[0]=1.0, bp[1]=1.5 */
243
+ v = 1.0 / (ax + i!(BP, k as usize));
244
+ s = u * v;
245
+ s_h = s;
246
+ is = s_h.to_bits() as i32;
247
+ s_h = f32::from_bits(is as u32 & 0xfffff000);
248
+ /* t_h=ax+bp[k] High */
249
+ is = (((ix as u32 >> 1) & 0xfffff000) | 0x20000000) as i32;
250
+ t_h = f32::from_bits(is as u32 + 0x00400000 + ((k as u32) << 21));
251
+ t_l = ax - (t_h - i!(BP, k as usize));
252
+ s_l = v * ((u - s_h * t_h) - s_h * t_l);
253
+ /* compute log(ax) */
254
+ s2 = s * s;
255
+ r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));
256
+ r += s_l * (s_h + s);
257
+ s2 = s_h * s_h;
258
+ t_h = 3.0 + s2 + r;
259
+ is = t_h.to_bits() as i32;
260
+ t_h = f32::from_bits(is as u32 & 0xfffff000);
261
+ t_l = r - ((t_h - 3.0) - s2);
262
+ /* u+v = s*(1+...) */
263
+ u = s_h * t_h;
264
+ v = s_l * t_h + t_l * s;
265
+ /* 2/(3log2)*(s+...) */
266
+ p_h = u + v;
267
+ is = p_h.to_bits() as i32;
268
+ p_h = f32::from_bits(is as u32 & 0xfffff000);
269
+ p_l = v - (p_h - u);
270
+ z_h = CP_H * p_h; /* cp_h+cp_l = 2/(3*log2) */
271
+ z_l = CP_L * p_h + p_l * CP + i!(DP_L, k as usize);
272
+ /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
273
+ t = n as f32;
274
+ t1 = ((z_h + z_l) + i!(DP_H, k as usize)) + t;
275
+ is = t1.to_bits() as i32;
276
+ t1 = f32::from_bits(is as u32 & 0xfffff000);
277
+ t2 = z_l - (((t1 - t) - i!(DP_H, k as usize)) - z_h);
278
+ };
279
+
280
+ /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
281
+ is = y.to_bits() as i32;
282
+ y1 = f32::from_bits(is as u32 & 0xfffff000);
283
+ p_l = (y - y1) * t1 + y * t2;
284
+ p_h = y1 * t1;
285
+ z = p_l + p_h;
286
+ j = z.to_bits() as i32;
287
+ if j > 0x43000000 {
288
+ /* if z > 128 */
289
+ return sn * HUGE * HUGE; /* overflow */
290
+ } else if j == 0x43000000 {
291
+ /* if z == 128 */
292
+ if p_l + OVT > z - p_h {
293
+ return sn * HUGE * HUGE; /* overflow */
294
+ }
295
+ } else if (j & 0x7fffffff) > 0x43160000 {
296
+ /* z < -150 */
297
+ // FIXME: check should be (uint32_t)j > 0xc3160000
298
+ return sn * TINY * TINY; /* underflow */
299
+ } else if j as u32 == 0xc3160000
300
+ /* z == -150 */
301
+ && p_l <= z - p_h
302
+ {
303
+ return sn * TINY * TINY; /* underflow */
304
+ }
305
+
306
+ /*
307
+ * compute 2**(p_h+p_l)
308
+ */
309
+ i = j & 0x7fffffff;
310
+ k = (i >> 23) - 0x7f;
311
+ n = 0;
312
+ if i > 0x3f000000 {
313
+ /* if |z| > 0.5, set n = [z+0.5] */
314
+ n = j + (0x00800000 >> (k + 1));
315
+ k = ((n & 0x7fffffff) >> 23) - 0x7f; /* new k for n */
316
+ t = f32::from_bits(n as u32 & !(0x007fffff >> k));
317
+ n = ((n & 0x007fffff) | 0x00800000) >> (23 - k);
318
+ if j < 0 {
319
+ n = -n;
320
+ }
321
+ p_h -= t;
322
+ }
323
+ t = p_l + p_h;
324
+ is = t.to_bits() as i32;
325
+ t = f32::from_bits(is as u32 & 0xffff8000);
326
+ u = t * LG2_H;
327
+ v = (p_l - (t - p_h)) * LG2 + t * LG2_L;
328
+ z = u + v;
329
+ w = v - (z - u);
330
+ t = z * z;
331
+ t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));
332
+ r = (z * t1) / (t1 - 2.0) - (w + z * w);
333
+ z = 1.0 - (r - z);
334
+ j = z.to_bits() as i32;
335
+ j += n << 23;
336
+ if (j >> 23) <= 0 {
337
+ /* subnormal output */
338
+ z = scalbnf(z, n);
339
+ } else {
340
+ z = f32::from_bits(j as u32);
341
+ }
342
+ sn * z
343
+ }
@@ -0,0 +1,235 @@
1
+ // origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2.c
2
+ //
3
+ // ====================================================
4
+ // Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
+ //
6
+ // Developed at SunPro, a Sun Microsystems, Inc. business.
7
+ // Permission to use, copy, modify, and distribute this
8
+ // software is freely granted, provided that this notice
9
+ // is preserved.
10
+ // ====================================================
11
+ //
12
+ // Optimized by Bruce D. Evans. */
13
+ use super::rem_pio2_large;
14
+
15
+ // #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
16
+ // #define EPS DBL_EPSILON
17
+ const EPS: f64 = 2.2204460492503131e-16;
18
+ // #elif FLT_EVAL_METHOD==2
19
+ // #define EPS LDBL_EPSILON
20
+ // #endif
21
+
22
+ // TODO: Support FLT_EVAL_METHOD?
23
+
24
+ const TO_INT: f64 = 1.5 / EPS;
25
+ /// 53 bits of 2/pi
26
+ const INV_PIO2: f64 = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */
27
+ /// first 33 bits of pi/2
28
+ const PIO2_1: f64 = 1.57079632673412561417e+00; /* 0x3FF921FB, 0x54400000 */
29
+ /// pi/2 - PIO2_1
30
+ const PIO2_1T: f64 = 6.07710050650619224932e-11; /* 0x3DD0B461, 0x1A626331 */
31
+ /// second 33 bits of pi/2
32
+ const PIO2_2: f64 = 6.07710050630396597660e-11; /* 0x3DD0B461, 0x1A600000 */
33
+ /// pi/2 - (PIO2_1+PIO2_2)
34
+ const PIO2_2T: f64 = 2.02226624879595063154e-21; /* 0x3BA3198A, 0x2E037073 */
35
+ /// third 33 bits of pi/2
36
+ const PIO2_3: f64 = 2.02226624871116645580e-21; /* 0x3BA3198A, 0x2E000000 */
37
+ /// pi/2 - (PIO2_1+PIO2_2+PIO2_3)
38
+ const PIO2_3T: f64 = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
39
+
40
+ // return the remainder of x rem pi/2 in y[0]+y[1]
41
+ // use rem_pio2_large() for large x
42
+ //
43
+ // caller must handle the case when reduction is not needed: |x| ~<= pi/4 */
44
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
45
+ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
46
+ let x1p24 = f64::from_bits(0x4170000000000000);
47
+
48
+ let sign = (f64::to_bits(x) >> 63) as i32;
49
+ let ix = (f64::to_bits(x) >> 32) as u32 & 0x7fffffff;
50
+
51
+ fn medium(x: f64, ix: u32) -> (i32, f64, f64) {
52
+ /* rint(x/(pi/2)), Assume round-to-nearest. */
53
+ let tmp = x * INV_PIO2 + TO_INT;
54
+ // force rounding of tmp to it's storage format on x87 to avoid
55
+ // excess precision issues.
56
+ #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
57
+ let tmp = force_eval!(tmp);
58
+ let f_n = tmp - TO_INT;
59
+ let n = f_n as i32;
60
+ let mut r = x - f_n * PIO2_1;
61
+ let mut w = f_n * PIO2_1T; /* 1st round, good to 85 bits */
62
+ let mut y0 = r - w;
63
+ let ui = f64::to_bits(y0);
64
+ let ey = (ui >> 52) as i32 & 0x7ff;
65
+ let ex = (ix >> 20) as i32;
66
+ if ex - ey > 16 {
67
+ /* 2nd round, good to 118 bits */
68
+ let t = r;
69
+ w = f_n * PIO2_2;
70
+ r = t - w;
71
+ w = f_n * PIO2_2T - ((t - r) - w);
72
+ y0 = r - w;
73
+ let ey = (f64::to_bits(y0) >> 52) as i32 & 0x7ff;
74
+ if ex - ey > 49 {
75
+ /* 3rd round, good to 151 bits, covers all cases */
76
+ let t = r;
77
+ w = f_n * PIO2_3;
78
+ r = t - w;
79
+ w = f_n * PIO2_3T - ((t - r) - w);
80
+ y0 = r - w;
81
+ }
82
+ }
83
+ let y1 = (r - y0) - w;
84
+ (n, y0, y1)
85
+ }
86
+
87
+ if ix <= 0x400f6a7a {
88
+ /* |x| ~<= 5pi/4 */
89
+ if (ix & 0xfffff) == 0x921fb {
90
+ /* |x| ~= pi/2 or 2pi/2 */
91
+ return medium(x, ix); /* cancellation -- use medium case */
92
+ }
93
+ if ix <= 0x4002d97c {
94
+ /* |x| ~<= 3pi/4 */
95
+ if sign == 0 {
96
+ let z = x - PIO2_1; /* one round good to 85 bits */
97
+ let y0 = z - PIO2_1T;
98
+ let y1 = (z - y0) - PIO2_1T;
99
+ return (1, y0, y1);
100
+ } else {
101
+ let z = x + PIO2_1;
102
+ let y0 = z + PIO2_1T;
103
+ let y1 = (z - y0) + PIO2_1T;
104
+ return (-1, y0, y1);
105
+ }
106
+ } else if sign == 0 {
107
+ let z = x - 2.0 * PIO2_1;
108
+ let y0 = z - 2.0 * PIO2_1T;
109
+ let y1 = (z - y0) - 2.0 * PIO2_1T;
110
+ return (2, y0, y1);
111
+ } else {
112
+ let z = x + 2.0 * PIO2_1;
113
+ let y0 = z + 2.0 * PIO2_1T;
114
+ let y1 = (z - y0) + 2.0 * PIO2_1T;
115
+ return (-2, y0, y1);
116
+ }
117
+ }
118
+ if ix <= 0x401c463b {
119
+ /* |x| ~<= 9pi/4 */
120
+ if ix <= 0x4015fdbc {
121
+ /* |x| ~<= 7pi/4 */
122
+ if ix == 0x4012d97c {
123
+ /* |x| ~= 3pi/2 */
124
+ return medium(x, ix);
125
+ }
126
+ if sign == 0 {
127
+ let z = x - 3.0 * PIO2_1;
128
+ let y0 = z - 3.0 * PIO2_1T;
129
+ let y1 = (z - y0) - 3.0 * PIO2_1T;
130
+ return (3, y0, y1);
131
+ } else {
132
+ let z = x + 3.0 * PIO2_1;
133
+ let y0 = z + 3.0 * PIO2_1T;
134
+ let y1 = (z - y0) + 3.0 * PIO2_1T;
135
+ return (-3, y0, y1);
136
+ }
137
+ } else {
138
+ if ix == 0x401921fb {
139
+ /* |x| ~= 4pi/2 */
140
+ return medium(x, ix);
141
+ }
142
+ if sign == 0 {
143
+ let z = x - 4.0 * PIO2_1;
144
+ let y0 = z - 4.0 * PIO2_1T;
145
+ let y1 = (z - y0) - 4.0 * PIO2_1T;
146
+ return (4, y0, y1);
147
+ } else {
148
+ let z = x + 4.0 * PIO2_1;
149
+ let y0 = z + 4.0 * PIO2_1T;
150
+ let y1 = (z - y0) + 4.0 * PIO2_1T;
151
+ return (-4, y0, y1);
152
+ }
153
+ }
154
+ }
155
+ if ix < 0x413921fb {
156
+ /* |x| ~< 2^20*(pi/2), medium size */
157
+ return medium(x, ix);
158
+ }
159
+ /*
160
+ * all other (large) arguments
161
+ */
162
+ if ix >= 0x7ff00000 {
163
+ /* x is inf or NaN */
164
+ let y0 = x - x;
165
+ let y1 = y0;
166
+ return (0, y0, y1);
167
+ }
168
+ /* set z = scalbn(|x|,-ilogb(x)+23) */
169
+ let mut ui = f64::to_bits(x);
170
+ ui &= (!1) >> 12;
171
+ ui |= (0x3ff + 23) << 52;
172
+ let mut z = f64::from_bits(ui);
173
+ let mut tx = [0.0; 3];
174
+ for i in 0..2 {
175
+ i!(tx,i, =, z as i32 as f64);
176
+ z = (z - i!(tx, i)) * x1p24;
177
+ }
178
+ i!(tx,2, =, z);
179
+ /* skip zero terms, first term is non-zero */
180
+ let mut i = 2;
181
+ while i != 0 && i!(tx, i) == 0.0 {
182
+ i -= 1;
183
+ }
184
+ let mut ty = [0.0; 3];
185
+ let n = rem_pio2_large(&tx[..=i], &mut ty, ((ix as i32) >> 20) - (0x3ff + 23), 1);
186
+ if sign != 0 {
187
+ return (-n, -i!(ty, 0), -i!(ty, 1));
188
+ }
189
+ (n, i!(ty, 0), i!(ty, 1))
190
+ }
191
+
192
+ #[cfg(test)]
193
+ mod tests {
194
+ use super::rem_pio2;
195
+
196
+ #[test]
197
+ // FIXME(correctness): inaccurate results on i586
198
+ #[cfg_attr(x86_no_sse, ignore)]
199
+ fn test_near_pi() {
200
+ let arg = 3.141592025756836;
201
+ let arg = force_eval!(arg);
202
+ assert_eq!(
203
+ rem_pio2(arg),
204
+ (2, -6.278329573009626e-7, -2.1125998133974653e-23)
205
+ );
206
+ let arg = 3.141592033207416;
207
+ let arg = force_eval!(arg);
208
+ assert_eq!(
209
+ rem_pio2(arg),
210
+ (2, -6.20382377148128e-7, -2.1125998133974653e-23)
211
+ );
212
+ let arg = 3.141592144966125;
213
+ let arg = force_eval!(arg);
214
+ assert_eq!(
215
+ rem_pio2(arg),
216
+ (2, -5.086236681942706e-7, -2.1125998133974653e-23)
217
+ );
218
+ let arg = 3.141592979431152;
219
+ let arg = force_eval!(arg);
220
+ assert_eq!(
221
+ rem_pio2(arg),
222
+ (2, 3.2584135866119817e-7, -2.1125998133974653e-23)
223
+ );
224
+ }
225
+
226
+ #[test]
227
+ fn test_overflow_b9b847() {
228
+ let _ = rem_pio2(-3054214.5490637687);
229
+ }
230
+
231
+ #[test]
232
+ fn test_overflow_4747b9() {
233
+ let _ = rem_pio2(917340800458.2274);
234
+ }
235
+ }