@delali/narsil-react-native 0.3.1-next.155 → 0.3.1-next.157

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 (253) hide show
  1. package/NOTICE +144 -0
  2. package/NarsilReactNative.podspec +2 -2
  3. package/android/CMakeLists.txt +1 -1
  4. package/cpp/HybridNarsilCoreAnalysis.cpp +277 -0
  5. package/cpp/HybridNarsilCoreImpl.hpp +43 -0
  6. package/cpp/HybridNarsilCoreKeyword.cpp +253 -0
  7. package/cpp/HybridNarsilCoreMath.cpp +47 -0
  8. package/cpp/core/include/narsil_analysis.h +86 -0
  9. package/cpp/core/include/narsil_core.h +1 -1
  10. package/cpp/core/include/narsil_keyword.h +110 -0
  11. package/cpp/core/include/narsil_math.h +36 -0
  12. package/cpp/core/src/analysis/analyse.c +281 -0
  13. package/cpp/core/src/analysis/analyser.h +49 -0
  14. package/cpp/core/src/analysis/languages.c +79 -0
  15. package/cpp/core/src/analysis/languages.h +42 -0
  16. package/cpp/core/src/analysis/normalise.c +242 -0
  17. package/cpp/core/src/analysis/normalise.h +28 -0
  18. package/cpp/core/src/analysis/split.c +183 -0
  19. package/cpp/core/src/analysis/split.h +27 -0
  20. package/cpp/core/src/analysis/stop_words.c +82 -0
  21. package/cpp/core/src/analysis/stop_words.h +19 -0
  22. package/cpp/core/src/analysis/term_cache.c +88 -0
  23. package/cpp/core/src/analysis/term_cache.h +36 -0
  24. package/cpp/core/src/analysis/text.c +161 -0
  25. package/cpp/core/src/analysis/text.h +45 -0
  26. package/cpp/core/src/analysis/transform.c +103 -0
  27. package/cpp/core/src/analysis/unicode.c +252 -0
  28. package/cpp/core/src/analysis/unicode.h +54 -0
  29. package/cpp/core/src/internal.h +4 -0
  30. package/cpp/core/src/keyword/pass.h +117 -0
  31. package/cpp/core/src/keyword/prune.c +324 -0
  32. package/cpp/core/src/keyword/request.c +179 -0
  33. package/cpp/core/src/keyword/rows.c +83 -0
  34. package/cpp/core/src/keyword/rows.h +18 -0
  35. package/cpp/core/src/keyword/score.c +257 -0
  36. package/cpp/core/src/keyword/score.h +17 -0
  37. package/cpp/core/src/keyword/scratch.c +226 -0
  38. package/cpp/core/src/keyword/scratch.h +55 -0
  39. package/cpp/core/src/keyword/select.c +155 -0
  40. package/cpp/core/src/keyword/select.h +17 -0
  41. package/cpp/core/src/languages/bulgarian_stemmer.c +114 -0
  42. package/cpp/core/src/languages/data/albanian.c +54 -0
  43. package/cpp/core/src/languages/data/amharic.c +93 -0
  44. package/cpp/core/src/languages/data/arabic.c +146 -0
  45. package/cpp/core/src/languages/data/armenian.c +46 -0
  46. package/cpp/core/src/languages/data/azerbaijani.c +68 -0
  47. package/cpp/core/src/languages/data/bambara.c +48 -0
  48. package/cpp/core/src/languages/data/basque.c +62 -0
  49. package/cpp/core/src/languages/data/belarusian.c +56 -0
  50. package/cpp/core/src/languages/data/bengali.c +63 -0
  51. package/cpp/core/src/languages/data/bosnian.c +73 -0
  52. package/cpp/core/src/languages/data/breton.c +52 -0
  53. package/cpp/core/src/languages/data/bulgarian.c +144 -0
  54. package/cpp/core/src/languages/data/burmese.c +48 -0
  55. package/cpp/core/src/languages/data/catalan.c +84 -0
  56. package/cpp/core/src/languages/data/chinese.c +70 -0
  57. package/cpp/core/src/languages/data/croatian.c +72 -0
  58. package/cpp/core/src/languages/data/czech.c +72 -0
  59. package/cpp/core/src/languages/data/dagbani.c +88 -0
  60. package/cpp/core/src/languages/data/danish.c +56 -0
  61. package/cpp/core/src/languages/data/declarations.h +114 -0
  62. package/cpp/core/src/languages/data/dutch.c +58 -0
  63. package/cpp/core/src/languages/data/english.c +172 -0
  64. package/cpp/core/src/languages/data/esperanto.c +71 -0
  65. package/cpp/core/src/languages/data/estonian.c +417 -0
  66. package/cpp/core/src/languages/data/ewe.c +89 -0
  67. package/cpp/core/src/languages/data/faroese.c +54 -0
  68. package/cpp/core/src/languages/data/fijian.c +44 -0
  69. package/cpp/core/src/languages/data/finnish.c +100 -0
  70. package/cpp/core/src/languages/data/french.c +74 -0
  71. package/cpp/core/src/languages/data/ga.c +83 -0
  72. package/cpp/core/src/languages/data/galician.c +70 -0
  73. package/cpp/core/src/languages/data/georgian.c +57 -0
  74. package/cpp/core/src/languages/data/german.c +96 -0
  75. package/cpp/core/src/languages/data/greek.c +202 -0
  76. package/cpp/core/src/languages/data/guarani.c +110 -0
  77. package/cpp/core/src/languages/data/gujarati.c +90 -0
  78. package/cpp/core/src/languages/data/haitian-creole.c +54 -0
  79. package/cpp/core/src/languages/data/hausa.c +85 -0
  80. package/cpp/core/src/languages/data/hawaiian.c +50 -0
  81. package/cpp/core/src/languages/data/hebrew.c +85 -0
  82. package/cpp/core/src/languages/data/hindi.c +91 -0
  83. package/cpp/core/src/languages/data/hungarian.c +98 -0
  84. package/cpp/core/src/languages/data/icelandic.c +73 -0
  85. package/cpp/core/src/languages/data/igbo.c +90 -0
  86. package/cpp/core/src/languages/data/indonesian.c +296 -0
  87. package/cpp/core/src/languages/data/irish.c +60 -0
  88. package/cpp/core/src/languages/data/italian.c +107 -0
  89. package/cpp/core/src/languages/data/japanese.c +52 -0
  90. package/cpp/core/src/languages/data/kannada.c +60 -0
  91. package/cpp/core/src/languages/data/kazakh.c +57 -0
  92. package/cpp/core/src/languages/data/khmer.c +71 -0
  93. package/cpp/core/src/languages/data/kinyarwanda.c +54 -0
  94. package/cpp/core/src/languages/data/kirundi.c +53 -0
  95. package/cpp/core/src/languages/data/korean.c +74 -0
  96. package/cpp/core/src/languages/data/kurmanji.c +43 -0
  97. package/cpp/core/src/languages/data/kyrgyz.c +65 -0
  98. package/cpp/core/src/languages/data/lao.c +46 -0
  99. package/cpp/core/src/languages/data/latin.c +46 -0
  100. package/cpp/core/src/languages/data/latvian.c +75 -0
  101. package/cpp/core/src/languages/data/lingala.c +88 -0
  102. package/cpp/core/src/languages/data/lithuanian.c +65 -0
  103. package/cpp/core/src/languages/data/luxembourgish.c +80 -0
  104. package/cpp/core/src/languages/data/macedonian.c +286 -0
  105. package/cpp/core/src/languages/data/malagasy.c +51 -0
  106. package/cpp/core/src/languages/data/malay.c +184 -0
  107. package/cpp/core/src/languages/data/malayalam.c +64 -0
  108. package/cpp/core/src/languages/data/maltese.c +102 -0
  109. package/cpp/core/src/languages/data/maori.c +52 -0
  110. package/cpp/core/src/languages/data/marathi.c +62 -0
  111. package/cpp/core/src/languages/data/nepali.c +72 -0
  112. package/cpp/core/src/languages/data/norwegian.c +74 -0
  113. package/cpp/core/src/languages/data/oromo.c +51 -0
  114. package/cpp/core/src/languages/data/persian.c +150 -0
  115. package/cpp/core/src/languages/data/polish.c +111 -0
  116. package/cpp/core/src/languages/data/portuguese.c +91 -0
  117. package/cpp/core/src/languages/data/punjabi.c +80 -0
  118. package/cpp/core/src/languages/data/registry.c +116 -0
  119. package/cpp/core/src/languages/data/romanian.c +93 -0
  120. package/cpp/core/src/languages/data/russian.c +76 -0
  121. package/cpp/core/src/languages/data/samoan.c +47 -0
  122. package/cpp/core/src/languages/data/sanskrit.c +53 -0
  123. package/cpp/core/src/languages/data/scottish-gaelic.c +119 -0
  124. package/cpp/core/src/languages/data/serbian.c +84 -0
  125. package/cpp/core/src/languages/data/shona.c +55 -0
  126. package/cpp/core/src/languages/data/sinhala.c +78 -0
  127. package/cpp/core/src/languages/data/slovak.c +135 -0
  128. package/cpp/core/src/languages/data/slovenian.c +139 -0
  129. package/cpp/core/src/languages/data/sorani.c +55 -0
  130. package/cpp/core/src/languages/data/spanish.c +84 -0
  131. package/cpp/core/src/languages/data/swahili.c +59 -0
  132. package/cpp/core/src/languages/data/swedish.c +60 -0
  133. package/cpp/core/src/languages/data/tagalog.c +75 -0
  134. package/cpp/core/src/languages/data/tamil.c +69 -0
  135. package/cpp/core/src/languages/data/tatar.c +548 -0
  136. package/cpp/core/src/languages/data/telugu.c +54 -0
  137. package/cpp/core/src/languages/data/thai.c +46 -0
  138. package/cpp/core/src/languages/data/tibetan.c +55 -0
  139. package/cpp/core/src/languages/data/tigrinya.c +73 -0
  140. package/cpp/core/src/languages/data/tongan.c +47 -0
  141. package/cpp/core/src/languages/data/turkish.c +100 -0
  142. package/cpp/core/src/languages/data/twi.c +88 -0
  143. package/cpp/core/src/languages/data/ukrainian.c +99 -0
  144. package/cpp/core/src/languages/data/urdu.c +174 -0
  145. package/cpp/core/src/languages/data/vietnamese.c +88 -0
  146. package/cpp/core/src/languages/data/welsh.c +143 -0
  147. package/cpp/core/src/languages/data/wolof.c +51 -0
  148. package/cpp/core/src/languages/data/xhosa.c +56 -0
  149. package/cpp/core/src/languages/data/yoruba.c +93 -0
  150. package/cpp/core/src/languages/data/zulu.c +58 -0
  151. package/cpp/core/src/languages/marks.c +64 -0
  152. package/cpp/core/src/languages/rules.c +63 -0
  153. package/cpp/core/src/languages/rules.h +68 -0
  154. package/cpp/core/src/languages/sanskrit_stemmer.c +50 -0
  155. package/cpp/core/src/languages/scripts.c +143 -0
  156. package/cpp/core/src/languages/slovenian_stemmer.c +46 -0
  157. package/cpp/core/src/languages/snowball/api.c +52 -0
  158. package/cpp/core/src/languages/snowball/api.h +43 -0
  159. package/cpp/core/src/languages/snowball/arabic_stemmer.c +1506 -0
  160. package/cpp/core/src/languages/snowball/arabic_stemmer.h +24 -0
  161. package/cpp/core/src/languages/snowball/armenian_stemmer.c +523 -0
  162. package/cpp/core/src/languages/snowball/armenian_stemmer.h +24 -0
  163. package/cpp/core/src/languages/snowball/basque_stemmer.c +1089 -0
  164. package/cpp/core/src/languages/snowball/basque_stemmer.h +24 -0
  165. package/cpp/core/src/languages/snowball/catalan_stemmer.c +1380 -0
  166. package/cpp/core/src/languages/snowball/catalan_stemmer.h +24 -0
  167. package/cpp/core/src/languages/snowball/czech_stemmer.c +582 -0
  168. package/cpp/core/src/languages/snowball/czech_stemmer.h +24 -0
  169. package/cpp/core/src/languages/snowball/danish_stemmer.c +352 -0
  170. package/cpp/core/src/languages/snowball/danish_stemmer.h +24 -0
  171. package/cpp/core/src/languages/snowball/dutch_stemmer.c +1657 -0
  172. package/cpp/core/src/languages/snowball/dutch_stemmer.h +24 -0
  173. package/cpp/core/src/languages/snowball/english_stemmer.c +1019 -0
  174. package/cpp/core/src/languages/snowball/english_stemmer.h +24 -0
  175. package/cpp/core/src/languages/snowball/esperanto_stemmer.c +716 -0
  176. package/cpp/core/src/languages/snowball/esperanto_stemmer.h +24 -0
  177. package/cpp/core/src/languages/snowball/estonian_stemmer.c +1361 -0
  178. package/cpp/core/src/languages/snowball/estonian_stemmer.h +24 -0
  179. package/cpp/core/src/languages/snowball/finnish_stemmer.c +800 -0
  180. package/cpp/core/src/languages/snowball/finnish_stemmer.h +24 -0
  181. package/cpp/core/src/languages/snowball/french_stemmer.c +1217 -0
  182. package/cpp/core/src/languages/snowball/french_stemmer.h +24 -0
  183. package/cpp/core/src/languages/snowball/german_stemmer.c +567 -0
  184. package/cpp/core/src/languages/snowball/german_stemmer.h +24 -0
  185. package/cpp/core/src/languages/snowball/greek_stemmer.c +3450 -0
  186. package/cpp/core/src/languages/snowball/greek_stemmer.h +24 -0
  187. package/cpp/core/src/languages/snowball/hindi_stemmer.c +325 -0
  188. package/cpp/core/src/languages/snowball/hindi_stemmer.h +24 -0
  189. package/cpp/core/src/languages/snowball/hungarian_stemmer.c +742 -0
  190. package/cpp/core/src/languages/snowball/hungarian_stemmer.h +24 -0
  191. package/cpp/core/src/languages/snowball/indonesian_stemmer.c +443 -0
  192. package/cpp/core/src/languages/snowball/indonesian_stemmer.h +24 -0
  193. package/cpp/core/src/languages/snowball/irish_stemmer.c +428 -0
  194. package/cpp/core/src/languages/snowball/irish_stemmer.h +24 -0
  195. package/cpp/core/src/languages/snowball/italian_stemmer.c +983 -0
  196. package/cpp/core/src/languages/snowball/italian_stemmer.h +24 -0
  197. package/cpp/core/src/languages/snowball/lithuanian_stemmer.c +794 -0
  198. package/cpp/core/src/languages/snowball/lithuanian_stemmer.h +24 -0
  199. package/cpp/core/src/languages/snowball/nepali_stemmer.c +361 -0
  200. package/cpp/core/src/languages/snowball/nepali_stemmer.h +24 -0
  201. package/cpp/core/src/languages/snowball/norwegian_stemmer.c +332 -0
  202. package/cpp/core/src/languages/snowball/norwegian_stemmer.h +24 -0
  203. package/cpp/core/src/languages/snowball/persian_stemmer.c +538 -0
  204. package/cpp/core/src/languages/snowball/persian_stemmer.h +24 -0
  205. package/cpp/core/src/languages/snowball/polish_stemmer.c +501 -0
  206. package/cpp/core/src/languages/snowball/polish_stemmer.h +24 -0
  207. package/cpp/core/src/languages/snowball/portuguese_stemmer.c +866 -0
  208. package/cpp/core/src/languages/snowball/portuguese_stemmer.h +24 -0
  209. package/cpp/core/src/languages/snowball/romanian_stemmer.c +940 -0
  210. package/cpp/core/src/languages/snowball/romanian_stemmer.h +24 -0
  211. package/cpp/core/src/languages/snowball/russian_stemmer.c +598 -0
  212. package/cpp/core/src/languages/snowball/russian_stemmer.h +24 -0
  213. package/cpp/core/src/languages/snowball/serbian_stemmer.c +6765 -0
  214. package/cpp/core/src/languages/snowball/serbian_stemmer.h +24 -0
  215. package/cpp/core/src/languages/snowball/snowball_runtime.h +122 -0
  216. package/cpp/core/src/languages/snowball/spanish_stemmer.c +955 -0
  217. package/cpp/core/src/languages/snowball/spanish_stemmer.h +24 -0
  218. package/cpp/core/src/languages/snowball/swedish_stemmer.c +364 -0
  219. package/cpp/core/src/languages/snowball/swedish_stemmer.h +24 -0
  220. package/cpp/core/src/languages/snowball/tamil_stemmer.c +1305 -0
  221. package/cpp/core/src/languages/snowball/tamil_stemmer.h +24 -0
  222. package/cpp/core/src/languages/snowball/turkish_stemmer.c +1700 -0
  223. package/cpp/core/src/languages/snowball/turkish_stemmer.h +24 -0
  224. package/cpp/core/src/languages/snowball/utilities.c +716 -0
  225. package/cpp/core/src/languages/substitutions.c +131 -0
  226. package/cpp/core/src/languages/swahili_stemmer.c +85 -0
  227. package/cpp/core/src/languages/ukrainian_stemmer.c +168 -0
  228. package/cpp/core/src/locks.c +2 -15
  229. package/cpp/core/src/math/apply.c +44 -0
  230. package/cpp/core/src/math/fdlibm.h +16 -0
  231. package/cpp/core/src/math/inverse.c +242 -0
  232. package/cpp/core/src/math/log.c +90 -0
  233. package/cpp/core/src/math/reduce.c +325 -0
  234. package/cpp/core/src/math/trig.c +188 -0
  235. package/cpp/core/src/math/words.h +45 -0
  236. package/cpp/core/src/thread_yield.h +18 -0
  237. package/cpp/core/src/unicode/decompositions.c +310 -0
  238. package/cpp/core/src/unicode/lowercase.c +172 -0
  239. package/cpp/core/src/unicode/properties.c +214 -0
  240. package/cpp/core/src/workspace.c +5 -1
  241. package/lib/engine/analysis.d.ts +3 -0
  242. package/lib/engine/analysis.js +76 -0
  243. package/lib/engine/core.js +5 -0
  244. package/lib/engine/keyword.d.ts +3 -0
  245. package/lib/engine/keyword.js +25 -0
  246. package/lib/specs/core.nitro.d.ts +1 -0
  247. package/nitrogen/generated/shared/c++/HybridNarsilCoreSpec.cpp +1 -0
  248. package/nitrogen/generated/shared/c++/HybridNarsilCoreSpec.hpp +1 -0
  249. package/package.json +4 -3
  250. package/src/engine/analysis.ts +87 -0
  251. package/src/engine/core.ts +6 -0
  252. package/src/engine/keyword.ts +26 -0
  253. package/src/specs/core.nitro.ts +1 -0
@@ -0,0 +1,242 @@
1
+ #include "fdlibm.h"
2
+ #include "words.h"
3
+
4
+ #include <math.h>
5
+ #include <stdint.h>
6
+
7
+ #define ONE_HIGH_WORD 0x3FF00000
8
+ #define HALF_HIGH_WORD 0x3FE00000
9
+ #define TINY_HIGH_WORD 0x3E400000
10
+ #define STEEP_SINE_HIGH_WORD 0x3FEF3333
11
+ #define HUGE_TANGENT_HIGH_WORD 0x44100000
12
+ #define FIRST_BAND_HIGH_WORD 0x3FDC0000
13
+ #define SECOND_BAND_HIGH_WORD 0x3FE60000
14
+ #define THIRD_BAND_HIGH_WORD 0x3FF30000
15
+ #define FOURTH_BAND_HIGH_WORD 0x40038000
16
+ #define NO_BAND (-1)
17
+ #define STEEP_BAND 3
18
+ #define RATIO_EXPONENT_LIMIT 60
19
+ #define RUN_SIGN_SHIFT 30U
20
+ #define RUN_SIGN_MASK 2U
21
+ #define BOTH_POSITIVE 0U
22
+ #define RISE_NEGATIVE 1U
23
+ #define RUN_NEGATIVE 2U
24
+
25
+ static const double huge = 1.000e+300;
26
+ static const double two = 2.0;
27
+ static const double pio2_hi = 1.57079632679489655800e+00;
28
+ static const double pio2_lo = 6.12323399573676603587e-17;
29
+ static const double pio4_hi = 7.85398163397448278999e-01;
30
+ static const double pS0 = 1.66666666666666657415e-01;
31
+ static const double pS1 = -3.25565818622400915405e-01;
32
+ static const double pS2 = 2.01212532134862925881e-01;
33
+ static const double pS3 = -4.00555345006794114027e-02;
34
+ static const double pS4 = 7.91534994289814532176e-04;
35
+ static const double pS5 = 3.47933107596021167570e-05;
36
+ static const double qS1 = -2.40339491173441421878e+00;
37
+ static const double qS2 = 2.02094576023350569471e+00;
38
+ static const double qS3 = -6.88283971605453293030e-01;
39
+ static const double qS4 = 7.70381505559019352791e-02;
40
+
41
+ static const double atanhi[] = {
42
+ 4.63647609000806093515e-01,
43
+ 7.85398163397448278999e-01,
44
+ 9.82793723247329054082e-01,
45
+ 1.57079632679489655800e+00,
46
+ };
47
+
48
+ static const double atanlo[] = {
49
+ 2.26987774529616870924e-17,
50
+ 3.06161699786838301793e-17,
51
+ 1.39033110312309984516e-17,
52
+ 6.12323399573676603587e-17,
53
+ };
54
+
55
+ static const double atan_c0 = 3.33333333333329318027e-01;
56
+ static const double atan_c1 = -1.99999999998764832476e-01;
57
+ static const double atan_c2 = 1.42857142725034663711e-01;
58
+ static const double atan_c3 = -1.11111104054623557880e-01;
59
+ static const double atan_c4 = 9.09088713343650656196e-02;
60
+ static const double atan_c5 = -7.69187620504482999495e-02;
61
+ static const double atan_c6 = 6.66107313738753120669e-02;
62
+ static const double atan_c7 = -5.83357013379057348645e-02;
63
+ static const double atan_c8 = 4.97687799461593236017e-02;
64
+ static const double atan_c9 = -3.65315727442169155270e-02;
65
+ static const double atan_c10 = 1.62858201153657823623e-02;
66
+
67
+ static const double one_and_half = 1.5;
68
+ static const double half = 0.5;
69
+ static const double tiny = 1.0e-300;
70
+ static const double pi_o_4 = 7.8539816339744827900E-01;
71
+ static const double pi_o_2 = 1.5707963267948965580E+00;
72
+ static const double pi_whole = 3.1415926535897931160E+00;
73
+ static const double pi_lo = 1.2246467991473531772E-16;
74
+ static const double three = 3.0;
75
+
76
+ static double asin_ratio(double square) {
77
+ double numerator =
78
+ square * (pS0 + (square * (pS1 + (square * (pS2 + (square * (pS3 + (square * (pS4 + (square * pS5))))))))));
79
+ double denominator = 1.0 + (square * (qS1 + (square * (qS2 + (square * (qS3 + (square * qS4)))))));
80
+ return numerator / denominator;
81
+ }
82
+
83
+ static double steep_asin(double value) {
84
+ int32_t magnitude = high_word(value) & MAGNITUDE_MASK;
85
+ double rest = 1.0 - fabs(value);
86
+ double half_rest = rest * half;
87
+ double root = sqrt(half_rest);
88
+ if (magnitude >= STEEP_SINE_HIGH_WORD) {
89
+ return pio2_hi - ((two * (root + (root * asin_ratio(half_rest)))) - pio2_lo);
90
+ }
91
+ double root_head = with_low_word(root, 0);
92
+ double correction = (half_rest - (root_head * root_head)) / (root + root_head);
93
+ double ratio = asin_ratio(half_rest);
94
+ double low_part = (two * root * ratio) - (pio2_lo - (two * correction));
95
+ double high_part = pio4_hi - (two * root_head);
96
+ return pio4_hi - (low_part - high_part);
97
+ }
98
+
99
+ double fdlibm_asin(double value) {
100
+ int32_t high = high_word(value);
101
+ int32_t magnitude = high & MAGNITUDE_MASK;
102
+ if (magnitude >= ONE_HIGH_WORD) {
103
+ if (((uint32_t)(magnitude - ONE_HIGH_WORD) | low_word(value)) == 0U) {
104
+ return (value * pio2_hi) + (value * pio2_lo);
105
+ }
106
+ return (double)NAN;
107
+ }
108
+ if (magnitude < HALF_HIGH_WORD) {
109
+ double square = 0;
110
+ if (magnitude < TINY_HIGH_WORD) {
111
+ if (huge + value > 1.0) { return value; }
112
+ } else {
113
+ square = value * value;
114
+ }
115
+ return value + (value * asin_ratio(square));
116
+ }
117
+ double angle = steep_asin(value);
118
+ return is_negative_word(high) ? -angle : angle;
119
+ }
120
+
121
+ static int atan_band(double *value, int32_t magnitude) {
122
+ if (magnitude < FIRST_BAND_HIGH_WORD) { return NO_BAND; }
123
+ double absolute = fabs(*value);
124
+ if (magnitude < SECOND_BAND_HIGH_WORD) {
125
+ *value = ((two * absolute) - 1.0) / (two + absolute);
126
+ return 0;
127
+ }
128
+ if (magnitude < THIRD_BAND_HIGH_WORD) {
129
+ *value = (absolute - 1.0) / (absolute + 1.0);
130
+ return 1;
131
+ }
132
+ if (magnitude < FOURTH_BAND_HIGH_WORD) {
133
+ *value = (absolute - one_and_half) / (1.0 + (one_and_half * absolute));
134
+ return 2;
135
+ }
136
+ *value = -1.0 / absolute;
137
+ return STEEP_BAND;
138
+ }
139
+
140
+ double fdlibm_atan(double value) {
141
+ int32_t high = high_word(value);
142
+ int32_t magnitude = high & MAGNITUDE_MASK;
143
+ if (magnitude >= HUGE_TANGENT_HIGH_WORD) {
144
+ if (magnitude > INFINITE_HIGH_WORD || (magnitude == INFINITE_HIGH_WORD && low_word(value) != 0U)) {
145
+ return (double)NAN;
146
+ }
147
+ return is_negative_word(high) ? -atanhi[STEEP_BAND] - atanlo[STEEP_BAND] : atanhi[STEEP_BAND] + atanlo[STEEP_BAND];
148
+ }
149
+ if (magnitude < TINY_HIGH_WORD && huge + value > 1.0) { return value; }
150
+ double reduced = value;
151
+ int band = atan_band(&reduced, magnitude);
152
+ double square = reduced * reduced;
153
+ double fourth = square * square;
154
+ double odd =
155
+ square *
156
+ (atan_c0 +
157
+ (fourth * (atan_c2 + (fourth * (atan_c4 + (fourth * (atan_c6 + (fourth * (atan_c8 + (fourth * atan_c10))))))))));
158
+ double even =
159
+ fourth * (atan_c1 + (fourth * (atan_c3 + (fourth * (atan_c5 + (fourth * (atan_c7 + (fourth * atan_c9))))))));
160
+ if (band < 0) { return reduced - (reduced * (odd + even)); }
161
+ double angle = atanhi[band] - (((reduced * (odd + even)) - atanlo[band]) - reduced);
162
+ return is_negative_word(high) ? -angle : angle;
163
+ }
164
+
165
+ static int is_nan_value(double value) {
166
+ uint32_t low = low_word(value);
167
+ uint32_t magnitude = (uint32_t)(high_word(value) & MAGNITUDE_MASK);
168
+ return (magnitude | ((low | (0U - low)) >> SIGN_BIT)) > (uint32_t)INFINITE_HIGH_WORD;
169
+ }
170
+
171
+ static double both_infinite(uint32_t quadrant) {
172
+ if (quadrant == BOTH_POSITIVE) { return pi_o_4 + tiny; }
173
+ if (quadrant == RISE_NEGATIVE) { return -pi_o_4 - tiny; }
174
+ if (quadrant == RUN_NEGATIVE) { return (three * pi_o_4) + tiny; }
175
+ return (-three * pi_o_4) - tiny;
176
+ }
177
+
178
+ static double run_infinite(uint32_t quadrant) {
179
+ if (quadrant == BOTH_POSITIVE) { return 0.0; }
180
+ if (quadrant == RISE_NEGATIVE) { return -0.0; }
181
+ if (quadrant == RUN_NEGATIVE) { return pi_whole + tiny; }
182
+ return -pi_whole - tiny;
183
+ }
184
+
185
+ typedef struct {
186
+ double rise;
187
+ double run;
188
+ uint32_t quadrant;
189
+ } slope;
190
+
191
+ static double place_in_quadrant(const slope *line, double angle) {
192
+ if (line->quadrant == BOTH_POSITIVE) { return angle; }
193
+ if (line->quadrant == RISE_NEGATIVE) { return -angle; }
194
+ if (line->quadrant == RUN_NEGATIVE) { return pi_whole - (angle - pi_lo); }
195
+ return (angle - pi_lo) - pi_whole;
196
+ }
197
+
198
+ static double edge_angle(const slope *line, int *found) {
199
+ uint32_t quadrant = line->quadrant;
200
+ int32_t run_high = high_word(line->run);
201
+ uint32_t run_low = low_word(line->run);
202
+ int32_t run_magnitude = run_high & MAGNITUDE_MASK;
203
+ int32_t rise_high = high_word(line->rise);
204
+ int32_t rise_magnitude = rise_high & MAGNITUDE_MASK;
205
+ *found = 1;
206
+ if (((uint32_t)rise_magnitude | low_word(line->rise)) == 0U) {
207
+ if (quadrant == BOTH_POSITIVE || quadrant == RISE_NEGATIVE) { return line->rise; }
208
+ return quadrant == RUN_NEGATIVE ? pi_whole + tiny : -pi_whole - tiny;
209
+ }
210
+ if (((uint32_t)run_magnitude | run_low) == 0U) {
211
+ return is_negative_word(rise_high) ? -pi_o_2 - tiny : pi_o_2 + tiny;
212
+ }
213
+ if (run_magnitude == INFINITE_HIGH_WORD) {
214
+ return rise_magnitude == INFINITE_HIGH_WORD ? both_infinite(quadrant) : run_infinite(quadrant);
215
+ }
216
+ if (rise_magnitude == INFINITE_HIGH_WORD) { return is_negative_word(rise_high) ? -pi_o_2 - tiny : pi_o_2 + tiny; }
217
+ *found = 0;
218
+ return 0.0;
219
+ }
220
+
221
+ double fdlibm_atan2(double rise, double run) {
222
+ if (is_nan_value(rise) || is_nan_value(run)) { return (double)NAN; }
223
+ int32_t run_high = high_word(run);
224
+ if ((((uint32_t)run_high - (uint32_t)ONE_HIGH_WORD) | low_word(run)) == 0U) { return fdlibm_atan(rise); }
225
+ int32_t rise_high = high_word(rise);
226
+ slope line = {rise, run,
227
+ (((uint32_t)rise_high >> SIGN_BIT) & 1U) | (((uint32_t)run_high >> RUN_SIGN_SHIFT) & RUN_SIGN_MASK)};
228
+ int found = 0;
229
+ double edge = edge_angle(&line, &found);
230
+ if (found) { return edge; }
231
+ int32_t exponent_gap = floor_shift((rise_high & MAGNITUDE_MASK) - (run_high & MAGNITUDE_MASK), EXPONENT_SHIFT);
232
+ double angle = 0.0;
233
+ if (exponent_gap > RATIO_EXPONENT_LIMIT) {
234
+ angle = pi_o_2 + (half * pi_lo);
235
+ line.quadrant &= 1U;
236
+ } else if (is_negative_word(run_high) && exponent_gap < -RATIO_EXPONENT_LIMIT) {
237
+ angle = 0.0;
238
+ } else {
239
+ angle = fdlibm_atan(fabs(rise / run));
240
+ }
241
+ return place_in_quadrant(&line, angle);
242
+ }
@@ -0,0 +1,90 @@
1
+ #include "fdlibm.h"
2
+ #include "words.h"
3
+
4
+ #include <math.h>
5
+ #include <stdint.h>
6
+
7
+ #define EXPONENT_BIAS 1023
8
+ #define SUBNORMAL_SCALE_EXPONENT 54
9
+ #define ROUNDING_OFFSET 0x95F64
10
+ #define HALVING_BIT 0x100000
11
+ #define ONE_HIGH_WORD 0x3FF00000
12
+ #define SIGNIFICAND_MASK 0x000FFFFF
13
+ #define NEAR_ONE_LIMIT 3
14
+ #define LOWER_SPLIT 0x6147A
15
+ #define UPPER_SPLIT 0x6B851
16
+
17
+ static const double ln2_hi = 6.93147180369123816490e-01;
18
+ static const double ln2_lo = 1.90821492927058770002e-10;
19
+ static const double two54 = 1.80143985094819840000e+16;
20
+ static const double two = 2.0;
21
+ static const double third = 0.33333333333333333;
22
+ static const double half = 0.5;
23
+ static const double lg1 = 6.666666666666735130e-01;
24
+ static const double lg2 = 3.999999999940941908e-01;
25
+ static const double lg3 = 2.857142874366239149e-01;
26
+ static const double lg4 = 2.222219843214978396e-01;
27
+ static const double lg5 = 1.818357216161805012e-01;
28
+ static const double lg6 = 1.531383769920937332e-01;
29
+ static const double lg7 = 1.479819860511658591e-01;
30
+
31
+ typedef struct {
32
+ double fraction;
33
+ int32_t scale;
34
+ int32_t significand;
35
+ } log_parts;
36
+
37
+ static double near_one(const log_parts *parts) {
38
+ double fraction = parts->fraction;
39
+ if (fraction == 0.0) {
40
+ if (parts->scale == 0) { return 0.0; }
41
+ double scale = (double)parts->scale;
42
+ return (scale * ln2_hi) + (scale * ln2_lo);
43
+ }
44
+ double cubic = fraction * fraction * (half - (third * fraction));
45
+ if (parts->scale == 0) { return fraction - cubic; }
46
+ double scale = (double)parts->scale;
47
+ return (scale * ln2_hi) - ((cubic - (scale * ln2_lo)) - fraction);
48
+ }
49
+
50
+ static double series(const log_parts *parts) {
51
+ double fraction = parts->fraction;
52
+ double ratio = fraction / (two + fraction);
53
+ double scale = (double)parts->scale;
54
+ double square = ratio * ratio;
55
+ int32_t below = parts->significand - LOWER_SPLIT;
56
+ double fourth = square * square;
57
+ int32_t above = UPPER_SPLIT - parts->significand;
58
+ double even = fourth * (lg2 + (fourth * (lg4 + (fourth * lg6))));
59
+ double odd = square * (lg1 + (fourth * (lg3 + (fourth * (lg5 + (fourth * lg7))))));
60
+ double poly = odd + even;
61
+ if ((below | above) > 0) {
62
+ double half_square = half * fraction * fraction;
63
+ if (parts->scale == 0) { return fraction - (half_square - (ratio * (half_square + poly))); }
64
+ return (scale * ln2_hi) - ((half_square - ((ratio * (half_square + poly)) + (scale * ln2_lo))) - fraction);
65
+ }
66
+ if (parts->scale == 0) { return fraction - (ratio * (fraction - poly)); }
67
+ return (scale * ln2_hi) - (((ratio * (fraction - poly)) - (scale * ln2_lo)) - fraction);
68
+ }
69
+
70
+ double fdlibm_log(double value) {
71
+ int32_t high = high_word(value);
72
+ int32_t scale = 0;
73
+ double scaled = value;
74
+ if (high < SMALLEST_NORMAL_HIGH_WORD) {
75
+ if (((uint32_t)(high & MAGNITUDE_MASK) | low_word(value)) == 0U) { return -HUGE_VAL; }
76
+ if (high < 0) { return (double)NAN; }
77
+ scale -= SUBNORMAL_SCALE_EXPONENT;
78
+ scaled *= two54;
79
+ high = high_word(scaled);
80
+ }
81
+ if (high >= INFINITE_HIGH_WORD) { return scaled + scaled; }
82
+ scale += (high >> EXPONENT_SHIFT) - EXPONENT_BIAS;
83
+ int32_t significand = high & SIGNIFICAND_MASK;
84
+ int32_t halving = (significand + ROUNDING_OFFSET) & HALVING_BIT;
85
+ scaled = with_high_word(scaled, significand | (halving ^ ONE_HIGH_WORD));
86
+ scale += halving >> EXPONENT_SHIFT;
87
+ log_parts parts = {scaled - 1.0, scale, significand};
88
+ if ((SIGNIFICAND_MASK & (2 + significand)) < NEAR_ONE_LIMIT) { return near_one(&parts); }
89
+ return series(&parts);
90
+ }
@@ -0,0 +1,325 @@
1
+ #include "fdlibm.h"
2
+ #include "words.h"
3
+
4
+ #include <math.h>
5
+ #include <stdint.h>
6
+
7
+ #define CHUNK_BITS 24
8
+ #define CHUNK_TOP_BIT 23
9
+ #define CHUNK_LIMIT 0x1000000
10
+ #define CHUNK_MASK 0xFFFFFF
11
+ #define CHUNK_SLOTS 20
12
+ #define EXTENDED_TERMS 4
13
+ #define EXPONENT_BIAS_LESS_23 1046
14
+ #define INPUT_CHUNKS 3
15
+ #define INTEGRAL_INPUT_CHUNKS 2
16
+ #define OCTANT_MASK 7
17
+ #define PAST_HALF_TURN 2
18
+ #define TOP_CHUNK_MASK_ONE 0x7FFFFF
19
+ #define TOP_CHUNK_MASK_TWO 0x3FFFFF
20
+ #define TABLED_MULTIPLES 32
21
+ #define PI_OVER_FOUR_HIGH_WORD 0x3FE921FB
22
+ #define PI_OVER_TWO_HIGH_WORD 0x3FF921FB
23
+ #define THREE_PI_OVER_FOUR_HIGH_WORD 0x4002D97C
24
+ #define MEDIUM_LIMIT_HIGH_WORD 0x413921FB
25
+ #define SECOND_ROUND_CANCELLED_BITS 16
26
+ #define THIRD_ROUND_CANCELLED_BITS 49
27
+
28
+ static const int32_t two_over_pi[] = {
29
+ 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7,
30
+ 0x246E3A, 0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, 0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C,
31
+ 0x7026B4, 0x5F7E41, 0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, 0x97FFDE, 0x05980F, 0xEF2F11,
32
+ 0x8B5A0A, 0x6D1F6D, 0x367ECF, 0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, 0xF17B3D, 0x0739F7,
33
+ 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, 0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, 0x91615E,
34
+ 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, 0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
35
+ };
36
+
37
+ static const int32_t multiple_high_words[TABLED_MULTIPLES] = {
38
+ 0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, 0x4025FDBB, 0x402921FB,
39
+ 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, 0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB,
40
+ 0x403AB41B, 0x403C463A, 0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
41
+ 0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, 0x404858EB, 0x404921FB,
42
+ };
43
+
44
+ static const double pi_over_two_chunks[] = {
45
+ 1.57079625129699707031e+00, 7.54978941586159635335e-08, 5.39030252995776476554e-15, 3.28200341580791294123e-22,
46
+ 1.27065575308067607349e-29, 1.22933308981111328932e-36, 2.73370053816464559624e-44, 2.16741683877804819444e-51,
47
+ };
48
+
49
+ static const double two24 = 1.67772160000000000000e+07;
50
+ static const double twon24 = 5.96046447753906250000e-08;
51
+ static const double one_eighth = 0.125;
52
+ static const double eight = 8.0;
53
+ static const double half = 5.00000000000000000000e-01;
54
+ static const double invpio2 = 6.36619772367581382433e-01;
55
+ static const double pio2_1 = 1.57079632673412561417e+00;
56
+ static const double pio2_1t = 6.07710050650619224932e-11;
57
+ static const double pio2_2 = 6.07710050630396597660e-11;
58
+ static const double pio2_2t = 2.02226624879595063154e-21;
59
+ static const double pio2_3 = 2.02226624871116645580e-21;
60
+ static const double pio2_3t = 8.47842766036889956997e-32;
61
+
62
+ typedef struct {
63
+ const double *input;
64
+ int32_t last_input;
65
+ int32_t table_start;
66
+ int32_t exponent;
67
+ int32_t top;
68
+ int32_t quotient;
69
+ int32_t past_half;
70
+ double fraction;
71
+ int32_t chunks[CHUNK_SLOTS];
72
+ double factors[CHUNK_SLOTS];
73
+ double terms[CHUNK_SLOTS];
74
+ double products[CHUNK_SLOTS];
75
+ } reduction;
76
+
77
+ static double product_term(const reduction *red, int32_t index) {
78
+ double sum = 0.0;
79
+ for (int32_t j = 0; j <= red->last_input; j++) { sum += red->input[j] * red->factors[red->last_input + index - j]; }
80
+ return sum;
81
+ }
82
+
83
+ static void distill(reduction *red) {
84
+ double rest = red->products[red->top];
85
+ for (int32_t i = 0, j = red->top; j > 0; i++, j--) {
86
+ double carried = (double)(int32_t)(twon24 * rest);
87
+ red->chunks[i] = (int32_t)(rest - (two24 * carried));
88
+ rest = red->products[j - 1] + carried;
89
+ }
90
+ red->fraction = rest;
91
+ }
92
+
93
+ static void split_quotient(reduction *red) {
94
+ double scaled = scalbn(red->fraction, red->exponent);
95
+ scaled -= eight * floor(scaled * one_eighth);
96
+ red->quotient = (int32_t)scaled;
97
+ scaled -= (double)red->quotient;
98
+ red->past_half = 0;
99
+ int32_t highest = red->top - 1;
100
+ if (highest >= 0 && red->exponent > 0) {
101
+ int32_t whole = red->chunks[highest] >> (CHUNK_BITS - red->exponent);
102
+ red->quotient += whole;
103
+ red->chunks[highest] -= whole << (CHUNK_BITS - red->exponent);
104
+ red->past_half = red->chunks[highest] >> (CHUNK_TOP_BIT - red->exponent);
105
+ } else if (highest >= 0 && red->exponent == 0) {
106
+ red->past_half = red->chunks[highest] >> CHUNK_TOP_BIT;
107
+ } else if (scaled >= half) {
108
+ red->past_half = PAST_HALF_TURN;
109
+ }
110
+ red->fraction = scaled;
111
+ }
112
+
113
+ static void complement(reduction *red) {
114
+ if (red->past_half <= 0) { return; }
115
+ int32_t carry = 0;
116
+ red->quotient += 1;
117
+ for (int32_t i = 0; i < red->top; i++) {
118
+ int32_t chunk = red->chunks[i];
119
+ if (carry == 0) {
120
+ if (chunk != 0) {
121
+ carry = 1;
122
+ red->chunks[i] = CHUNK_LIMIT - chunk;
123
+ }
124
+ } else {
125
+ red->chunks[i] = CHUNK_MASK - chunk;
126
+ }
127
+ }
128
+ int32_t highest = red->top - 1;
129
+ if (highest >= 0 && highest < CHUNK_SLOTS) {
130
+ if (red->exponent == 1) { red->chunks[highest] &= TOP_CHUNK_MASK_ONE; }
131
+ if (red->exponent == 2) { red->chunks[highest] &= TOP_CHUNK_MASK_TWO; }
132
+ }
133
+ if (red->past_half == PAST_HALF_TURN) {
134
+ red->fraction = 1.0 - red->fraction;
135
+ if (carry != 0) { red->fraction -= scalbn(1.0, red->exponent); }
136
+ }
137
+ }
138
+
139
+ static int32_t more_terms_needed(const reduction *red) {
140
+ if (red->fraction != 0.0) { return 0; }
141
+ int32_t bits = 0;
142
+ for (int32_t i = red->top - 1; i >= EXTENDED_TERMS; i--) { bits |= red->chunks[i]; }
143
+ if (bits != 0) { return 0; }
144
+ int32_t count = 1;
145
+ while (EXTENDED_TERMS >= count && red->chunks[EXTENDED_TERMS - count] == 0) { count++; }
146
+ return count;
147
+ }
148
+
149
+ static void extend(reduction *red, int32_t count) {
150
+ for (int32_t i = red->top + 1; i <= red->top + count; i++) {
151
+ red->factors[red->last_input + i] = (double)two_over_pi[red->table_start + i];
152
+ red->products[i] = product_term(red, i);
153
+ }
154
+ red->top += count;
155
+ }
156
+
157
+ static void normalise_chunks(reduction *red) {
158
+ if (red->fraction == 0.0) {
159
+ red->top -= 1;
160
+ red->exponent -= CHUNK_BITS;
161
+ while (red->top > 0 && red->chunks[red->top] == 0) {
162
+ red->top--;
163
+ red->exponent -= CHUNK_BITS;
164
+ }
165
+ return;
166
+ }
167
+ double scaled = scalbn(red->fraction, -red->exponent);
168
+ if (scaled >= two24) {
169
+ double carried = (double)(int32_t)(twon24 * scaled);
170
+ red->chunks[red->top] = (int32_t)(scaled - (two24 * carried));
171
+ red->top += 1;
172
+ red->exponent += CHUNK_BITS;
173
+ red->chunks[red->top] = (int32_t)carried;
174
+ } else {
175
+ red->chunks[red->top] = (int32_t)scaled;
176
+ }
177
+ }
178
+
179
+ static void write_result(reduction *red, double *out) {
180
+ double scale = scalbn(1.0, red->exponent);
181
+ for (int32_t i = red->top; i >= 0; i--) {
182
+ red->products[i] = scale * (double)red->chunks[i];
183
+ scale *= twon24;
184
+ }
185
+ for (int32_t i = red->top; i >= 0; i--) {
186
+ double sum = 0.0;
187
+ for (int32_t k = 0; k <= EXTENDED_TERMS && k <= red->top - i; k++) {
188
+ sum += pi_over_two_chunks[k] * red->products[i + k];
189
+ }
190
+ red->terms[red->top - i] = sum;
191
+ }
192
+ double sum = 0.0;
193
+ for (int32_t i = red->top; i >= 0; i--) { sum += red->terms[i]; }
194
+ out[0] = red->past_half == 0 ? sum : -sum;
195
+ sum = red->terms[0] - sum;
196
+ for (int32_t i = 1; i <= red->top; i++) { sum += red->terms[i]; }
197
+ out[1] = red->past_half == 0 ? sum : -sum;
198
+ }
199
+
200
+ static int32_t kernel_rem_pio2(const double *input, int32_t count, double *out, int32_t exponent) {
201
+ reduction red = {0};
202
+ red.input = input;
203
+ red.last_input = count - 1;
204
+ red.table_start = (exponent - 3) / CHUNK_BITS;
205
+ if (red.table_start < 0) { red.table_start = 0; }
206
+ red.exponent = exponent - (CHUNK_BITS * (red.table_start + 1));
207
+ for (int32_t i = 0, j = red.table_start - red.last_input; i <= red.last_input + EXTENDED_TERMS; i++, j++) {
208
+ red.factors[i] = j < 0 ? 0.0 : (double)two_over_pi[j];
209
+ }
210
+ for (int32_t i = 0; i <= EXTENDED_TERMS; i++) { red.products[i] = product_term(&red, i); }
211
+ red.top = EXTENDED_TERMS;
212
+ for (;;) {
213
+ distill(&red);
214
+ split_quotient(&red);
215
+ complement(&red);
216
+ int32_t needed = more_terms_needed(&red);
217
+ if (needed == 0) { break; }
218
+ extend(&red, needed);
219
+ }
220
+ normalise_chunks(&red);
221
+ write_result(&red, out);
222
+ return red.quotient & OCTANT_MASK;
223
+ }
224
+
225
+ static int32_t near_quarter_turn(double value, double *out) {
226
+ int32_t magnitude = high_word(value) & MAGNITUDE_MASK;
227
+ if (!is_negative_word(high_word(value))) {
228
+ double rest = value - pio2_1;
229
+ if (magnitude != PI_OVER_TWO_HIGH_WORD) {
230
+ out[0] = rest - pio2_1t;
231
+ out[1] = (rest - out[0]) - pio2_1t;
232
+ } else {
233
+ rest -= pio2_2;
234
+ out[0] = rest - pio2_2t;
235
+ out[1] = (rest - out[0]) - pio2_2t;
236
+ }
237
+ return 1;
238
+ }
239
+ double rest = value + pio2_1;
240
+ if (magnitude != PI_OVER_TWO_HIGH_WORD) {
241
+ out[0] = rest + pio2_1t;
242
+ out[1] = (rest - out[0]) + pio2_1t;
243
+ } else {
244
+ rest += pio2_2;
245
+ out[0] = rest + pio2_2t;
246
+ out[1] = (rest - out[0]) + pio2_2t;
247
+ }
248
+ return -1;
249
+ }
250
+
251
+ static int32_t cancelled_bits(int32_t exponent, double reduced) {
252
+ return exponent - (int32_t)(((uint32_t)high_word(reduced) >> EXPONENT_SHIFT) & EXPONENT_MASK);
253
+ }
254
+
255
+ static int32_t medium_turns(double value, double *out) {
256
+ int32_t magnitude = high_word(value) & MAGNITUDE_MASK;
257
+ double absolute = fabs(value);
258
+ int32_t turns = (int32_t)((absolute * invpio2) + half);
259
+ double whole = (double)turns;
260
+ double rest = absolute - (whole * pio2_1);
261
+ double tail = whole * pio2_1t;
262
+ out[0] = rest - tail;
263
+ if (turns >= TABLED_MULTIPLES || magnitude == multiple_high_words[turns - 1]) {
264
+ int32_t exponent = magnitude >> EXPONENT_SHIFT;
265
+ if (cancelled_bits(exponent, out[0]) > SECOND_ROUND_CANCELLED_BITS) {
266
+ double before = rest;
267
+ tail = whole * pio2_2;
268
+ rest = before - tail;
269
+ tail = (whole * pio2_2t) - ((before - rest) - tail);
270
+ out[0] = rest - tail;
271
+ if (cancelled_bits(exponent, out[0]) > THIRD_ROUND_CANCELLED_BITS) {
272
+ before = rest;
273
+ tail = whole * pio2_3;
274
+ rest = before - tail;
275
+ tail = (whole * pio2_3t) - ((before - rest) - tail);
276
+ out[0] = rest - tail;
277
+ }
278
+ }
279
+ }
280
+ out[1] = (rest - out[0]) - tail;
281
+ if (is_negative_word(high_word(value))) {
282
+ out[0] = -out[0];
283
+ out[1] = -out[1];
284
+ return -turns;
285
+ }
286
+ return turns;
287
+ }
288
+
289
+ static int32_t large_turns(double value, double *out) {
290
+ int32_t magnitude = high_word(value) & MAGNITUDE_MASK;
291
+ int32_t exponent = (magnitude >> EXPONENT_SHIFT) - EXPONENT_BIAS_LESS_23;
292
+ double scaled = from_words(magnitude - (int32_t)((uint32_t)exponent << EXPONENT_SHIFT), low_word(value));
293
+ double chunks[INPUT_CHUNKS];
294
+ for (int32_t i = 0; i < INTEGRAL_INPUT_CHUNKS; i++) {
295
+ chunks[i] = (double)(int32_t)scaled;
296
+ scaled = (scaled - chunks[i]) * two24;
297
+ }
298
+ chunks[INTEGRAL_INPUT_CHUNKS] = scaled;
299
+ int32_t count = INPUT_CHUNKS;
300
+ while (count > 1 && chunks[count - 1] == 0.0) { count--; }
301
+ int32_t turns = kernel_rem_pio2(chunks, count, out, exponent);
302
+ if (is_negative_word(high_word(value))) {
303
+ out[0] = -out[0];
304
+ out[1] = -out[1];
305
+ return -turns;
306
+ }
307
+ return turns;
308
+ }
309
+
310
+ int32_t fdlibm_rem_pio2(double value, double *out) {
311
+ int32_t magnitude = high_word(value) & MAGNITUDE_MASK;
312
+ if (magnitude <= PI_OVER_FOUR_HIGH_WORD) {
313
+ out[0] = value;
314
+ out[1] = 0;
315
+ return 0;
316
+ }
317
+ if (magnitude < THREE_PI_OVER_FOUR_HIGH_WORD) { return near_quarter_turn(value, out); }
318
+ if (magnitude <= MEDIUM_LIMIT_HIGH_WORD) { return medium_turns(value, out); }
319
+ if (magnitude >= INFINITE_HIGH_WORD) {
320
+ out[0] = (double)NAN;
321
+ out[1] = out[0];
322
+ return 0;
323
+ }
324
+ return large_turns(value, out);
325
+ }