@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,115 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_asin.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
+ /* asin(x)
13
+ * Method :
14
+ * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
15
+ * we approximate asin(x) on [0,0.5] by
16
+ * asin(x) = x + x*x^2*R(x^2)
17
+ * where
18
+ * R(x^2) is a rational approximation of (asin(x)-x)/x^3
19
+ * and its remez error is bounded by
20
+ * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
21
+ *
22
+ * For x in [0.5,1]
23
+ * asin(x) = pi/2-2*asin(sqrt((1-x)/2))
24
+ * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
25
+ * then for x>0.98
26
+ * asin(x) = pi/2 - 2*(s+s*z*R(z))
27
+ * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
28
+ * For x<=0.98, let pio4_hi = pio2_hi/2, then
29
+ * f = hi part of s;
30
+ * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z)
31
+ * and
32
+ * asin(x) = pi/2 - 2*(s+s*z*R(z))
33
+ * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
34
+ * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
35
+ *
36
+ * Special cases:
37
+ * if x is NaN, return x itself;
38
+ * if |x|>1, return NaN with invalid signal.
39
+ *
40
+ */
41
+
42
+ use super::{fabs, get_high_word, get_low_word, sqrt, with_set_low_word};
43
+
44
+ const PIO2_HI: f64 = 1.57079632679489655800e+00; /* 0x3FF921FB, 0x54442D18 */
45
+ const PIO2_LO: f64 = 6.12323399573676603587e-17; /* 0x3C91A626, 0x33145C07 */
46
+ /* coefficients for R(x^2) */
47
+ const P_S0: f64 = 1.66666666666666657415e-01; /* 0x3FC55555, 0x55555555 */
48
+ const P_S1: f64 = -3.25565818622400915405e-01; /* 0xBFD4D612, 0x03EB6F7D */
49
+ const P_S2: f64 = 2.01212532134862925881e-01; /* 0x3FC9C155, 0x0E884455 */
50
+ const P_S3: f64 = -4.00555345006794114027e-02; /* 0xBFA48228, 0xB5688F3B */
51
+ const P_S4: f64 = 7.91534994289814532176e-04; /* 0x3F49EFE0, 0x7501B288 */
52
+ const P_S5: f64 = 3.47933107596021167570e-05; /* 0x3F023DE1, 0x0DFDF709 */
53
+ const Q_S1: f64 = -2.40339491173441421878e+00; /* 0xC0033A27, 0x1C8A2D4B */
54
+ const Q_S2: f64 = 2.02094576023350569471e+00; /* 0x40002AE5, 0x9C598AC8 */
55
+ const Q_S3: f64 = -6.88283971605453293030e-01; /* 0xBFE6066C, 0x1B8D0159 */
56
+ const Q_S4: f64 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
57
+
58
+ fn comp_r(z: f64) -> f64 {
59
+ let p = z * (P_S0 + z * (P_S1 + z * (P_S2 + z * (P_S3 + z * (P_S4 + z * P_S5)))));
60
+ let q = 1.0 + z * (Q_S1 + z * (Q_S2 + z * (Q_S3 + z * Q_S4)));
61
+ p / q
62
+ }
63
+
64
+ /// Arcsine (f64)
65
+ ///
66
+ /// Computes the inverse sine (arc sine) of the argument `x`.
67
+ /// Arguments to asin must be in the range -1 to 1.
68
+ /// Returns values in radians, in the range of -pi/2 to pi/2.
69
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
70
+ pub fn asin(mut x: f64) -> f64 {
71
+ let z: f64;
72
+ let r: f64;
73
+ let s: f64;
74
+ let hx: u32;
75
+ let ix: u32;
76
+
77
+ hx = get_high_word(x);
78
+ ix = hx & 0x7fffffff;
79
+ /* |x| >= 1 or nan */
80
+ if ix >= 0x3ff00000 {
81
+ let lx: u32;
82
+ lx = get_low_word(x);
83
+ if ((ix - 0x3ff00000) | lx) == 0 {
84
+ /* asin(1) = +-pi/2 with inexact */
85
+ return x * PIO2_HI + f64::from_bits(0x3870000000000000);
86
+ } else {
87
+ return 0.0 / (x - x);
88
+ }
89
+ }
90
+ /* |x| < 0.5 */
91
+ if ix < 0x3fe00000 {
92
+ /* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */
93
+ if (0x00100000..0x3e500000).contains(&ix) {
94
+ return x;
95
+ } else {
96
+ return x + x * comp_r(x * x);
97
+ }
98
+ }
99
+ /* 1 > |x| >= 0.5 */
100
+ z = (1.0 - fabs(x)) * 0.5;
101
+ s = sqrt(z);
102
+ r = comp_r(z);
103
+ if ix >= 0x3fef3333 {
104
+ /* if |x| > 0.975 */
105
+ x = PIO2_HI - (2. * (s + s * r) - PIO2_LO);
106
+ } else {
107
+ let f: f64;
108
+ let c: f64;
109
+ /* f+c = sqrt(z) */
110
+ f = with_set_low_word(s, 0);
111
+ c = (z - f * f) / (s + f);
112
+ x = 0.5 * PIO2_HI - (2.0 * s * r - (PIO2_LO - 2.0 * c) - (0.5 * PIO2_HI - 2.0 * f));
113
+ }
114
+ if hx >> 31 != 0 { -x } else { x }
115
+ }
@@ -0,0 +1,68 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_asinf.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::sqrt::sqrt;
17
+ use super::support::Float;
18
+
19
+ const PIO2: f64 = 1.570796326794896558e+00;
20
+
21
+ /* coefficients for R(x^2) */
22
+ const P_S0: f32 = 1.6666586697e-01;
23
+ const P_S1: f32 = -4.2743422091e-02;
24
+ const P_S2: f32 = -8.6563630030e-03;
25
+ const Q_S1: f32 = -7.0662963390e-01;
26
+
27
+ fn r(z: f32) -> f32 {
28
+ let p = z * (P_S0 + z * (P_S1 + z * P_S2));
29
+ let q = 1. + z * Q_S1;
30
+ p / q
31
+ }
32
+
33
+ /// Arcsine (f32)
34
+ ///
35
+ /// Computes the inverse sine (arc sine) of the argument `x`.
36
+ /// Arguments to asin must be in the range -1 to 1.
37
+ /// Returns values in radians, in the range of -pi/2 to pi/2.
38
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
39
+ pub fn asinf(mut x: f32) -> f32 {
40
+ let x1p_120 = f64::from_bits(0x3870000000000000); // 0x1p-120 === 2 ^ (-120)
41
+
42
+ let hx = x.to_bits();
43
+ let ix = hx & 0x7fffffff;
44
+
45
+ if ix >= 0x3f800000 {
46
+ /* |x| >= 1 */
47
+ if ix == 0x3f800000 {
48
+ /* |x| == 1 */
49
+ return ((x as f64) * PIO2 + x1p_120) as f32; /* asin(+-1) = +-pi/2 with inexact */
50
+ }
51
+ return 0. / (x - x); /* asin(|x|>1) is NaN */
52
+ }
53
+
54
+ if ix < 0x3f000000 {
55
+ /* |x| < 0.5 */
56
+ /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
57
+ if (0x00800000..0x39800000).contains(&ix) {
58
+ return x;
59
+ }
60
+ return x + x * r(x * x);
61
+ }
62
+
63
+ /* 1 > |x| >= 0.5 */
64
+ let z = (1. - Float::abs(x)) * 0.5;
65
+ let s = sqrt(z as f64);
66
+ x = (PIO2 - 2. * (s + s * (r(z) as f64))) as f32;
67
+ if (hx >> 31) != 0 { -x } else { x }
68
+ }
@@ -0,0 +1,180 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/s_atan.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
+ /* atan(x)
13
+ * Method
14
+ * 1. Reduce x to positive by atan(x) = -atan(-x).
15
+ * 2. According to the integer k=4t+0.25 chopped, t=x, the argument
16
+ * is further reduced to one of the following intervals and the
17
+ * arctangent of t is evaluated by the corresponding formula:
18
+ *
19
+ * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)
20
+ * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )
21
+ * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )
22
+ * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )
23
+ * [39/16,INF] atan(x) = atan(INF) + atan( -1/t )
24
+ *
25
+ * Constants:
26
+ * The hexadecimal values are the intended ones for the following
27
+ * constants. The decimal values may be used, provided that the
28
+ * compiler will convert from decimal to binary accurately enough
29
+ * to produce the hexadecimal values shown.
30
+ */
31
+
32
+ use super::fabs;
33
+
34
+ const ATANHI: [f64; 4] = [
35
+ 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */
36
+ 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */
37
+ 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */
38
+ 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */
39
+ ];
40
+
41
+ const ATANLO: [f64; 4] = [
42
+ 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */
43
+ 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */
44
+ 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */
45
+ 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */
46
+ ];
47
+
48
+ const AT: [f64; 11] = [
49
+ 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */
50
+ -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */
51
+ 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */
52
+ -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */
53
+ 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */
54
+ -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */
55
+ 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */
56
+ -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */
57
+ 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */
58
+ -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */
59
+ 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */
60
+ ];
61
+
62
+ /// Arctangent (f64)
63
+ ///
64
+ /// Computes the inverse tangent (arc tangent) of the input value.
65
+ /// Returns a value in radians, in the range of -pi/2 to pi/2.
66
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
67
+ pub fn atan(x: f64) -> f64 {
68
+ let mut x = x;
69
+ let mut ix = (x.to_bits() >> 32) as u32;
70
+ let sign = ix >> 31;
71
+ ix &= 0x7fff_ffff;
72
+ if ix >= 0x4410_0000 {
73
+ if x.is_nan() {
74
+ return x;
75
+ }
76
+
77
+ let z = ATANHI[3] + f64::from_bits(0x0380_0000); // 0x1p-120f
78
+ return if sign != 0 { -z } else { z };
79
+ }
80
+
81
+ let id = if ix < 0x3fdc_0000 {
82
+ /* |x| < 0.4375 */
83
+ if ix < 0x3e40_0000 {
84
+ /* |x| < 2^-27 */
85
+ if ix < 0x0010_0000 {
86
+ /* raise underflow for subnormal x */
87
+ force_eval!(x as f32);
88
+ }
89
+
90
+ return x;
91
+ }
92
+
93
+ -1
94
+ } else {
95
+ x = fabs(x);
96
+ if ix < 0x3ff30000 {
97
+ /* |x| < 1.1875 */
98
+ if ix < 0x3fe60000 {
99
+ /* 7/16 <= |x| < 11/16 */
100
+ x = (2. * x - 1.) / (2. + x);
101
+ 0
102
+ } else {
103
+ /* 11/16 <= |x| < 19/16 */
104
+ x = (x - 1.) / (x + 1.);
105
+ 1
106
+ }
107
+ } else if ix < 0x40038000 {
108
+ /* |x| < 2.4375 */
109
+ x = (x - 1.5) / (1. + 1.5 * x);
110
+ 2
111
+ } else {
112
+ /* 2.4375 <= |x| < 2^66 */
113
+ x = -1. / x;
114
+ 3
115
+ }
116
+ };
117
+
118
+ let z = x * x;
119
+ let w = z * z;
120
+ /* break sum from i=0 to 10 AT[i]z**(i+1) into odd and even poly */
121
+ let s1 = z * (AT[0] + w * (AT[2] + w * (AT[4] + w * (AT[6] + w * (AT[8] + w * AT[10])))));
122
+ let s2 = w * (AT[1] + w * (AT[3] + w * (AT[5] + w * (AT[7] + w * AT[9]))));
123
+
124
+ if id < 0 {
125
+ return x - x * (s1 + s2);
126
+ }
127
+
128
+ let z = i!(ATANHI, id as usize) - (x * (s1 + s2) - i!(ATANLO, id as usize) - x);
129
+
130
+ if sign != 0 { -z } else { z }
131
+ }
132
+
133
+ #[cfg(test)]
134
+ mod tests {
135
+ use core::f64::consts;
136
+
137
+ use super::atan;
138
+
139
+ #[test]
140
+ fn sanity_check() {
141
+ for (input, answer) in [
142
+ (3.0_f64.sqrt() / 3.0, consts::FRAC_PI_6),
143
+ (1.0, consts::FRAC_PI_4),
144
+ (3.0_f64.sqrt(), consts::FRAC_PI_3),
145
+ (-3.0_f64.sqrt() / 3.0, -consts::FRAC_PI_6),
146
+ (-1.0, -consts::FRAC_PI_4),
147
+ (-3.0_f64.sqrt(), -consts::FRAC_PI_3),
148
+ ]
149
+ .iter()
150
+ {
151
+ assert!(
152
+ (atan(*input) - answer) / answer < 1e-5,
153
+ "\natan({:.4}/16) = {:.4}, actual: {}",
154
+ input * 16.0,
155
+ answer,
156
+ atan(*input)
157
+ );
158
+ }
159
+ }
160
+
161
+ #[test]
162
+ fn zero() {
163
+ assert_eq!(atan(0.0), 0.0);
164
+ }
165
+
166
+ #[test]
167
+ fn infinity() {
168
+ assert_eq!(atan(f64::INFINITY), consts::FRAC_PI_2);
169
+ }
170
+
171
+ #[test]
172
+ fn minus_infinity() {
173
+ assert_eq!(atan(f64::NEG_INFINITY), -consts::FRAC_PI_2);
174
+ }
175
+
176
+ #[test]
177
+ fn nan() {
178
+ assert!(atan(f64::NAN).is_nan());
179
+ }
180
+ }
@@ -0,0 +1,131 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_atan2.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
+ /* atan2(y,x)
14
+ * Method :
15
+ * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
16
+ * 2. Reduce x to positive by (if x and y are unexceptional):
17
+ * ARG (x+iy) = arctan(y/x) ... if x > 0,
18
+ * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
19
+ *
20
+ * Special cases:
21
+ *
22
+ * ATAN2((anything), NaN ) is NaN;
23
+ * ATAN2(NAN , (anything) ) is NaN;
24
+ * ATAN2(+-0, +(anything but NaN)) is +-0 ;
25
+ * ATAN2(+-0, -(anything but NaN)) is +-pi ;
26
+ * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
27
+ * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
28
+ * ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
29
+ * ATAN2(+-INF,+INF ) is +-pi/4 ;
30
+ * ATAN2(+-INF,-INF ) is +-3pi/4;
31
+ * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
32
+ *
33
+ * Constants:
34
+ * The hexadecimal values are the intended ones for the following
35
+ * constants. The decimal values may be used, provided that the
36
+ * compiler will convert from decimal to binary accurately enough
37
+ * to produce the hexadecimal values shown.
38
+ */
39
+
40
+ use super::{atan, fabs};
41
+
42
+ const PI: f64 = 3.1415926535897931160E+00; /* 0x400921FB, 0x54442D18 */
43
+ const PI_LO: f64 = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
44
+
45
+ /// Arctangent of y/x (f64)
46
+ ///
47
+ /// Computes the inverse tangent (arc tangent) of `y/x`.
48
+ /// Produces the correct result even for angles near pi/2 or -pi/2 (that is, when `x` is near 0).
49
+ /// Returns a value in radians, in the range of -pi to pi.
50
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
51
+ pub fn atan2(y: f64, x: f64) -> f64 {
52
+ if x.is_nan() || y.is_nan() {
53
+ return x + y;
54
+ }
55
+ let mut ix = (x.to_bits() >> 32) as u32;
56
+ let lx = x.to_bits() as u32;
57
+ let mut iy = (y.to_bits() >> 32) as u32;
58
+ let ly = y.to_bits() as u32;
59
+ if ((ix.wrapping_sub(0x3ff00000)) | lx) == 0 {
60
+ /* x = 1.0 */
61
+ return atan(y);
62
+ }
63
+ let m = ((iy >> 31) & 1) | ((ix >> 30) & 2); /* 2*sign(x)+sign(y) */
64
+ ix &= 0x7fffffff;
65
+ iy &= 0x7fffffff;
66
+
67
+ /* when y = 0 */
68
+ if (iy | ly) == 0 {
69
+ return match m {
70
+ 0 | 1 => y, /* atan(+-0,+anything)=+-0 */
71
+ 2 => PI, /* atan(+0,-anything) = PI */
72
+ _ => -PI, /* atan(-0,-anything) =-PI */
73
+ };
74
+ }
75
+ /* when x = 0 */
76
+ if (ix | lx) == 0 {
77
+ return if m & 1 != 0 { -PI / 2.0 } else { PI / 2.0 };
78
+ }
79
+ /* when x is INF */
80
+ if ix == 0x7ff00000 {
81
+ if iy == 0x7ff00000 {
82
+ return match m {
83
+ 0 => PI / 4.0, /* atan(+INF,+INF) */
84
+ 1 => -PI / 4.0, /* atan(-INF,+INF) */
85
+ 2 => 3.0 * PI / 4.0, /* atan(+INF,-INF) */
86
+ _ => -3.0 * PI / 4.0, /* atan(-INF,-INF) */
87
+ };
88
+ } else {
89
+ return match m {
90
+ 0 => 0.0, /* atan(+...,+INF) */
91
+ 1 => -0.0, /* atan(-...,+INF) */
92
+ 2 => PI, /* atan(+...,-INF) */
93
+ _ => -PI, /* atan(-...,-INF) */
94
+ };
95
+ }
96
+ }
97
+ /* |y/x| > 0x1p64 */
98
+ if ix.wrapping_add(64 << 20) < iy || iy == 0x7ff00000 {
99
+ return if m & 1 != 0 { -PI / 2.0 } else { PI / 2.0 };
100
+ }
101
+
102
+ /* z = atan(|y/x|) without spurious underflow */
103
+ let z = if (m & 2 != 0) && iy.wrapping_add(64 << 20) < ix {
104
+ /* |y/x| < 0x1p-64, x<0 */
105
+ 0.0
106
+ } else {
107
+ atan(fabs(y / x))
108
+ };
109
+ match m {
110
+ 0 => z, /* atan(+,+) */
111
+ 1 => -z, /* atan(-,+) */
112
+ 2 => PI - (z - PI_LO), /* atan(+,-) */
113
+ _ => (z - PI_LO) - PI, /* atan(-,-) */
114
+ }
115
+ }
116
+
117
+ #[cfg(test)]
118
+ mod tests {
119
+ use super::*;
120
+
121
+ #[test]
122
+ #[cfg_attr(x86_no_sse, ignore = "FIXME(i586): possible incorrect rounding")]
123
+ fn sanity_check() {
124
+ assert_eq!(atan2(0.0, 1.0), 0.0);
125
+ assert_eq!(atan2(0.0, -1.0), PI);
126
+ assert_eq!(atan2(-0.0, -1.0), -PI);
127
+ assert_eq!(atan2(3.0, 2.0), atan(3.0 / 2.0));
128
+ assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);
129
+ assert_eq!(atan2(-2.0, -1.0), atan(-2.0 / -1.0) - PI);
130
+ }
131
+ }
@@ -0,0 +1,90 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/e_atan2f.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::{atanf, fabsf};
17
+
18
+ const PI: f32 = 3.1415927410e+00; /* 0x40490fdb */
19
+ const PI_LO: f32 = -8.7422776573e-08; /* 0xb3bbbd2e */
20
+
21
+ /// Arctangent of y/x (f32)
22
+ ///
23
+ /// Computes the inverse tangent (arc tangent) of `y/x`.
24
+ /// Produces the correct result even for angles near pi/2 or -pi/2 (that is, when `x` is near 0).
25
+ /// Returns a value in radians, in the range of -pi to pi.
26
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
27
+ pub fn atan2f(y: f32, x: f32) -> f32 {
28
+ if x.is_nan() || y.is_nan() {
29
+ return x + y;
30
+ }
31
+ let mut ix = x.to_bits();
32
+ let mut iy = y.to_bits();
33
+
34
+ if ix == 0x3f800000 {
35
+ /* x=1.0 */
36
+ return atanf(y);
37
+ }
38
+ let m = ((iy >> 31) & 1) | ((ix >> 30) & 2); /* 2*sign(x)+sign(y) */
39
+ ix &= 0x7fffffff;
40
+ iy &= 0x7fffffff;
41
+
42
+ /* when y = 0 */
43
+ if iy == 0 {
44
+ return match m {
45
+ 0 | 1 => y, /* atan(+-0,+anything)=+-0 */
46
+ 2 => PI, /* atan(+0,-anything) = pi */
47
+ _ => -PI, /* atan(-0,-anything) =-pi */
48
+ };
49
+ }
50
+ /* when x = 0 */
51
+ if ix == 0 {
52
+ return if m & 1 != 0 { -PI / 2. } else { PI / 2. };
53
+ }
54
+ /* when x is INF */
55
+ if ix == 0x7f800000 {
56
+ return if iy == 0x7f800000 {
57
+ match m {
58
+ 0 => PI / 4., /* atan(+INF,+INF) */
59
+ 1 => -PI / 4., /* atan(-INF,+INF) */
60
+ 2 => 3. * PI / 4., /* atan(+INF,-INF)*/
61
+ _ => -3. * PI / 4., /* atan(-INF,-INF)*/
62
+ }
63
+ } else {
64
+ match m {
65
+ 0 => 0., /* atan(+...,+INF) */
66
+ 1 => -0., /* atan(-...,+INF) */
67
+ 2 => PI, /* atan(+...,-INF) */
68
+ _ => -PI, /* atan(-...,-INF) */
69
+ }
70
+ };
71
+ }
72
+ /* |y/x| > 0x1p26 */
73
+ if (ix + (26 << 23) < iy) || (iy == 0x7f800000) {
74
+ return if m & 1 != 0 { -PI / 2. } else { PI / 2. };
75
+ }
76
+
77
+ /* z = atan(|y/x|) with correct underflow */
78
+ let z = if (m & 2 != 0) && (iy + (26 << 23) < ix) {
79
+ /*|y/x| < 0x1p-26, x < 0 */
80
+ 0.
81
+ } else {
82
+ atanf(fabsf(y / x))
83
+ };
84
+ match m {
85
+ 0 => z, /* atan(+,+) */
86
+ 1 => -z, /* atan(-,+) */
87
+ 2 => PI - (z - PI_LO), /* atan(+,-) */
88
+ _ => (z - PI_LO) - PI, /* case 3 */ /* atan(-,-) */
89
+ }
90
+ }
@@ -0,0 +1,108 @@
1
+ /* origin: FreeBSD /usr/src/lib/msun/src/s_atanf.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::fabsf;
17
+
18
+ const ATAN_HI: [f32; 4] = [
19
+ 4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */
20
+ 7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */
21
+ 9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */
22
+ 1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */
23
+ ];
24
+
25
+ const ATAN_LO: [f32; 4] = [
26
+ 5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */
27
+ 3.7748947079e-08, /* atan(1.0)lo 0x33222168 */
28
+ 3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */
29
+ 7.5497894159e-08, /* atan(inf)lo 0x33a22168 */
30
+ ];
31
+
32
+ const A_T: [f32; 5] = [
33
+ 3.3333328366e-01,
34
+ -1.9999158382e-01,
35
+ 1.4253635705e-01,
36
+ -1.0648017377e-01,
37
+ 6.1687607318e-02,
38
+ ];
39
+
40
+ /// Arctangent (f32)
41
+ ///
42
+ /// Computes the inverse tangent (arc tangent) of the input value.
43
+ /// Returns a value in radians, in the range of -pi/2 to pi/2.
44
+ #[cfg_attr(assert_no_panic, no_panic::no_panic)]
45
+ pub fn atanf(mut x: f32) -> f32 {
46
+ let x1p_120 = f32::from_bits(0x03800000); // 0x1p-120 === 2 ^ (-120)
47
+
48
+ let z: f32;
49
+
50
+ let mut ix = x.to_bits();
51
+ let sign = (ix >> 31) != 0;
52
+ ix &= 0x7fffffff;
53
+
54
+ if ix >= 0x4c800000 {
55
+ /* if |x| >= 2**26 */
56
+ if x.is_nan() {
57
+ return x;
58
+ }
59
+ z = i!(ATAN_HI, 3) + x1p_120;
60
+ return if sign { -z } else { z };
61
+ }
62
+ let id = if ix < 0x3ee00000 {
63
+ /* |x| < 0.4375 */
64
+ if ix < 0x39800000 {
65
+ /* |x| < 2**-12 */
66
+ if ix < 0x00800000 {
67
+ /* raise underflow for subnormal x */
68
+ force_eval!(x * x);
69
+ }
70
+ return x;
71
+ }
72
+ -1
73
+ } else {
74
+ x = fabsf(x);
75
+ if ix < 0x3f980000 {
76
+ /* |x| < 1.1875 */
77
+ if ix < 0x3f300000 {
78
+ /* 7/16 <= |x| < 11/16 */
79
+ x = (2. * x - 1.) / (2. + x);
80
+ 0
81
+ } else {
82
+ /* 11/16 <= |x| < 19/16 */
83
+ x = (x - 1.) / (x + 1.);
84
+ 1
85
+ }
86
+ } else if ix < 0x401c0000 {
87
+ /* |x| < 2.4375 */
88
+ x = (x - 1.5) / (1. + 1.5 * x);
89
+ 2
90
+ } else {
91
+ /* 2.4375 <= |x| < 2**26 */
92
+ x = -1. / x;
93
+ 3
94
+ }
95
+ };
96
+ /* end of argument reduction */
97
+ z = x * x;
98
+ let w = z * z;
99
+ /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
100
+ let s1 = z * (i!(A_T, 0) + w * (i!(A_T, 2) + w * i!(A_T, 4)));
101
+ let s2 = w * (i!(A_T, 1) + w * i!(A_T, 3));
102
+ if id < 0 {
103
+ return x - x * (s1 + s2);
104
+ }
105
+ let id = id as usize;
106
+ let z = i!(ATAN_HI, id) - ((x * (s1 + s2) - i!(ATAN_LO, id)) - x);
107
+ if sign { -z } else { z }
108
+ }