@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,116 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_log10.c */
2
+ /*
3
+ * ====================================================
4
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
+ *
6
+ * Developed at SunSoft, 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
+ /*
13
+ * Return the base 10 logarithm of x. See log.c for most comments.
14
+ *
15
+ * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2
16
+ * as in log.c, then combine and scale in extra precision:
17
+ * log10(x) = (f - f*f/2 + r)/log(10) + k*log10(2)
18
+ */
19
+
20
+ const IVLN10HI: f64 = 4.34294481878168880939e-01; /* 0x3fdbcb7b, 0x15200000 */
21
+ const IVLN10LO: f64 = 2.50829467116452752298e-11; /* 0x3dbb9438, 0xca9aadd5 */
22
+ const LOG10_2HI: f64 = 3.01029995663611771306e-01; /* 0x3FD34413, 0x509F6000 */
23
+ const LOG10_2LO: f64 = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
24
+ const LG1: f64 = 6.666666666666735130e-01; /* 3FE55555 55555593 */
25
+ const LG2: f64 = 3.999999999940941908e-01; /* 3FD99999 9997FA04 */
26
+ const LG3: f64 = 2.857142874366239149e-01; /* 3FD24924 94229359 */
27
+ const LG4: f64 = 2.222219843214978396e-01; /* 3FCC71C5 1D8E78AF */
28
+ const LG5: f64 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
29
+ const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
30
+ const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
31
+
32
+ /// The base 10 logarithm of `x` (f64).
33
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
34
+ pub fn log10(mut x: f64) -> f64 {
35
+ let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54
36
+
37
+ let mut ui: u64 = x.to_bits();
38
+ let hfsq: f64;
39
+ let f: f64;
40
+ let s: f64;
41
+ let z: f64;
42
+ let r: f64;
43
+ let mut w: f64;
44
+ let t1: f64;
45
+ let t2: f64;
46
+ let dk: f64;
47
+ let y: f64;
48
+ let mut hi: f64;
49
+ let lo: f64;
50
+ let mut val_hi: f64;
51
+ let mut val_lo: f64;
52
+ let mut hx: u32;
53
+ let mut k: i32;
54
+
55
+ hx = (ui >> 32) as u32;
56
+ k = 0;
57
+ if hx < 0x00100000 || (hx >> 31) > 0 {
58
+ if ui << 1 == 0 {
59
+ return -1. / (x * x); /* log(+-0)=-inf */
60
+ }
61
+ if (hx >> 31) > 0 {
62
+ return (x - x) / 0.0; /* log(-#) = NaN */
63
+ }
64
+ /* subnormal number, scale x up */
65
+ k -= 54;
66
+ x *= x1p54;
67
+ ui = x.to_bits();
68
+ hx = (ui >> 32) as u32;
69
+ } else if hx >= 0x7ff00000 {
70
+ return x;
71
+ } else if hx == 0x3ff00000 && ui << 32 == 0 {
72
+ return 0.;
73
+ }
74
+
75
+ /* reduce x into [sqrt(2)/2, sqrt(2)] */
76
+ hx += 0x3ff00000 - 0x3fe6a09e;
77
+ k += (hx >> 20) as i32 - 0x3ff;
78
+ hx = (hx & 0x000fffff) + 0x3fe6a09e;
79
+ ui = ((hx as u64) << 32) | (ui & 0xffffffff);
80
+ x = f64::from_bits(ui);
81
+
82
+ f = x - 1.0;
83
+ hfsq = 0.5 * f * f;
84
+ s = f / (2.0 + f);
85
+ z = s * s;
86
+ w = z * z;
87
+ t1 = w * (LG2 + w * (LG4 + w * LG6));
88
+ t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7)));
89
+ r = t2 + t1;
90
+
91
+ /* See log2.c for details. */
92
+ /* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */
93
+ hi = f - hfsq;
94
+ ui = hi.to_bits();
95
+ ui &= (-1i64 as u64) << 32;
96
+ hi = f64::from_bits(ui);
97
+ lo = f - hi - hfsq + s * (hfsq + r);
98
+
99
+ /* val_hi+val_lo ~ log10(1+f) + k*log10(2) */
100
+ val_hi = hi * IVLN10HI;
101
+ dk = k as f64;
102
+ y = dk * LOG10_2HI;
103
+ val_lo = dk * LOG10_2LO + (lo + hi) * IVLN10LO + lo * IVLN10HI;
104
+
105
+ /*
106
+ * Extra precision in for adding y is not strictly needed
107
+ * since there is no very large cancellation near x = sqrt(2) or
108
+ * x = 1/sqrt(2), but we do it anyway since it costs little on CPUs
109
+ * with some parallelism and it reduces the error for many args.
110
+ */
111
+ w = y + val_hi;
112
+ val_lo += (y - w) + val_hi;
113
+ val_hi = w;
114
+
115
+ val_lo + val_hi
116
+ }
@@ -0,0 +1,90 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.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
+ /*
13
+ * See comments in log10.c.
14
+ */
15
+
16
+ const IVLN10HI: f32 = 4.3432617188e-01; /* 0x3ede6000 */
17
+ const IVLN10LO: f32 = -3.1689971365e-05; /* 0xb804ead9 */
18
+ const LOG10_2HI: f32 = 3.0102920532e-01; /* 0x3e9a2080 */
19
+ const LOG10_2LO: f32 = 7.9034151668e-07; /* 0x355427db */
20
+ /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
21
+ const LG1: f32 = 0.66666662693; /* 0xaaaaaa.0p-24 */
22
+ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
23
+ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
24
+ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
25
+
26
+ /// The base 10 logarithm of `x` (f32).
27
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
28
+ pub fn log10f(mut x: f32) -> f32 {
29
+ let x1p25f = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25
30
+
31
+ let mut ui: u32 = x.to_bits();
32
+ let hfsq: f32;
33
+ let f: f32;
34
+ let s: f32;
35
+ let z: f32;
36
+ let r: f32;
37
+ let w: f32;
38
+ let t1: f32;
39
+ let t2: f32;
40
+ let dk: f32;
41
+ let mut hi: f32;
42
+ let lo: f32;
43
+ let mut ix: u32;
44
+ let mut k: i32;
45
+
46
+ ix = ui;
47
+ k = 0;
48
+ if ix < 0x00800000 || (ix >> 31) > 0 {
49
+ /* x < 2**-126 */
50
+ if ix << 1 == 0 {
51
+ return -1. / (x * x); /* log(+-0)=-inf */
52
+ }
53
+ if (ix >> 31) > 0 {
54
+ return (x - x) / 0.0; /* log(-#) = NaN */
55
+ }
56
+ /* subnormal number, scale up x */
57
+ k -= 25;
58
+ x *= x1p25f;
59
+ ui = x.to_bits();
60
+ ix = ui;
61
+ } else if ix >= 0x7f800000 {
62
+ return x;
63
+ } else if ix == 0x3f800000 {
64
+ return 0.;
65
+ }
66
+
67
+ /* reduce x into [sqrt(2)/2, sqrt(2)] */
68
+ ix += 0x3f800000 - 0x3f3504f3;
69
+ k += (ix >> 23) as i32 - 0x7f;
70
+ ix = (ix & 0x007fffff) + 0x3f3504f3;
71
+ ui = ix;
72
+ x = f32::from_bits(ui);
73
+
74
+ f = x - 1.0;
75
+ s = f / (2.0 + f);
76
+ z = s * s;
77
+ w = z * z;
78
+ t1 = w * (LG2 + w * LG4);
79
+ t2 = z * (LG1 + w * LG3);
80
+ r = t2 + t1;
81
+ hfsq = 0.5 * f * f;
82
+
83
+ hi = f - hfsq;
84
+ ui = hi.to_bits();
85
+ ui &= 0xfffff000;
86
+ hi = f32::from_bits(ui);
87
+ lo = f - hi - hfsq + s * (hfsq + r);
88
+ dk = k as f32;
89
+ dk * LOG10_2LO + (lo + hi) * IVLN10LO + lo * IVLN10HI + hi * IVLN10HI + dk * LOG10_2HI
90
+ }
@@ -0,0 +1,142 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/s_log1p.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
+ /* double log1p(double x)
13
+ * Return the natural logarithm of 1+x.
14
+ *
15
+ * Method :
16
+ * 1. Argument Reduction: find k and f such that
17
+ * 1+x = 2^k * (1+f),
18
+ * where sqrt(2)/2 < 1+f < sqrt(2) .
19
+ *
20
+ * Note. If k=0, then f=x is exact. However, if k!=0, then f
21
+ * may not be representable exactly. In that case, a correction
22
+ * term is need. Let u=1+x rounded. Let c = (1+x)-u, then
23
+ * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u),
24
+ * and add back the correction term c/u.
25
+ * (Note: when x > 2**53, one can simply return log(x))
26
+ *
27
+ * 2. Approximation of log(1+f): See log.c
28
+ *
29
+ * 3. Finally, log1p(x) = k*ln2 + log(1+f) + c/u. See log.c
30
+ *
31
+ * Special cases:
32
+ * log1p(x) is NaN with signal if x < -1 (including -INF) ;
33
+ * log1p(+INF) is +INF; log1p(-1) is -INF with signal;
34
+ * log1p(NaN) is that NaN with no signal.
35
+ *
36
+ * Accuracy:
37
+ * according to an error analysis, the error is always less than
38
+ * 1 ulp (unit in the last place).
39
+ *
40
+ * Constants:
41
+ * The hexadecimal values are the intended ones for the following
42
+ * constants. The decimal values may be used, provided that the
43
+ * compiler will convert from decimal to binary accurately enough
44
+ * to produce the hexadecimal values shown.
45
+ *
46
+ * Note: Assuming log() return accurate answer, the following
47
+ * algorithm can be used to compute log1p(x) to within a few ULP:
48
+ *
49
+ * u = 1+x;
50
+ * if(u==1.0) return x ; else
51
+ * return log(u)*(x/(u-1.0));
52
+ *
53
+ * See HP-15C Advanced Functions Handbook, p.193.
54
+ */
55
+
56
+ const LN2_HI: f64 = 6.93147180369123816490e-01; /* 3fe62e42 fee00000 */
57
+ const LN2_LO: f64 = 1.90821492927058770002e-10; /* 3dea39ef 35793c76 */
58
+ const LG1: f64 = 6.666666666666735130e-01; /* 3FE55555 55555593 */
59
+ const LG2: f64 = 3.999999999940941908e-01; /* 3FD99999 9997FA04 */
60
+ const LG3: f64 = 2.857142874366239149e-01; /* 3FD24924 94229359 */
61
+ const LG4: f64 = 2.222219843214978396e-01; /* 3FCC71C5 1D8E78AF */
62
+ const LG5: f64 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
63
+ const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
64
+ const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
65
+
66
+ /// The natural logarithm of 1+`x` (f64).
67
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
68
+ pub fn log1p(x: f64) -> f64 {
69
+ let mut ui: u64 = x.to_bits();
70
+ let hfsq: f64;
71
+ let mut f: f64 = 0.;
72
+ let mut c: f64 = 0.;
73
+ let s: f64;
74
+ let z: f64;
75
+ let r: f64;
76
+ let w: f64;
77
+ let t1: f64;
78
+ let t2: f64;
79
+ let dk: f64;
80
+ let hx: u32;
81
+ let mut hu: u32;
82
+ let mut k: i32;
83
+
84
+ hx = (ui >> 32) as u32;
85
+ k = 1;
86
+ if hx < 0x3fda827a || (hx >> 31) > 0 {
87
+ /* 1+x < sqrt(2)+ */
88
+ if hx >= 0xbff00000 {
89
+ /* x <= -1.0 */
90
+ if x == -1. {
91
+ return x / 0.0; /* log1p(-1) = -inf */
92
+ }
93
+ return (x - x) / 0.0; /* log1p(x<-1) = NaN */
94
+ }
95
+ if hx << 1 < 0x3ca00000 << 1 {
96
+ /* |x| < 2**-53 */
97
+ /* underflow if subnormal */
98
+ if (hx & 0x7ff00000) == 0 {
99
+ force_eval!(x as f32);
100
+ }
101
+ return x;
102
+ }
103
+ if hx <= 0xbfd2bec4 {
104
+ /* sqrt(2)/2- <= 1+x < sqrt(2)+ */
105
+ k = 0;
106
+ c = 0.;
107
+ f = x;
108
+ }
109
+ } else if hx >= 0x7ff00000 {
110
+ return x;
111
+ }
112
+ if k > 0 {
113
+ ui = (1. + x).to_bits();
114
+ hu = (ui >> 32) as u32;
115
+ hu += 0x3ff00000 - 0x3fe6a09e;
116
+ k = (hu >> 20) as i32 - 0x3ff;
117
+ /* correction term ~ log(1+x)-log(u), avoid underflow in c/u */
118
+ if k < 54 {
119
+ c = if k >= 2 {
120
+ 1. - (f64::from_bits(ui) - x)
121
+ } else {
122
+ x - (f64::from_bits(ui) - 1.)
123
+ };
124
+ c /= f64::from_bits(ui);
125
+ } else {
126
+ c = 0.;
127
+ }
128
+ /* reduce u into [sqrt(2)/2, sqrt(2)] */
129
+ hu = (hu & 0x000fffff) + 0x3fe6a09e;
130
+ ui = ((hu as u64) << 32) | (ui & 0xffffffff);
131
+ f = f64::from_bits(ui) - 1.;
132
+ }
133
+ hfsq = 0.5 * f * f;
134
+ s = f / (2.0 + f);
135
+ z = s * s;
136
+ w = z * z;
137
+ t1 = w * (LG2 + w * (LG4 + w * LG6));
138
+ t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7)));
139
+ r = t2 + t1;
140
+ dk = k as f64;
141
+ s * (hfsq + r) + (dk * LN2_LO + c) - hfsq + f + dk * LN2_HI
142
+ }
@@ -0,0 +1,97 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/s_log1pf.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
+
13
+ const LN2_HI: f32 = 6.9313812256e-01; /* 0x3f317180 */
14
+ const LN2_LO: f32 = 9.0580006145e-06; /* 0x3717f7d1 */
15
+ /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
16
+ const LG1: f32 = 0.66666662693; /* 0xaaaaaa.0p-24 */
17
+ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
18
+ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
19
+ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
20
+
21
+ /// The natural logarithm of 1+`x` (f32).
22
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
23
+ pub fn log1pf(x: f32) -> f32 {
24
+ let mut ui: u32 = x.to_bits();
25
+ let hfsq: f32;
26
+ let mut f: f32 = 0.;
27
+ let mut c: f32 = 0.;
28
+ let s: f32;
29
+ let z: f32;
30
+ let r: f32;
31
+ let w: f32;
32
+ let t1: f32;
33
+ let t2: f32;
34
+ let dk: f32;
35
+ let ix: u32;
36
+ let mut iu: u32;
37
+ let mut k: i32;
38
+
39
+ ix = ui;
40
+ k = 1;
41
+ if ix < 0x3ed413d0 || (ix >> 31) > 0 {
42
+ /* 1+x < sqrt(2)+ */
43
+ if ix >= 0xbf800000 {
44
+ /* x <= -1.0 */
45
+ if x == -1. {
46
+ return x / 0.0; /* log1p(-1)=+inf */
47
+ }
48
+ return (x - x) / 0.0; /* log1p(x<-1)=NaN */
49
+ }
50
+ if ix << 1 < 0x33800000 << 1 {
51
+ /* |x| < 2**-24 */
52
+ /* underflow if subnormal */
53
+ if (ix & 0x7f800000) == 0 {
54
+ force_eval!(x * x);
55
+ }
56
+ return x;
57
+ }
58
+ if ix <= 0xbe95f619 {
59
+ /* sqrt(2)/2- <= 1+x < sqrt(2)+ */
60
+ k = 0;
61
+ c = 0.;
62
+ f = x;
63
+ }
64
+ } else if ix >= 0x7f800000 {
65
+ return x;
66
+ }
67
+ if k > 0 {
68
+ ui = (1. + x).to_bits();
69
+ iu = ui;
70
+ iu += 0x3f800000 - 0x3f3504f3;
71
+ k = (iu >> 23) as i32 - 0x7f;
72
+ /* correction term ~ log(1+x)-log(u), avoid underflow in c/u */
73
+ if k < 25 {
74
+ c = if k >= 2 {
75
+ 1. - (f32::from_bits(ui) - x)
76
+ } else {
77
+ x - (f32::from_bits(ui) - 1.)
78
+ };
79
+ c /= f32::from_bits(ui);
80
+ } else {
81
+ c = 0.;
82
+ }
83
+ /* reduce u into [sqrt(2)/2, sqrt(2)] */
84
+ iu = (iu & 0x007fffff) + 0x3f3504f3;
85
+ ui = iu;
86
+ f = f32::from_bits(ui) - 1.;
87
+ }
88
+ s = f / (2.0 + f);
89
+ z = s * s;
90
+ w = z * z;
91
+ t1 = w * (LG2 + w * LG4);
92
+ t2 = z * (LG1 + w * LG3);
93
+ r = t2 + t1;
94
+ hfsq = 0.5 * f * f;
95
+ dk = k as f32;
96
+ s * (hfsq + r) + (dk * LN2_LO + c) - hfsq + f + dk * LN2_HI
97
+ }
@@ -0,0 +1,105 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_log2.c */
2
+ /*
3
+ * ====================================================
4
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
+ *
6
+ * Developed at SunSoft, 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
+ /*
13
+ * Return the base 2 logarithm of x. See log.c for most comments.
14
+ *
15
+ * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2
16
+ * as in log.c, then combine and scale in extra precision:
17
+ * log2(x) = (f - f*f/2 + r)/log(2) + k
18
+ */
19
+
20
+ const IVLN2HI: f64 = 1.44269504072144627571e+00; /* 0x3ff71547, 0x65200000 */
21
+ const IVLN2LO: f64 = 1.67517131648865118353e-10; /* 0x3de705fc, 0x2eefa200 */
22
+ const LG1: f64 = 6.666666666666735130e-01; /* 3FE55555 55555593 */
23
+ const LG2: f64 = 3.999999999940941908e-01; /* 3FD99999 9997FA04 */
24
+ const LG3: f64 = 2.857142874366239149e-01; /* 3FD24924 94229359 */
25
+ const LG4: f64 = 2.222219843214978396e-01; /* 3FCC71C5 1D8E78AF */
26
+ const LG5: f64 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
27
+ const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
28
+ const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
29
+
30
+ /// The base 2 logarithm of `x` (f64).
31
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
32
+ pub fn log2(mut x: f64) -> f64 {
33
+ let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54
34
+
35
+ let mut ui: u64 = x.to_bits();
36
+ let hfsq: f64;
37
+ let f: f64;
38
+ let s: f64;
39
+ let z: f64;
40
+ let r: f64;
41
+ let mut w: f64;
42
+ let t1: f64;
43
+ let t2: f64;
44
+ let y: f64;
45
+ let mut hi: f64;
46
+ let lo: f64;
47
+ let mut val_hi: f64;
48
+ let mut val_lo: f64;
49
+ let mut hx: u32;
50
+ let mut k: i32;
51
+
52
+ hx = (ui >> 32) as u32;
53
+ k = 0;
54
+ if hx < 0x00100000 || (hx >> 31) > 0 {
55
+ if ui << 1 == 0 {
56
+ return -1. / (x * x); /* log(+-0)=-inf */
57
+ }
58
+ if (hx >> 31) > 0 {
59
+ return (x - x) / 0.0; /* log(-#) = NaN */
60
+ }
61
+ /* subnormal number, scale x up */
62
+ k -= 54;
63
+ x *= x1p54;
64
+ ui = x.to_bits();
65
+ hx = (ui >> 32) as u32;
66
+ } else if hx >= 0x7ff00000 {
67
+ return x;
68
+ } else if hx == 0x3ff00000 && ui << 32 == 0 {
69
+ return 0.;
70
+ }
71
+
72
+ /* reduce x into [sqrt(2)/2, sqrt(2)] */
73
+ hx += 0x3ff00000 - 0x3fe6a09e;
74
+ k += (hx >> 20) as i32 - 0x3ff;
75
+ hx = (hx & 0x000fffff) + 0x3fe6a09e;
76
+ ui = ((hx as u64) << 32) | (ui & 0xffffffff);
77
+ x = f64::from_bits(ui);
78
+
79
+ f = x - 1.0;
80
+ hfsq = 0.5 * f * f;
81
+ s = f / (2.0 + f);
82
+ z = s * s;
83
+ w = z * z;
84
+ t1 = w * (LG2 + w * (LG4 + w * LG6));
85
+ t2 = z * (LG1 + w * (LG3 + w * (LG5 + w * LG7)));
86
+ r = t2 + t1;
87
+
88
+ /* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */
89
+ hi = f - hfsq;
90
+ ui = hi.to_bits();
91
+ ui &= (-1i64 as u64) << 32;
92
+ hi = f64::from_bits(ui);
93
+ lo = f - hi - hfsq + s * (hfsq + r);
94
+
95
+ val_hi = hi * IVLN2HI;
96
+ val_lo = (lo + hi) * IVLN2LO + lo * IVLN2HI;
97
+
98
+ /* spadd(val_hi, val_lo, y), except for not using double_t: */
99
+ y = k.into();
100
+ w = y + val_hi;
101
+ val_lo += (y - w) + val_hi;
102
+ val_hi = w;
103
+
104
+ val_lo + val_hi
105
+ }
@@ -0,0 +1,86 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_log2f.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
+ /*
13
+ * See comments in log2.c.
14
+ */
15
+
16
+ const IVLN2HI: f32 = 1.4428710938e+00; /* 0x3fb8b000 */
17
+ const IVLN2LO: f32 = -1.7605285393e-04; /* 0xb9389ad4 */
18
+ /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
19
+ const LG1: f32 = 0.66666662693; /* 0xaaaaaa.0p-24 */
20
+ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
21
+ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
22
+ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
23
+
24
+ /// The base 2 logarithm of `x` (f32).
25
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
26
+ pub fn log2f(mut x: f32) -> f32 {
27
+ let x1p25f = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25
28
+
29
+ let mut ui: u32 = x.to_bits();
30
+ let hfsq: f32;
31
+ let f: f32;
32
+ let s: f32;
33
+ let z: f32;
34
+ let r: f32;
35
+ let w: f32;
36
+ let t1: f32;
37
+ let t2: f32;
38
+ let mut hi: f32;
39
+ let lo: f32;
40
+ let mut ix: u32;
41
+ let mut k: i32;
42
+
43
+ ix = ui;
44
+ k = 0;
45
+ if ix < 0x00800000 || (ix >> 31) > 0 {
46
+ /* x < 2**-126 */
47
+ if ix << 1 == 0 {
48
+ return -1. / (x * x); /* log(+-0)=-inf */
49
+ }
50
+ if (ix >> 31) > 0 {
51
+ return (x - x) / 0.0; /* log(-#) = NaN */
52
+ }
53
+ /* subnormal number, scale up x */
54
+ k -= 25;
55
+ x *= x1p25f;
56
+ ui = x.to_bits();
57
+ ix = ui;
58
+ } else if ix >= 0x7f800000 {
59
+ return x;
60
+ } else if ix == 0x3f800000 {
61
+ return 0.;
62
+ }
63
+
64
+ /* reduce x into [sqrt(2)/2, sqrt(2)] */
65
+ ix += 0x3f800000 - 0x3f3504f3;
66
+ k += (ix >> 23) as i32 - 0x7f;
67
+ ix = (ix & 0x007fffff) + 0x3f3504f3;
68
+ ui = ix;
69
+ x = f32::from_bits(ui);
70
+
71
+ f = x - 1.0;
72
+ s = f / (2.0 + f);
73
+ z = s * s;
74
+ w = z * z;
75
+ t1 = w * (LG2 + w * LG4);
76
+ t2 = z * (LG1 + w * LG3);
77
+ r = t2 + t1;
78
+ hfsq = 0.5 * f * f;
79
+
80
+ hi = f - hfsq;
81
+ ui = hi.to_bits();
82
+ ui &= 0xfffff000;
83
+ hi = f32::from_bits(ui);
84
+ lo = f - hi - hfsq + s * (hfsq + r);
85
+ (lo + hi) * IVLN2LO + lo * IVLN2HI + hi * IVLN2HI + k as f32
86
+ }
@@ -0,0 +1,66 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_logf.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
+ const LN2_HI: f32 = 6.9313812256e-01; /* 0x3f317180 */
17
+ const LN2_LO: f32 = 9.0580006145e-06; /* 0x3717f7d1 */
18
+ /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
19
+ const LG1: f32 = 0.66666662693; /* 0xaaaaaa.0p-24*/
20
+ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
21
+ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
22
+ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
23
+
24
+ /// The natural logarithm of `x` (f32).
25
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
26
+ pub fn logf(mut x: f32) -> f32 {
27
+ let x1p25 = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25
28
+
29
+ let mut ix = x.to_bits();
30
+ let mut k = 0i32;
31
+
32
+ if (ix < 0x00800000) || ((ix >> 31) != 0) {
33
+ /* x < 2**-126 */
34
+ if ix << 1 == 0 {
35
+ return -1. / (x * x); /* log(+-0)=-inf */
36
+ }
37
+ if (ix >> 31) != 0 {
38
+ return (x - x) / 0.; /* log(-#) = NaN */
39
+ }
40
+ /* subnormal number, scale up x */
41
+ k -= 25;
42
+ x *= x1p25;
43
+ ix = x.to_bits();
44
+ } else if ix >= 0x7f800000 {
45
+ return x;
46
+ } else if ix == 0x3f800000 {
47
+ return 0.;
48
+ }
49
+
50
+ /* reduce x into [sqrt(2)/2, sqrt(2)] */
51
+ ix += 0x3f800000 - 0x3f3504f3;
52
+ k += ((ix >> 23) as i32) - 0x7f;
53
+ ix = (ix & 0x007fffff) + 0x3f3504f3;
54
+ x = f32::from_bits(ix);
55
+
56
+ let f = x - 1.;
57
+ let s = f / (2. + f);
58
+ let z = s * s;
59
+ let w = z * z;
60
+ let t1 = w * (LG2 + w * LG4);
61
+ let t2 = z * (LG1 + w * LG3);
62
+ let r = t2 + t1;
63
+ let hfsq = 0.5 * f * f;
64
+ let dk = k as f32;
65
+ s * (hfsq + r) + dk * LN2_LO - hfsq + f + dk * LN2_HI
66
+ }