@fluixi/utils 1.0.0-alpha.53

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 (354) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/dist/index.cjs +1 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/index.mjs +1 -0
  8. package/dist/lib/array/advanced.cjs +1 -0
  9. package/dist/lib/array/advanced.d.ts +1116 -0
  10. package/dist/lib/array/advanced.d.ts.map +1 -0
  11. package/dist/lib/array/advanced.js +2429 -0
  12. package/dist/lib/array/advanced.mjs +1 -0
  13. package/dist/lib/array/array.cjs +1 -0
  14. package/dist/lib/array/array.d.ts +6 -0
  15. package/dist/lib/array/array.d.ts.map +1 -0
  16. package/dist/lib/array/array.js +31 -0
  17. package/dist/lib/array/array.mjs +1 -0
  18. package/dist/lib/array/index.cjs +1 -0
  19. package/dist/lib/array/index.d.ts +4 -0
  20. package/dist/lib/array/index.d.ts.map +1 -0
  21. package/dist/lib/array/index.js +3 -0
  22. package/dist/lib/array/index.mjs +1 -0
  23. package/dist/lib/array/utils.cjs +1 -0
  24. package/dist/lib/array/utils.d.ts +100 -0
  25. package/dist/lib/array/utils.d.ts.map +1 -0
  26. package/dist/lib/array/utils.js +165 -0
  27. package/dist/lib/array/utils.mjs +1 -0
  28. package/dist/lib/color/color.cjs +1 -0
  29. package/dist/lib/color/color.d.ts +366 -0
  30. package/dist/lib/color/color.d.ts.map +1 -0
  31. package/dist/lib/color/color.js +722 -0
  32. package/dist/lib/color/color.mjs +1 -0
  33. package/dist/lib/color/constants.cjs +1 -0
  34. package/dist/lib/color/constants.d.ts +361 -0
  35. package/dist/lib/color/constants.d.ts.map +1 -0
  36. package/dist/lib/color/constants.js +358 -0
  37. package/dist/lib/color/constants.mjs +1 -0
  38. package/dist/lib/color/conversions.cjs +1 -0
  39. package/dist/lib/color/conversions.d.ts +166 -0
  40. package/dist/lib/color/conversions.d.ts.map +1 -0
  41. package/dist/lib/color/conversions.js +766 -0
  42. package/dist/lib/color/conversions.mjs +1 -0
  43. package/dist/lib/color/helpers.cjs +1 -0
  44. package/dist/lib/color/helpers.d.ts +75 -0
  45. package/dist/lib/color/helpers.d.ts.map +1 -0
  46. package/dist/lib/color/helpers.js +419 -0
  47. package/dist/lib/color/helpers.mjs +1 -0
  48. package/dist/lib/color/index.cjs +1 -0
  49. package/dist/lib/color/index.d.ts +12 -0
  50. package/dist/lib/color/index.d.ts.map +1 -0
  51. package/dist/lib/color/index.js +15 -0
  52. package/dist/lib/color/index.mjs +1 -0
  53. package/dist/lib/color/types.cjs +1 -0
  54. package/dist/lib/color/types.d.ts +179 -0
  55. package/dist/lib/color/types.d.ts.map +1 -0
  56. package/dist/lib/color/types.js +1 -0
  57. package/dist/lib/color/types.mjs +0 -0
  58. package/dist/lib/color/utils.cjs +1 -0
  59. package/dist/lib/color/utils.d.ts +199 -0
  60. package/dist/lib/color/utils.d.ts.map +1 -0
  61. package/dist/lib/color/utils.js +858 -0
  62. package/dist/lib/color/utils.mjs +1 -0
  63. package/dist/lib/compare/comparators.cjs +1 -0
  64. package/dist/lib/compare/comparators.d.ts +65 -0
  65. package/dist/lib/compare/comparators.d.ts.map +1 -0
  66. package/dist/lib/compare/comparators.js +210 -0
  67. package/dist/lib/compare/comparators.mjs +1 -0
  68. package/dist/lib/compare/index.cjs +1 -0
  69. package/dist/lib/compare/index.d.ts +2 -0
  70. package/dist/lib/compare/index.d.ts.map +1 -0
  71. package/dist/lib/compare/index.js +1 -0
  72. package/dist/lib/compare/index.mjs +1 -0
  73. package/dist/lib/crypto/hash.cjs +1 -0
  74. package/dist/lib/crypto/hash.d.ts +6 -0
  75. package/dist/lib/crypto/hash.d.ts.map +1 -0
  76. package/dist/lib/crypto/hash.js +53 -0
  77. package/dist/lib/crypto/hash.mjs +1 -0
  78. package/dist/lib/crypto/index.cjs +1 -0
  79. package/dist/lib/crypto/index.d.ts +2 -0
  80. package/dist/lib/crypto/index.d.ts.map +1 -0
  81. package/dist/lib/crypto/index.js +1 -0
  82. package/dist/lib/crypto/index.mjs +1 -0
  83. package/dist/lib/dom/events.cjs +1 -0
  84. package/dist/lib/dom/events.d.ts +159 -0
  85. package/dist/lib/dom/events.d.ts.map +1 -0
  86. package/dist/lib/dom/events.js +50 -0
  87. package/dist/lib/dom/events.mjs +1 -0
  88. package/dist/lib/dom/index.cjs +1 -0
  89. package/dist/lib/dom/index.d.ts +3 -0
  90. package/dist/lib/dom/index.d.ts.map +1 -0
  91. package/dist/lib/dom/index.js +2 -0
  92. package/dist/lib/dom/index.mjs +1 -0
  93. package/dist/lib/dom/utils.cjs +1 -0
  94. package/dist/lib/dom/utils.d.ts +6 -0
  95. package/dist/lib/dom/utils.d.ts.map +1 -0
  96. package/dist/lib/dom/utils.js +37 -0
  97. package/dist/lib/dom/utils.mjs +1 -0
  98. package/dist/lib/functions/functions.cjs +1 -0
  99. package/dist/lib/functions/functions.d.ts +329 -0
  100. package/dist/lib/functions/functions.d.ts.map +1 -0
  101. package/dist/lib/functions/functions.js +585 -0
  102. package/dist/lib/functions/functions.mjs +1 -0
  103. package/dist/lib/functions/index.cjs +1 -0
  104. package/dist/lib/functions/index.d.ts +3 -0
  105. package/dist/lib/functions/index.d.ts.map +1 -0
  106. package/dist/lib/functions/index.js +1 -0
  107. package/dist/lib/functions/index.mjs +1 -0
  108. package/dist/lib/functions/types.cjs +1 -0
  109. package/dist/lib/functions/types.d.ts +2 -0
  110. package/dist/lib/functions/types.d.ts.map +1 -0
  111. package/dist/lib/functions/types.js +1 -0
  112. package/dist/lib/functions/types.mjs +0 -0
  113. package/dist/lib/helpers.cjs +1 -0
  114. package/dist/lib/helpers.d.ts +13 -0
  115. package/dist/lib/helpers.d.ts.map +1 -0
  116. package/dist/lib/helpers.js +66 -0
  117. package/dist/lib/helpers.mjs +1 -0
  118. package/dist/lib/index.cjs +1 -0
  119. package/dist/lib/index.d.ts +6 -0
  120. package/dist/lib/index.d.ts.map +1 -0
  121. package/dist/lib/index.js +8 -0
  122. package/dist/lib/index.mjs +1 -0
  123. package/dist/lib/maths/constants.cjs +1 -0
  124. package/dist/lib/maths/constants.d.ts +84 -0
  125. package/dist/lib/maths/constants.d.ts.map +1 -0
  126. package/dist/lib/maths/constants.js +79 -0
  127. package/dist/lib/maths/constants.mjs +1 -0
  128. package/dist/lib/maths/fn/advanced.cjs +1 -0
  129. package/dist/lib/maths/fn/advanced.d.ts +149 -0
  130. package/dist/lib/maths/fn/advanced.d.ts.map +1 -0
  131. package/dist/lib/maths/fn/advanced.js +264 -0
  132. package/dist/lib/maths/fn/advanced.mjs +1 -0
  133. package/dist/lib/maths/fn/basic.cjs +1 -0
  134. package/dist/lib/maths/fn/basic.d.ts +182 -0
  135. package/dist/lib/maths/fn/basic.d.ts.map +1 -0
  136. package/dist/lib/maths/fn/basic.js +343 -0
  137. package/dist/lib/maths/fn/basic.mjs +1 -0
  138. package/dist/lib/maths/fn/complex.cjs +1 -0
  139. package/dist/lib/maths/fn/complex.d.ts +153 -0
  140. package/dist/lib/maths/fn/complex.d.ts.map +1 -0
  141. package/dist/lib/maths/fn/complex.js +383 -0
  142. package/dist/lib/maths/fn/complex.mjs +1 -0
  143. package/dist/lib/maths/fn/index.cjs +1 -0
  144. package/dist/lib/maths/fn/index.d.ts +10 -0
  145. package/dist/lib/maths/fn/index.d.ts.map +1 -0
  146. package/dist/lib/maths/fn/index.js +9 -0
  147. package/dist/lib/maths/fn/index.mjs +1 -0
  148. package/dist/lib/maths/fn/trigo.cjs +1 -0
  149. package/dist/lib/maths/fn/trigo.d.ts +147 -0
  150. package/dist/lib/maths/fn/trigo.d.ts.map +1 -0
  151. package/dist/lib/maths/fn/trigo.js +227 -0
  152. package/dist/lib/maths/fn/trigo.mjs +1 -0
  153. package/dist/lib/maths/fn/vector.cjs +1 -0
  154. package/dist/lib/maths/fn/vector.d.ts +512 -0
  155. package/dist/lib/maths/fn/vector.d.ts.map +1 -0
  156. package/dist/lib/maths/fn/vector.js +1136 -0
  157. package/dist/lib/maths/fn/vector.mjs +1 -0
  158. package/dist/lib/maths/formatter.cjs +1 -0
  159. package/dist/lib/maths/formatter.d.ts +35 -0
  160. package/dist/lib/maths/formatter.d.ts.map +1 -0
  161. package/dist/lib/maths/formatter.js +56 -0
  162. package/dist/lib/maths/formatter.mjs +1 -0
  163. package/dist/lib/maths/guards.cjs +1 -0
  164. package/dist/lib/maths/guards.d.ts +166 -0
  165. package/dist/lib/maths/guards.d.ts.map +1 -0
  166. package/dist/lib/maths/guards.js +315 -0
  167. package/dist/lib/maths/guards.mjs +1 -0
  168. package/dist/lib/maths/index.cjs +1 -0
  169. package/dist/lib/maths/index.d.ts +24 -0
  170. package/dist/lib/maths/index.d.ts.map +1 -0
  171. package/dist/lib/maths/index.js +29 -0
  172. package/dist/lib/maths/index.mjs +1 -0
  173. package/dist/lib/maths/parser.cjs +1 -0
  174. package/dist/lib/maths/parser.d.ts +20 -0
  175. package/dist/lib/maths/parser.d.ts.map +1 -0
  176. package/dist/lib/maths/parser.js +78 -0
  177. package/dist/lib/maths/parser.mjs +1 -0
  178. package/dist/lib/maths/random.cjs +1 -0
  179. package/dist/lib/maths/random.d.ts +27 -0
  180. package/dist/lib/maths/random.d.ts.map +1 -0
  181. package/dist/lib/maths/random.js +49 -0
  182. package/dist/lib/maths/random.mjs +1 -0
  183. package/dist/lib/maths/types/advanced.cjs +1 -0
  184. package/dist/lib/maths/types/advanced.d.ts +357 -0
  185. package/dist/lib/maths/types/advanced.d.ts.map +1 -0
  186. package/dist/lib/maths/types/advanced.js +5 -0
  187. package/dist/lib/maths/types/advanced.mjs +0 -0
  188. package/dist/lib/maths/types/basic.cjs +1 -0
  189. package/dist/lib/maths/types/basic.d.ts +95 -0
  190. package/dist/lib/maths/types/basic.d.ts.map +1 -0
  191. package/dist/lib/maths/types/basic.js +5 -0
  192. package/dist/lib/maths/types/basic.mjs +0 -0
  193. package/dist/lib/maths/types/index.cjs +1 -0
  194. package/dist/lib/maths/types/index.d.ts +4 -0
  195. package/dist/lib/maths/types/index.d.ts.map +1 -0
  196. package/dist/lib/maths/types/index.js +3 -0
  197. package/dist/lib/maths/types/index.mjs +0 -0
  198. package/dist/lib/maths/types/negative.cjs +1 -0
  199. package/dist/lib/maths/types/negative.d.ts +51 -0
  200. package/dist/lib/maths/types/negative.d.ts.map +1 -0
  201. package/dist/lib/maths/types/negative.js +5 -0
  202. package/dist/lib/maths/types/negative.mjs +0 -0
  203. package/dist/lib/maths/types/operations.cjs +1 -0
  204. package/dist/lib/maths/types/operations.d.ts +188 -0
  205. package/dist/lib/maths/types/operations.d.ts.map +1 -0
  206. package/dist/lib/maths/types/operations.js +6 -0
  207. package/dist/lib/maths/types/operations.mjs +0 -0
  208. package/dist/lib/object/clone.cjs +1 -0
  209. package/dist/lib/object/clone.d.ts +46 -0
  210. package/dist/lib/object/clone.d.ts.map +1 -0
  211. package/dist/lib/object/clone.js +104 -0
  212. package/dist/lib/object/clone.mjs +1 -0
  213. package/dist/lib/object/diff.cjs +1 -0
  214. package/dist/lib/object/diff.d.ts +203 -0
  215. package/dist/lib/object/diff.d.ts.map +1 -0
  216. package/dist/lib/object/diff.js +805 -0
  217. package/dist/lib/object/diff.mjs +1 -0
  218. package/dist/lib/object/getter-setter.cjs +1 -0
  219. package/dist/lib/object/getter-setter.d.ts +361 -0
  220. package/dist/lib/object/getter-setter.d.ts.map +1 -0
  221. package/dist/lib/object/getter-setter.js +1771 -0
  222. package/dist/lib/object/getter-setter.mjs +1 -0
  223. package/dist/lib/object/index.cjs +6 -0
  224. package/dist/lib/object/index.d.ts +13 -0
  225. package/dist/lib/object/index.d.ts.map +1 -0
  226. package/dist/lib/object/index.js +12 -0
  227. package/dist/lib/object/index.mjs +6 -0
  228. package/dist/lib/object/merge.cjs +1 -0
  229. package/dist/lib/object/merge.d.ts +93 -0
  230. package/dist/lib/object/merge.d.ts.map +1 -0
  231. package/dist/lib/object/merge.js +474 -0
  232. package/dist/lib/object/merge.mjs +1 -0
  233. package/dist/lib/object/object.cjs +1 -0
  234. package/dist/lib/object/object.d.ts +128 -0
  235. package/dist/lib/object/object.d.ts.map +1 -0
  236. package/dist/lib/object/object.js +432 -0
  237. package/dist/lib/object/object.mjs +1 -0
  238. package/dist/lib/object/omit.cjs +1 -0
  239. package/dist/lib/object/omit.d.ts +351 -0
  240. package/dist/lib/object/omit.d.ts.map +1 -0
  241. package/dist/lib/object/omit.js +656 -0
  242. package/dist/lib/object/omit.mjs +1 -0
  243. package/dist/lib/object/reconcile.cjs +1 -0
  244. package/dist/lib/object/reconcile.d.ts +7 -0
  245. package/dist/lib/object/reconcile.d.ts.map +1 -0
  246. package/dist/lib/object/reconcile.js +122 -0
  247. package/dist/lib/object/reconcile.mjs +1 -0
  248. package/dist/lib/object/selector.cjs +1 -0
  249. package/dist/lib/object/selector.d.ts +50 -0
  250. package/dist/lib/object/selector.d.ts.map +1 -0
  251. package/dist/lib/object/selector.js +371 -0
  252. package/dist/lib/object/selector.mjs +1 -0
  253. package/dist/lib/object/sort.cjs +1 -0
  254. package/dist/lib/object/sort.d.ts +149 -0
  255. package/dist/lib/object/sort.d.ts.map +1 -0
  256. package/dist/lib/object/sort.js +298 -0
  257. package/dist/lib/object/sort.mjs +1 -0
  258. package/dist/lib/object/transform.cjs +1 -0
  259. package/dist/lib/object/transform.d.ts +620 -0
  260. package/dist/lib/object/transform.d.ts.map +1 -0
  261. package/dist/lib/object/transform.js +1058 -0
  262. package/dist/lib/object/transform.mjs +1 -0
  263. package/dist/lib/object/types.cjs +1 -0
  264. package/dist/lib/object/types.d.ts +250 -0
  265. package/dist/lib/object/types.d.ts.map +1 -0
  266. package/dist/lib/object/types.js +1 -0
  267. package/dist/lib/object/types.mjs +0 -0
  268. package/dist/lib/object/utils.cjs +6 -0
  269. package/dist/lib/object/utils.d.ts +165 -0
  270. package/dist/lib/object/utils.d.ts.map +1 -0
  271. package/dist/lib/object/utils.js +444 -0
  272. package/dist/lib/object/utils.mjs +6 -0
  273. package/dist/lib/primitive/boolean/boolean.cjs +1 -0
  274. package/dist/lib/primitive/boolean/boolean.d.ts +276 -0
  275. package/dist/lib/primitive/boolean/boolean.d.ts.map +1 -0
  276. package/dist/lib/primitive/boolean/boolean.js +615 -0
  277. package/dist/lib/primitive/boolean/boolean.mjs +1 -0
  278. package/dist/lib/primitive/boolean/index.cjs +1 -0
  279. package/dist/lib/primitive/boolean/index.d.ts +3 -0
  280. package/dist/lib/primitive/boolean/index.d.ts.map +1 -0
  281. package/dist/lib/primitive/boolean/index.js +2 -0
  282. package/dist/lib/primitive/boolean/index.mjs +1 -0
  283. package/dist/lib/primitive/boolean/types.cjs +1 -0
  284. package/dist/lib/primitive/boolean/types.d.ts +14 -0
  285. package/dist/lib/primitive/boolean/types.d.ts.map +1 -0
  286. package/dist/lib/primitive/boolean/types.js +1 -0
  287. package/dist/lib/primitive/boolean/types.mjs +0 -0
  288. package/dist/lib/primitive/date/date.cjs +1 -0
  289. package/dist/lib/primitive/date/date.d.ts +641 -0
  290. package/dist/lib/primitive/date/date.d.ts.map +1 -0
  291. package/dist/lib/primitive/date/date.js +1998 -0
  292. package/dist/lib/primitive/date/date.mjs +1 -0
  293. package/dist/lib/primitive/date/index.cjs +1 -0
  294. package/dist/lib/primitive/date/index.d.ts +3 -0
  295. package/dist/lib/primitive/date/index.d.ts.map +1 -0
  296. package/dist/lib/primitive/date/index.js +2 -0
  297. package/dist/lib/primitive/date/index.mjs +1 -0
  298. package/dist/lib/primitive/date/types.cjs +1 -0
  299. package/dist/lib/primitive/date/types.d.ts +205 -0
  300. package/dist/lib/primitive/date/types.d.ts.map +1 -0
  301. package/dist/lib/primitive/date/types.js +7 -0
  302. package/dist/lib/primitive/date/types.mjs +0 -0
  303. package/dist/lib/primitive/index.cjs +5 -0
  304. package/dist/lib/primitive/index.d.ts +5 -0
  305. package/dist/lib/primitive/index.d.ts.map +1 -0
  306. package/dist/lib/primitive/index.js +4 -0
  307. package/dist/lib/primitive/index.mjs +5 -0
  308. package/dist/lib/primitive/string/index.cjs +5 -0
  309. package/dist/lib/primitive/string/index.d.ts +3 -0
  310. package/dist/lib/primitive/string/index.d.ts.map +1 -0
  311. package/dist/lib/primitive/string/index.js +2 -0
  312. package/dist/lib/primitive/string/index.mjs +5 -0
  313. package/dist/lib/primitive/string/parser-2.cjs +8 -0
  314. package/dist/lib/primitive/string/parser-2.d.ts +17 -0
  315. package/dist/lib/primitive/string/parser-2.d.ts.map +1 -0
  316. package/dist/lib/primitive/string/parser-2.js +656 -0
  317. package/dist/lib/primitive/string/parser-2.mjs +8 -0
  318. package/dist/lib/primitive/string/parser.cjs +3 -0
  319. package/dist/lib/primitive/string/parser.d.ts +9 -0
  320. package/dist/lib/primitive/string/parser.d.ts.map +1 -0
  321. package/dist/lib/primitive/string/parser.js +775 -0
  322. package/dist/lib/primitive/string/parser.mjs +3 -0
  323. package/dist/lib/primitive/string/string.cjs +5 -0
  324. package/dist/lib/primitive/string/string.d.ts +535 -0
  325. package/dist/lib/primitive/string/string.d.ts.map +1 -0
  326. package/dist/lib/primitive/string/string.js +1301 -0
  327. package/dist/lib/primitive/string/string.mjs +5 -0
  328. package/dist/lib/primitive/string/types.cjs +1 -0
  329. package/dist/lib/primitive/string/types.d.ts +318 -0
  330. package/dist/lib/primitive/string/types.d.ts.map +1 -0
  331. package/dist/lib/primitive/string/types.js +5 -0
  332. package/dist/lib/primitive/string/types.mjs +0 -0
  333. package/dist/lib/primitive/types.cjs +1 -0
  334. package/dist/lib/primitive/types.d.ts +27 -0
  335. package/dist/lib/primitive/types.d.ts.map +1 -0
  336. package/dist/lib/primitive/types.js +1 -0
  337. package/dist/lib/primitive/types.mjs +0 -0
  338. package/dist/lib/url/index.cjs +1 -0
  339. package/dist/lib/url/index.d.ts +3 -0
  340. package/dist/lib/url/index.d.ts.map +1 -0
  341. package/dist/lib/url/index.js +2 -0
  342. package/dist/lib/url/index.mjs +1 -0
  343. package/dist/lib/url/parser.cjs +1 -0
  344. package/dist/lib/url/parser.d.ts +216 -0
  345. package/dist/lib/url/parser.d.ts.map +1 -0
  346. package/dist/lib/url/parser.js +488 -0
  347. package/dist/lib/url/parser.mjs +1 -0
  348. package/dist/lib/url/types.cjs +1 -0
  349. package/dist/lib/url/types.d.ts +18 -0
  350. package/dist/lib/url/types.d.ts.map +1 -0
  351. package/dist/lib/url/types.js +1 -0
  352. package/dist/lib/url/types.mjs +0 -0
  353. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  354. package/package.json +150 -0
@@ -0,0 +1,383 @@
1
+ /**
2
+ * Complex number operations.
3
+ * @module ComplexFunctions
4
+ */
5
+ // Constants
6
+ const EPSILON = 1e-10;
7
+ const TWO_PI = 2 * Math.PI;
8
+ /**
9
+ * Checks if a value is approximately zero within epsilon.
10
+ * @param value - The value to check
11
+ * @returns True if the value is effectively zero
12
+ */
13
+ function isApproximatelyZero(value) {
14
+ return Math.abs(value) < EPSILON;
15
+ }
16
+ /**
17
+ * Safely compares two numbers with epsilon precision.
18
+ * @param a - First number
19
+ * @param b - Second number
20
+ * @returns True if numbers are approximately equal
21
+ */
22
+ function approximatelyEqual(a, b) {
23
+ return Math.abs(a - b) < EPSILON;
24
+ }
25
+ /**
26
+ * Normalizes a complex number by handling near-zero values.
27
+ * @param c - The complex number to normalize
28
+ * @returns Normalized complex number
29
+ */
30
+ function normalizeComplex(c) {
31
+ return {
32
+ real: isApproximatelyZero(c.real) ? 0 : c.real,
33
+ imag: isApproximatelyZero(c.imag) ? 0 : c.imag,
34
+ };
35
+ }
36
+ /**
37
+ * Validates that a value is a finite number.
38
+ * @param value - The value to validate
39
+ * @param name - Name of the value for error messages
40
+ * @throws {Error} If value is not a finite number
41
+ */
42
+ function validateNumber(value, name) {
43
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
44
+ throw new Error(`${name} must be a finite number, got ${value}`);
45
+ }
46
+ }
47
+ /**
48
+ * Validates a complex number.
49
+ * @param c - The complex number to validate
50
+ * @param name - Name of the complex number for error messages
51
+ * @throws {Error} If complex number is invalid
52
+ */
53
+ function validateComplexNumber(c, name = 'Complex number') {
54
+ if (!c || typeof c !== 'object') {
55
+ throw new Error(`${name} must be an object`);
56
+ }
57
+ validateNumber(c.real, `${name}.real`);
58
+ validateNumber(c.imag, `${name}.imag`);
59
+ }
60
+ /**
61
+ * Creates a complex number with validation and normalization.
62
+ * @param real - Real part
63
+ * @param imag - Imaginary part
64
+ * @returns Validated and normalized complex number
65
+ */
66
+ export function createComplex(real, imag = 0) {
67
+ validateNumber(real, 'real');
68
+ validateNumber(imag, 'imag');
69
+ return normalizeComplex({ real, imag });
70
+ }
71
+ /**
72
+ * Checks if two complex numbers are approximately equal.
73
+ * @param a - First complex number
74
+ * @param b - Second complex number
75
+ * @returns True if numbers are approximately equal
76
+ */
77
+ export function complexEquals(a, b) {
78
+ validateComplexNumber(a, 'First complex number');
79
+ validateComplexNumber(b, 'Second complex number');
80
+ return (approximatelyEqual(a.real, b.real) && approximatelyEqual(a.imag, b.imag));
81
+ }
82
+ /**
83
+ * Adds two complex numbers.
84
+ * @param a - First complex number
85
+ * @param b - Second complex number
86
+ * @returns The sum as a complex number
87
+ */
88
+ export function addComplex(a, b) {
89
+ validateComplexNumber(a, 'First complex number');
90
+ validateComplexNumber(b, 'Second complex number');
91
+ return normalizeComplex({
92
+ real: a.real + b.real,
93
+ imag: a.imag + b.imag,
94
+ });
95
+ }
96
+ /**
97
+ * Subtracts two complex numbers.
98
+ * @param a - First complex number
99
+ * @param b - Second complex number
100
+ * @returns The difference as a complex number (a - b)
101
+ */
102
+ export function subtractComplex(a, b) {
103
+ validateComplexNumber(a, 'First complex number');
104
+ validateComplexNumber(b, 'Second complex number');
105
+ return normalizeComplex({
106
+ real: a.real - b.real,
107
+ imag: a.imag - b.imag,
108
+ });
109
+ }
110
+ /**
111
+ * Multiplies two complex numbers.
112
+ * @param a - First complex number
113
+ * @param b - Second complex number
114
+ * @returns The product as a complex number
115
+ */
116
+ export function multiplyComplex(a, b) {
117
+ validateComplexNumber(a, 'First complex number');
118
+ validateComplexNumber(b, 'Second complex number');
119
+ return normalizeComplex({
120
+ real: a.real * b.real - a.imag * b.imag,
121
+ imag: a.real * b.imag + a.imag * b.real,
122
+ });
123
+ }
124
+ /**
125
+ * Divides two complex numbers.
126
+ * @param a - Numerator complex number
127
+ * @param b - Denominator complex number
128
+ * @returns The quotient as a complex number
129
+ * @throws {Error} If dividing by zero or near-zero complex number
130
+ */
131
+ export function divideComplex(a, b) {
132
+ validateComplexNumber(a, 'Numerator complex number');
133
+ validateComplexNumber(b, 'Denominator complex number');
134
+ const denominator = b.real * b.real + b.imag * b.imag;
135
+ if (isApproximatelyZero(denominator)) {
136
+ throw new Error('Cannot divide by zero or near-zero complex number');
137
+ }
138
+ return normalizeComplex({
139
+ real: (a.real * b.real + a.imag * b.imag) / denominator,
140
+ imag: (a.imag * b.real - a.real * b.imag) / denominator,
141
+ });
142
+ }
143
+ /**
144
+ * Calculates the magnitude (absolute value) of a complex number.
145
+ * @param c - The complex number
146
+ * @returns The magnitude (non-negative)
147
+ */
148
+ export function magnitudeComplex(c) {
149
+ validateComplexNumber(c);
150
+ const magnitude = Math.sqrt(c.real * c.real + c.imag * c.imag);
151
+ return isApproximatelyZero(magnitude) ? 0 : magnitude;
152
+ }
153
+ /**
154
+ * Calculates the conjugate of a complex number.
155
+ * @param c - The complex number
156
+ * @returns The complex conjugate
157
+ */
158
+ export function conjugateComplex(c) {
159
+ validateComplexNumber(c);
160
+ return normalizeComplex({
161
+ real: c.real,
162
+ imag: -c.imag,
163
+ });
164
+ }
165
+ /**
166
+ * Calculates the argument (angle) of a complex number in radians.
167
+ * @param c - The complex number
168
+ * @returns The principal argument in radians (-π, π]
169
+ */
170
+ export function argumentComplex(c) {
171
+ validateComplexNumber(c);
172
+ if (isApproximatelyZero(c.real) && isApproximatelyZero(c.imag)) {
173
+ return 0; // Argument of zero is conventionally 0
174
+ }
175
+ return Math.atan2(c.imag, c.real);
176
+ }
177
+ /**
178
+ * Converts a complex number to polar form.
179
+ * @param c - The complex number
180
+ * @returns Polar representation {magnitude, angle}
181
+ */
182
+ export function toPolarComplex(c) {
183
+ validateComplexNumber(c);
184
+ return {
185
+ magnitude: magnitudeComplex(c),
186
+ angle: argumentComplex(c),
187
+ };
188
+ }
189
+ /**
190
+ * Converts polar form to a complex number.
191
+ * @param magnitude - The magnitude (must be non-negative)
192
+ * @param angle - The angle in radians
193
+ * @returns The complex number
194
+ * @throws {Error} If magnitude is negative
195
+ */
196
+ export function fromPolarComplex(magnitude, angle) {
197
+ validateNumber(magnitude, 'magnitude');
198
+ validateNumber(angle, 'angle');
199
+ if (magnitude < -EPSILON) {
200
+ throw new Error('Magnitude must be non-negative');
201
+ }
202
+ // Normalize angle to (-π, π]
203
+ let normalizedAngle = angle % TWO_PI;
204
+ if (normalizedAngle > Math.PI)
205
+ normalizedAngle -= TWO_PI;
206
+ if (normalizedAngle <= -Math.PI)
207
+ normalizedAngle += TWO_PI;
208
+ const mag = Math.max(0, magnitude); // Ensure non-negative
209
+ return normalizeComplex({
210
+ real: mag * Math.cos(normalizedAngle),
211
+ imag: mag * Math.sin(normalizedAngle),
212
+ });
213
+ }
214
+ /**
215
+ * Calculates the square root of a complex number.
216
+ * @param c - The complex number
217
+ * @returns Array of two complex square roots (principal and secondary)
218
+ */
219
+ export function sqrtComplex(c) {
220
+ validateComplexNumber(c);
221
+ // Special case for zero
222
+ if (isApproximatelyZero(c.real) && isApproximatelyZero(c.imag)) {
223
+ const zero = createComplex(0, 0);
224
+ return [zero, zero];
225
+ }
226
+ const magnitude = magnitudeComplex(c);
227
+ const angle = argumentComplex(c);
228
+ const rootMagnitude = Math.sqrt(magnitude);
229
+ const rootAngle1 = angle / 2;
230
+ const rootAngle2 = rootAngle1 + Math.PI;
231
+ return [
232
+ fromPolarComplex(rootMagnitude, rootAngle1),
233
+ fromPolarComplex(rootMagnitude, rootAngle2),
234
+ ];
235
+ }
236
+ /**
237
+ * Calculates the power of a complex number with a real exponent.
238
+ * @param c - The complex number
239
+ * @param exponent - The exponent (real number)
240
+ * @returns The complex number raised to the power
241
+ */
242
+ export function powerComplex(c, exponent) {
243
+ validateComplexNumber(c);
244
+ validateNumber(exponent, 'exponent');
245
+ // Special cases for optimization
246
+ if (isApproximatelyZero(exponent)) {
247
+ return createComplex(1, 0); // c^0 = 1
248
+ }
249
+ if (approximatelyEqual(exponent, 1)) {
250
+ return createComplex(c.real, c.imag); // c^1 = c
251
+ }
252
+ if (approximatelyEqual(exponent, 2)) {
253
+ // Square directly for better performance
254
+ return multiplyComplex(c, c);
255
+ }
256
+ if (isApproximatelyZero(c.real) && isApproximatelyZero(c.imag)) {
257
+ if (exponent > 0) {
258
+ return createComplex(0, 0); // 0^n = 0 for n > 0
259
+ }
260
+ else if (exponent < 0) {
261
+ throw new Error('Cannot raise zero to a negative power');
262
+ }
263
+ }
264
+ const polar = toPolarComplex(c);
265
+ const magnitude = Math.pow(polar.magnitude, exponent);
266
+ // Handle negative magnitude due to floating point errors
267
+ const safeMagnitude = magnitude < -EPSILON ? Math.abs(magnitude) : Math.max(0, magnitude);
268
+ const angle = polar.angle * exponent;
269
+ return fromPolarComplex(safeMagnitude, angle);
270
+ }
271
+ /**
272
+ * Calculates the natural logarithm of a complex number.
273
+ * @param c - The complex number
274
+ * @returns The principal value of natural logarithm as a complex number
275
+ * @throws {Error} If the complex number is zero or near-zero
276
+ */
277
+ export function lnComplex(c) {
278
+ validateComplexNumber(c);
279
+ const magnitude = magnitudeComplex(c);
280
+ if (isApproximatelyZero(magnitude)) {
281
+ throw new Error('Cannot take logarithm of zero or near-zero complex number');
282
+ }
283
+ const angle = argumentComplex(c);
284
+ return normalizeComplex({
285
+ real: Math.log(magnitude),
286
+ imag: angle,
287
+ });
288
+ }
289
+ /**
290
+ * Calculates the exponential of a complex number.
291
+ * @param c - The complex number
292
+ * @returns The exponential as a complex number
293
+ */
294
+ export function expComplex(c) {
295
+ validateComplexNumber(c);
296
+ const expReal = Math.exp(c.real);
297
+ return normalizeComplex({
298
+ real: expReal * Math.cos(c.imag),
299
+ imag: expReal * Math.sin(c.imag),
300
+ });
301
+ }
302
+ /**
303
+ * Calculates the sine of a complex number.
304
+ * @param c - The complex number
305
+ * @returns The sine as a complex number
306
+ */
307
+ export function sinComplex(c) {
308
+ validateComplexNumber(c);
309
+ // sin(a + bi) = sin(a)cosh(b) + i cos(a)sinh(b)
310
+ return normalizeComplex({
311
+ real: Math.sin(c.real) * Math.cosh(c.imag),
312
+ imag: Math.cos(c.real) * Math.sinh(c.imag),
313
+ });
314
+ }
315
+ /**
316
+ * Calculates the cosine of a complex number.
317
+ * @param c - The complex number
318
+ * @returns The cosine as a complex number
319
+ */
320
+ export function cosComplex(c) {
321
+ validateComplexNumber(c);
322
+ // cos(a + bi) = cos(a)cosh(b) - i sin(a)sinh(b)
323
+ return normalizeComplex({
324
+ real: Math.cos(c.real) * Math.cosh(c.imag),
325
+ imag: -Math.sin(c.real) * Math.sinh(c.imag),
326
+ });
327
+ }
328
+ /**
329
+ * Checks if a complex number is zero (or effectively zero).
330
+ * @param c - The complex number to check
331
+ * @returns True if the complex number is effectively zero
332
+ */
333
+ export function isZeroComplex(c) {
334
+ validateComplexNumber(c);
335
+ return isApproximatelyZero(c.real) && isApproximatelyZero(c.imag);
336
+ }
337
+ /**
338
+ * Returns the real part of a complex number.
339
+ * @param c - The complex number
340
+ * @returns The real part
341
+ */
342
+ export function getReal(c) {
343
+ validateComplexNumber(c);
344
+ return c.real;
345
+ }
346
+ /**
347
+ * Returns the imaginary part of a complex number.
348
+ * @param c - The complex number
349
+ * @returns The imaginary part
350
+ */
351
+ export function getImag(c) {
352
+ validateComplexNumber(c);
353
+ return c.imag;
354
+ }
355
+ /**
356
+ * Negates a complex number.
357
+ * @param c - The complex number
358
+ * @returns The negated complex number
359
+ */
360
+ export function negateComplex(c) {
361
+ validateComplexNumber(c);
362
+ return normalizeComplex({
363
+ real: -c.real,
364
+ imag: -c.imag,
365
+ });
366
+ }
367
+ /**
368
+ * Calculates the reciprocal of a complex number.
369
+ * @param c - The complex number
370
+ * @returns The reciprocal (1/c)
371
+ * @throws {Error} If the complex number is zero or near-zero
372
+ */
373
+ export function reciprocalComplex(c) {
374
+ validateComplexNumber(c);
375
+ const denominator = c.real * c.real + c.imag * c.imag;
376
+ if (isApproximatelyZero(denominator)) {
377
+ throw new Error('Cannot calculate reciprocal of zero or near-zero complex number');
378
+ }
379
+ return normalizeComplex({
380
+ real: c.real / denominator,
381
+ imag: -c.imag / denominator,
382
+ });
383
+ }
@@ -0,0 +1 @@
1
+ var g=2*Math.PI;function n(e){return Math.abs(e)<1e-10}function p(e,r){return Math.abs(e-r)<1e-10}function t(e){return{real:n(e.real)?0:e.real,imag:n(e.imag)?0:e.imag}}function l(e,r){if(typeof e!="number"||!Number.isFinite(e))throw new Error(`${r} must be a finite number, got ${e}`)}function m(e,r="Complex number"){if(!e||typeof e!="object")throw new Error(`${r} must be an object`);l(e.real,`${r}.real`),l(e.imag,`${r}.imag`)}function i(e,r=0){return l(e,"real"),l(r,"imag"),t({real:e,imag:r})}function M(e,r){return m(e,"First complex number"),m(r,"Second complex number"),p(e.real,r.real)&&p(e.imag,r.imag)}function c(e,r){return m(e,"First complex number"),m(r,"Second complex number"),t({real:e.real+r.real,imag:e.imag+r.imag})}function d(e,r){return m(e,"First complex number"),m(r,"Second complex number"),t({real:e.real-r.real,imag:e.imag-r.imag})}function f(e,r){return m(e,"First complex number"),m(r,"Second complex number"),t({real:e.real*r.real-e.imag*r.imag,imag:e.real*r.imag+e.imag*r.real})}function w(e,r){m(e,"Numerator complex number"),m(r,"Denominator complex number");let o=r.real*r.real+r.imag*r.imag;if(n(o))throw new Error("Cannot divide by zero or near-zero complex number");return t({real:(e.real*r.real+e.imag*r.imag)/o,imag:(e.imag*r.real-e.real*r.imag)/o})}function C(e){m(e);let r=Math.sqrt(e.real*e.real+e.imag*e.imag);return n(r)?0:r}function E(e){return m(e),t({real:e.real,imag:-e.imag})}function s(e){return m(e),n(e.real)&&n(e.imag)?0:Math.atan2(e.imag,e.real)}function h(e){return m(e),{magnitude:C(e),angle:s(e)}}function b(e,r){if(l(e,"magnitude"),l(r,"angle"),e<-1e-10)throw new Error("Magnitude must be non-negative");let o=r%g;o>Math.PI&&(o-=g),o<=-Math.PI&&(o+=g);let a=Math.max(0,e);return t({real:a*Math.cos(o),imag:a*Math.sin(o)})}function P(e){if(m(e),n(e.real)&&n(e.imag)){let N=i(0,0);return[N,N]}let r=C(e),o=s(e),a=Math.sqrt(r),u=o/2,x=u+Math.PI;return[b(a,u),b(a,x)]}function I(e,r){if(m(e),l(r,"exponent"),n(r))return i(1,0);if(p(r,1))return i(e.real,e.imag);if(p(r,2))return f(e,e);if(n(e.real)&&n(e.imag)){if(r>0)return i(0,0);if(r<0)throw new Error("Cannot raise zero to a negative power")}let o=h(e),a=Math.pow(o.magnitude,r),u=a<-1e-10?Math.abs(a):Math.max(0,a),x=o.angle*r;return b(u,x)}function z(e){m(e);let r=C(e);if(n(r))throw new Error("Cannot take logarithm of zero or near-zero complex number");let o=s(e);return t({real:Math.log(r),imag:o})}function S(e){m(e);let r=Math.exp(e.real);return t({real:r*Math.cos(e.imag),imag:r*Math.sin(e.imag)})}function y(e){return m(e),t({real:Math.sin(e.real)*Math.cosh(e.imag),imag:Math.cos(e.real)*Math.sinh(e.imag)})}function v(e){return m(e),t({real:Math.cos(e.real)*Math.cosh(e.imag),imag:-Math.sin(e.real)*Math.sinh(e.imag)})}function O(e){return m(e),n(e.real)&&n(e.imag)}function q(e){return m(e),e.real}function F(e){return m(e),e.imag}function L(e){return m(e),t({real:-e.real,imag:-e.imag})}function $(e){m(e);let r=e.real*e.real+e.imag*e.imag;if(n(r))throw new Error("Cannot calculate reciprocal of zero or near-zero complex number");return t({real:e.real/r,imag:-e.imag/r})}export{c as addComplex,s as argumentComplex,M as complexEquals,E as conjugateComplex,v as cosComplex,i as createComplex,w as divideComplex,S as expComplex,b as fromPolarComplex,F as getImag,q as getReal,O as isZeroComplex,z as lnComplex,C as magnitudeComplex,f as multiplyComplex,L as negateComplex,I as powerComplex,$ as reciprocalComplex,y as sinComplex,P as sqrtComplex,d as subtractComplex,h as toPolarComplex};
@@ -0,0 +1 @@
1
+ "use strict";var S=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var pe=(r,e)=>{for(var n in e)S(r,n,{get:e[n],enumerable:!0})},le=(r,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of se(e))!xe.call(r,o)&&o!==n&&S(r,o,{get:()=>e[o],enumerable:!(t=ae(e,o))||t.enumerable});return r};var fe=r=>le(S({},"__esModule",{value:!0}),r);var Fe={};pe(Fe,{abs:()=>O,acos:()=>Jr,acosh:()=>oe,add:()=>_,addComplex:()=>Pr,addFractions:()=>xr,addVectors2D:()=>Cr,angleBetween2D:()=>Sr,argumentComplex:()=>w,asin:()=>Wr,asinh:()=>te,atan:()=>Kr,atan2:()=>vr,atanh:()=>ue,average:()=>K,cbrt:()=>cr,ceil:()=>k,clamp:()=>M,conjugateComplex:()=>Lr,cos:()=>Hr,cosh:()=>ee,cot:()=>me,crossProduct3D:()=>Mr,csc:()=>ce,degToGrad:()=>kr,degToRad:()=>Br,distance2D:()=>Rr,distance3D:()=>Fr,divide:()=>$,divideComplex:()=>_r,dotProduct2D:()=>T,dotProduct3D:()=>zr,evaluatePolynomial:()=>sr,exp:()=>ir,factorial:()=>Y,floor:()=>Q,fromPolarComplex:()=>g,gcd:()=>h,gradToDeg:()=>Qr,invLerp:()=>F,lcm:()=>H,lerp:()=>R,lerp2D:()=>Ir,ln:()=>nr,lnComplex:()=>Gr,log:()=>ur,log10:()=>tr,log2:()=>or,magnitude2D:()=>y,magnitude3D:()=>I,magnitude4D:()=>gr,magnitudeComplex:()=>V,mapRange:()=>U,max:()=>J,median:()=>rr,min:()=>W,modulo:()=>j,multiplyComplex:()=>P,multiplyFractions:()=>pr,normalize:()=>hr,normalize2D:()=>Vr,normalize3D:()=>wr,normalizeDegrees:()=>Xr,normalizeRadians:()=>Zr,nthRoot:()=>mr,percentage:()=>lr,power:()=>G,powerComplex:()=>jr,product:()=>er,radToDeg:()=>Or,range:()=>br,rotate2D:()=>Tr,round:()=>b,scaleVector2D:()=>Nr,sec:()=>ie,sign:()=>X,simplifyFraction:()=>C,sin:()=>Yr,sinh:()=>re,solveQuadratic:()=>ar,sqrt:()=>B,sqrtComplex:()=>$r,subtract:()=>L,subtractComplex:()=>qr,subtractVectors2D:()=>Er,sum:()=>v,tan:()=>Ur,tanh:()=>ne,toBase:()=>fr,toOrdinal:()=>Dr,toPolarComplex:()=>q,trunc:()=>Z,truncateDecimals:()=>dr,wrap:()=>yr});module.exports=fe(Fe);function _(r,e){return r+e}function L(r,e){return r-e}var $=(r,e,n)=>e===0?n!==void 0?n:NaN:r/e;function j(r,e){return r%e}function G(r,e){return Math.pow(r,e)}function B(r){if(r<0)throw new Error("Cannot calculate square root of negative number");return Math.sqrt(r)}function O(r){return Math.abs(r)}var b=(r,e=0,n="round")=>{if(n==="david")return De(r,e,n);if(!Number.isFinite(r))return r;if(e===0)return Math[n](r);if(e<0){let z=10**-e;return Math[n](r/z)*z}let t=10**e,o=Math.pow(2,-52),u=r*t,s=Math.sign(u)*o*Math.abs(u),l;switch(n){case"round":l=Math.round(u+s);break;case"ceil":l=Math.ceil(u-o);break;case"floor":l=Math.floor(u+o);break;case"trunc":l=u<0?Math.ceil(u):Math.floor(u);break;default:l=Math.round(u+s)}return l/t},De=(r,e=0,n="round")=>{let t=Math.abs(r),o=r<0?-1:1;if(e===0)return Math.round(t)*o;if(!Number.isFinite(t))return t*o;let u=10**e,s=t*u,l=Math.pow(2,-53),z=Math.sign(s)*l*Math.abs(s);return s+=z,Math.round(s)/u*o},k=(r,e=0)=>b(r,e,"ceil"),Q=(r,e=0)=>b(r,e,"floor"),Z=(r,e=0)=>b(r,e,"trunc"),M=(r,e,n)=>(e>n&&([e,n]=[n,e]),r<e?e:r>n?n:r);function X(r){return r>0?1:r<0?-1:0}function Y(r){if(!Number.isInteger(r)||r<0)throw new Error("Factorial is only defined for non-negative integers");if(r===0||r===1)return 1;let e=1;for(let n=2;n<=r;n++)e*=n;return e}function h(r,e){for(r=Math.abs(r),e=Math.abs(e);e!==0;){let n=e;e=r%e,r=n}return r}function H(r,e){return Math.abs(r*e)/h(r,e)}function R(r,e,n){return r+(e-r)*M(n,0,1)}var F=(r,e,n)=>M((n-r)/(e-r),0,1),U=(r,e,n,t,o)=>{let u=F(e,n,r);return R(t,o,u)};function W(...r){return Math.min(...r)}function J(...r){return Math.max(...r)}var K=(...r)=>{if(!Array.isArray(r)||r.length===0)return 0;let e=0,n=0;for(let t of r)Number.isFinite(t)&&(e+=t,n++);return n===0?0:e/n},v=(...r)=>Array.isArray(r)?r.reduce((e,n)=>e+(Number.isFinite(n)?n:0),0):0,rr=(...r)=>{if(!Array.isArray(r)||r.length===0)return 0;let e=r.filter(Number.isFinite);if(e.length===0)return 0;e.sort((t,o)=>t-o);let n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]};function er(...r){return r.reduce((e,n)=>e*n,1)}function nr(r){if(r<=0)throw new Error("Natural logarithm is only defined for positive numbers");return Math.log(r)}function tr(r){if(r<=0)throw new Error("Logarithm is only defined for positive numbers");return Math.log10(r)}function or(r){if(r<=0)throw new Error("Logarithm is only defined for positive numbers");return Math.log2(r)}function ur(r,e){if(r<=0||e<=0)throw new Error("Logarithm is only defined for positive numbers and bases");return Math.log(r)/Math.log(e)}function ir(r){return Math.exp(r)}function cr(r){return Math.cbrt(r)}function mr(r,e){if(e===0)throw new Error("Cannot calculate 0th root");if(r<0&&e%2===0)throw new Error("Cannot calculate even root of negative number");let n=1/e;return Math.sign(r)*Math.pow(Math.abs(r),n)}function ar(r,e,n){if(r===0)return e===0?[]:[-n/e];let t=e*e-4*r*n;if(t<0)return[];if(t===0)return[-e/(2*r)];{let o=Math.sqrt(t);return[(-e-o)/(2*r),(-e+o)/(2*r)]}}function sr(r,e){let n=0;for(let t=0;t<r.length;t++)n=n*e+r[t];return n}function C(r){let e=h(r.numerator,r.denominator);return{numerator:r.numerator/e,denominator:r.denominator/e}}function xr(r,e){let n=r.numerator*e.denominator+e.numerator*r.denominator,t=r.denominator*e.denominator;return C({numerator:n,denominator:t})}function pr(r,e){let n=r.numerator*e.numerator,t=r.denominator*e.denominator;return C({numerator:n,denominator:t})}var lr=(r,e,n=2)=>{if(e===0)return 0;let t=r/e*100;return b(t,n)},fr=(r,e,n=1)=>{if(e<2||e>36)throw new Error("Base must be between 2 and 36");return r.toString(e).padStart(n,"0")},Dr=r=>{let e=["th","st","nd","rd"],n=r%100;return r+(e[(n-20)%10]||e[n]||e[0])},br=(r,e,n=1)=>{let t=[];if(n===0)return t;if(n>0)for(let o=r;o<e;o+=n)t.push(o);else for(let o=r;o>e;o+=n)t.push(o);return t},dr=(r,e)=>{if(!Number.isFinite(r))return r;let n=10**e;return Math.trunc(r*n)/n},hr=(r,e,n)=>e===n?0:(r-e)/(n-e),yr=(r,e,n)=>{let t=n-e;return((r-e)%t+t)%t+e};function m(r,e){if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${e} must be a finite number, got ${r}`)}function p(r){return Math.abs(r)<1e-9}function i(r,e="Vector2D"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);m(r.x,`${e}.x`),m(r.y,`${e}.y`)}function f(r,e="Vector3D"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);m(r.x,`${e}.x`),m(r.y,`${e}.y`),m(r.z,`${e}.z`)}function be(r,e="Vector4D"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);m(r.x,`${e}.x`),m(r.y,`${e}.y`),m(r.z,`${e}.z`),m(r.w,`${e}.w`)}function y(r){i(r);let e=Math.sqrt(r.x*r.x+r.y*r.y);return p(e)?0:e}function I(r){f(r);let e=Math.sqrt(r.x*r.x+r.y*r.y+r.z*r.z);return p(e)?0:e}function gr(r){be(r);let e=Math.sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.w*r.w);return p(e)?0:e}function Vr(r){i(r);let e=y(r);if(p(e))throw new Error("Cannot normalize zero or near-zero vector");return{x:r.x/e,y:r.y/e}}function wr(r){f(r);let e=I(r);if(p(e))throw new Error("Cannot normalize zero or near-zero vector");return{x:r.x/e,y:r.y/e,z:r.z/e}}function T(r,e){return i(r,"First vector"),i(e,"Second vector"),r.x*e.x+r.y*e.y}function zr(r,e){return f(r,"First vector"),f(e,"Second vector"),r.x*e.x+r.y*e.y+r.z*e.z}function Mr(r,e){return f(r,"First vector"),f(e,"Second vector"),{x:r.y*e.z-r.z*e.y,y:r.z*e.x-r.x*e.z,z:r.x*e.y-r.y*e.x}}function Cr(r,e){return i(r,"First vector"),i(e,"Second vector"),{x:r.x+e.x,y:r.y+e.y}}function Er(r,e){return i(r,"First vector"),i(e,"Second vector"),{x:r.x-e.x,y:r.y-e.y}}function Nr(r,e){return i(r),m(e,"scalar"),{x:r.x*e,y:r.y*e}}function Sr(r,e){i(r,"First vector"),i(e,"Second vector");let n=T(r,e),t=y(r),o=y(e);if(p(t)||p(o))throw new Error("Cannot calculate angle with zero or near-zero vector");let u=Math.max(-1,Math.min(1,n/(t*o)));return Math.acos(u)}function Rr(r,e){i(r,"First point"),i(e,"Second point");let n=e.x-r.x,t=e.y-r.y,o=Math.sqrt(n*n+t*t);return p(o)?0:o}function Fr(r,e){f(r,"First point"),f(e,"Second point");let n=e.x-r.x,t=e.y-r.y,o=e.z-r.z,u=Math.sqrt(n*n+t*t+o*o);return p(u)?0:u}function Ir(r,e,n){return i(r,"Start vector"),i(e,"End vector"),m(n,"t"),{x:r.x+(e.x-r.x)*n,y:r.y+(e.y-r.y)*n}}function Tr(r,e){i(r),m(e,"angle");let n=Math.cos(e),t=Math.sin(e);return{x:r.x*n-r.y*t,y:r.x*t+r.y*n}}var A=2*Math.PI;function a(r){return Math.abs(r)<1e-10}function Ar(r,e){return Math.abs(r-e)<1e-10}function D(r){return{real:a(r.real)?0:r.real,imag:a(r.imag)?0:r.imag}}function d(r,e){if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${e} must be a finite number, got ${r}`)}function c(r,e="Complex number"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);d(r.real,`${e}.real`),d(r.imag,`${e}.imag`)}function E(r,e=0){return d(r,"real"),d(e,"imag"),D({real:r,imag:e})}function Pr(r,e){return c(r,"First complex number"),c(e,"Second complex number"),D({real:r.real+e.real,imag:r.imag+e.imag})}function qr(r,e){return c(r,"First complex number"),c(e,"Second complex number"),D({real:r.real-e.real,imag:r.imag-e.imag})}function P(r,e){return c(r,"First complex number"),c(e,"Second complex number"),D({real:r.real*e.real-r.imag*e.imag,imag:r.real*e.imag+r.imag*e.real})}function _r(r,e){c(r,"Numerator complex number"),c(e,"Denominator complex number");let n=e.real*e.real+e.imag*e.imag;if(a(n))throw new Error("Cannot divide by zero or near-zero complex number");return D({real:(r.real*e.real+r.imag*e.imag)/n,imag:(r.imag*e.real-r.real*e.imag)/n})}function V(r){c(r);let e=Math.sqrt(r.real*r.real+r.imag*r.imag);return a(e)?0:e}function Lr(r){return c(r),D({real:r.real,imag:-r.imag})}function w(r){return c(r),a(r.real)&&a(r.imag)?0:Math.atan2(r.imag,r.real)}function q(r){return c(r),{magnitude:V(r),angle:w(r)}}function g(r,e){if(d(r,"magnitude"),d(e,"angle"),r<-1e-10)throw new Error("Magnitude must be non-negative");let n=e%A;n>Math.PI&&(n-=A),n<=-Math.PI&&(n+=A);let t=Math.max(0,r);return D({real:t*Math.cos(n),imag:t*Math.sin(n)})}function $r(r){if(c(r),a(r.real)&&a(r.imag)){let s=E(0,0);return[s,s]}let e=V(r),n=w(r),t=Math.sqrt(e),o=n/2,u=o+Math.PI;return[g(t,o),g(t,u)]}function jr(r,e){if(c(r),d(e,"exponent"),a(e))return E(1,0);if(Ar(e,1))return E(r.real,r.imag);if(Ar(e,2))return P(r,r);if(a(r.real)&&a(r.imag)){if(e>0)return E(0,0);if(e<0)throw new Error("Cannot raise zero to a negative power")}let n=q(r),t=Math.pow(n.magnitude,e),o=t<-1e-10?Math.abs(t):Math.max(0,t),u=n.angle*e;return g(o,u)}function Gr(r){c(r);let e=V(r);if(a(e))throw new Error("Cannot take logarithm of zero or near-zero complex number");let n=w(r);return D({real:Math.log(e),imag:n})}var N=3.141592653589793,de=2.718281828459045,he=1.618033988749894,ye=1.4142135623730951,ge=.7071067811865476,Ve=.6931471805599453,we=2.302585092994046,ze=1.4426950408889634,Me=.4342944819032518,Ce=360,Ee=2*N,Ne=400,Se=180/N,Re=N/180,x={PI:N,E:de,PHI:he,SQRT2:ye,SQRT1_2:ge,LN2:Ve,LN10:we,LOG2E:ze,LOG10E:Me,DEGREES_IN_CIRCLE:Ce,RADIANS_IN_CIRCLE:Ee,GRADIANS_IN_CIRCLE:Ne,DEGREES_PER_RADIAN:Se,RADIANS_PER_DEGREE:Re};function Br(r){return r*x.RADIANS_PER_DEGREE}function Or(r){return r*x.DEGREES_PER_RADIAN}function kr(r){return r*(x.GRADIANS_IN_CIRCLE/x.DEGREES_IN_CIRCLE)}function Qr(r){return r*(x.DEGREES_IN_CIRCLE/x.GRADIANS_IN_CIRCLE)}function Zr(r){let e=x.RADIANS_IN_CIRCLE,n=r%e;return n<0&&(n+=e),n}function Xr(r){let e=r%x.DEGREES_IN_CIRCLE;return e<0&&(e+=x.DEGREES_IN_CIRCLE),e}function Yr(r){return Math.sin(r)}function Hr(r){return Math.cos(r)}function Ur(r){let e=Math.cos(r);if(Math.abs(e)<1e-10)throw new Error("Tangent undefined for this angle (cosine is zero)");return Math.tan(r)}function Wr(r){if(r<-1||r>1)throw new Error("Arcsine is only defined for values between -1 and 1");return Math.asin(r)}function Jr(r){if(r<-1||r>1)throw new Error("Arccosine is only defined for values between -1 and 1");return Math.acos(r)}function Kr(r){return Math.atan(r)}function vr(r,e){return Math.atan2(r,e)}function re(r){return Math.sinh(r)}function ee(r){return Math.cosh(r)}function ne(r){return Math.tanh(r)}function te(r){return Math.asinh(r)}function oe(r){if(r<1)throw new Error("Inverse hyperbolic cosine is only defined for x >= 1");return Math.acosh(r)}function ue(r){if(Math.abs(r)>=1)throw new Error("Inverse hyperbolic tangent is only defined for |x| < 1");return Math.atanh(r)}function ie(r){let e=Math.cos(r);if(Math.abs(e)<1e-10)throw new Error("Secant undefined for this angle (cosine is zero)");return 1/e}function ce(r){let e=Math.sin(r);if(Math.abs(e)<1e-10)throw new Error("Cosecant undefined for this angle (sine is zero)");return 1/e}function me(r){let e=Math.tan(r);if(Math.abs(e)<1e-10)throw new Error("Cotangent undefined for this angle (tangent is zero)");return 1/e}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Re-export all mathematical functions.
3
+ * @module MathFunctions
4
+ */
5
+ export { add, subtract, divide, modulo, power, sqrt, abs, round, floor, ceil, trunc, clamp, sign, factorial, gcd, lcm, lerp, min, max, average, sum, product, invLerp, mapRange, median } from './basic.js';
6
+ export { ln, log10, log2, log, exp, cbrt, nthRoot, solveQuadratic, evaluatePolynomial, simplifyFraction, addFractions, multiplyFractions, percentage, normalize, range, toBase, toOrdinal, truncateDecimals, wrap } from './advanced.js';
7
+ export { magnitude2D, magnitude3D, magnitude4D, normalize2D, normalize3D, dotProduct2D, dotProduct3D, crossProduct3D, addVectors2D, subtractVectors2D, scaleVector2D, angleBetween2D, distance2D, distance3D, lerp2D, rotate2D, } from './vector.js';
8
+ export { addComplex, subtractComplex, multiplyComplex, divideComplex, magnitudeComplex, conjugateComplex, argumentComplex, toPolarComplex, fromPolarComplex, sqrtComplex, powerComplex, lnComplex, } from './complex.js';
9
+ export { degToRad, radToDeg, degToGrad, gradToDeg, normalizeRadians, normalizeDegrees, sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, sec, csc, cot, } from './trigo.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/maths/fn/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,GAAG,EACH,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,IAAI,EACJ,GAAG,EACH,KAAK,EACL,KAAK,EACL,IAAI,EACJ,KAAK,EACL,KAAK,EACL,IAAI,EACJ,SAAS,EACT,GAAG,EACH,GAAG,EACH,IAAI,EACJ,GAAG,EACH,GAAG,EACH,OAAO,EACP,GAAG,EACH,OAAO,EACP,OAAO,EACP,QAAQ,EACR,MAAM,EACP,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,EAAE,EACF,KAAK,EACL,IAAI,EACJ,GAAG,EACH,GAAG,EACH,IAAI,EACJ,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,KAAK,EACL,MAAM,EACN,SAAS,EACT,gBAAgB,EAChB,IAAI,EACL,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,UAAU,EACV,UAAU,EACV,MAAM,EACN,QAAQ,GACT,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,UAAU,EACV,eAAe,EACf,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,SAAS,GACV,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,GAAG,EACH,GAAG,EACH,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,GAAG,EACH,GAAG,EACH,GAAG,GACJ,MAAM,YAAY,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Re-export all mathematical functions.
3
+ * @module MathFunctions
4
+ */
5
+ export { add, subtract, divide, modulo, power, sqrt, abs, round, floor, ceil, trunc, clamp, sign, factorial, gcd, lcm, lerp, min, max, average, sum, product, invLerp, mapRange, median } from './basic.js';
6
+ export { ln, log10, log2, log, exp, cbrt, nthRoot, solveQuadratic, evaluatePolynomial, simplifyFraction, addFractions, multiplyFractions, percentage, normalize, range, toBase, toOrdinal, truncateDecimals, wrap } from './advanced.js';
7
+ export { magnitude2D, magnitude3D, magnitude4D, normalize2D, normalize3D, dotProduct2D, dotProduct3D, crossProduct3D, addVectors2D, subtractVectors2D, scaleVector2D, angleBetween2D, distance2D, distance3D, lerp2D, rotate2D, } from './vector.js';
8
+ export { addComplex, subtractComplex, multiplyComplex, divideComplex, magnitudeComplex, conjugateComplex, argumentComplex, toPolarComplex, fromPolarComplex, sqrtComplex, powerComplex, lnComplex, } from './complex.js';
9
+ export { degToRad, radToDeg, degToGrad, gradToDeg, normalizeRadians, normalizeDegrees, sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, sec, csc, cot, } from './trigo.js';
@@ -0,0 +1 @@
1
+ function _(r,e){return r+e}function L(r,e){return r-e}var $=(r,e,n)=>e===0?n!==void 0?n:NaN:r/e;function j(r,e){return r%e}function G(r,e){return Math.pow(r,e)}function B(r){if(r<0)throw new Error("Cannot calculate square root of negative number");return Math.sqrt(r)}function O(r){return Math.abs(r)}var d=(r,e=0,n="round")=>{if(n==="david")return k(r,e,n);if(!Number.isFinite(r))return r;if(e===0)return Math[n](r);if(e<0){let h=10**-e;return Math[n](r/h)*h}let t=10**e,o=Math.pow(2,-52),u=r*t,s=Math.sign(u)*o*Math.abs(u),l;switch(n){case"round":l=Math.round(u+s);break;case"ceil":l=Math.ceil(u-o);break;case"floor":l=Math.floor(u+o);break;case"trunc":l=u<0?Math.ceil(u):Math.floor(u);break;default:l=Math.round(u+s)}return l/t},k=(r,e=0,n="round")=>{let t=Math.abs(r),o=r<0?-1:1;if(e===0)return Math.round(t)*o;if(!Number.isFinite(t))return t*o;let u=10**e,s=t*u,l=Math.pow(2,-53),h=Math.sign(s)*l*Math.abs(s);return s+=h,Math.round(s)/u*o},Q=(r,e=0)=>d(r,e,"ceil"),Z=(r,e=0)=>d(r,e,"floor"),X=(r,e=0)=>d(r,e,"trunc"),E=(r,e,n)=>(e>n&&([e,n]=[n,e]),r<e?e:r>n?n:r);function Y(r){return r>0?1:r<0?-1:0}function H(r){if(!Number.isInteger(r)||r<0)throw new Error("Factorial is only defined for non-negative integers");if(r===0||r===1)return 1;let e=1;for(let n=2;n<=r;n++)e*=n;return e}function y(r,e){for(r=Math.abs(r),e=Math.abs(e);e!==0;){let n=e;e=r%e,r=n}return r}function U(r,e){return Math.abs(r*e)/y(r,e)}function R(r,e,n){return r+(e-r)*E(n,0,1)}var F=(r,e,n)=>E((n-r)/(e-r),0,1),W=(r,e,n,t,o)=>{let u=F(e,n,r);return R(t,o,u)};function J(...r){return Math.min(...r)}function K(...r){return Math.max(...r)}var v=(...r)=>{if(!Array.isArray(r)||r.length===0)return 0;let e=0,n=0;for(let t of r)Number.isFinite(t)&&(e+=t,n++);return n===0?0:e/n},rr=(...r)=>Array.isArray(r)?r.reduce((e,n)=>e+(Number.isFinite(n)?n:0),0):0,er=(...r)=>{if(!Array.isArray(r)||r.length===0)return 0;let e=r.filter(Number.isFinite);if(e.length===0)return 0;e.sort((t,o)=>t-o);let n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]};function nr(...r){return r.reduce((e,n)=>e*n,1)}function tr(r){if(r<=0)throw new Error("Natural logarithm is only defined for positive numbers");return Math.log(r)}function or(r){if(r<=0)throw new Error("Logarithm is only defined for positive numbers");return Math.log10(r)}function ur(r){if(r<=0)throw new Error("Logarithm is only defined for positive numbers");return Math.log2(r)}function ir(r,e){if(r<=0||e<=0)throw new Error("Logarithm is only defined for positive numbers and bases");return Math.log(r)/Math.log(e)}function cr(r){return Math.exp(r)}function mr(r){return Math.cbrt(r)}function ar(r,e){if(e===0)throw new Error("Cannot calculate 0th root");if(r<0&&e%2===0)throw new Error("Cannot calculate even root of negative number");let n=1/e;return Math.sign(r)*Math.pow(Math.abs(r),n)}function sr(r,e,n){if(r===0)return e===0?[]:[-n/e];let t=e*e-4*r*n;if(t<0)return[];if(t===0)return[-e/(2*r)];{let o=Math.sqrt(t);return[(-e-o)/(2*r),(-e+o)/(2*r)]}}function xr(r,e){let n=0;for(let t=0;t<r.length;t++)n=n*e+r[t];return n}function N(r){let e=y(r.numerator,r.denominator);return{numerator:r.numerator/e,denominator:r.denominator/e}}function pr(r,e){let n=r.numerator*e.denominator+e.numerator*r.denominator,t=r.denominator*e.denominator;return N({numerator:n,denominator:t})}function lr(r,e){let n=r.numerator*e.numerator,t=r.denominator*e.denominator;return N({numerator:n,denominator:t})}var fr=(r,e,n=2)=>{if(e===0)return 0;let t=r/e*100;return d(t,n)},Dr=(r,e,n=1)=>{if(e<2||e>36)throw new Error("Base must be between 2 and 36");return r.toString(e).padStart(n,"0")},br=r=>{let e=["th","st","nd","rd"],n=r%100;return r+(e[(n-20)%10]||e[n]||e[0])},dr=(r,e,n=1)=>{let t=[];if(n===0)return t;if(n>0)for(let o=r;o<e;o+=n)t.push(o);else for(let o=r;o>e;o+=n)t.push(o);return t},hr=(r,e)=>{if(!Number.isFinite(r))return r;let n=10**e;return Math.trunc(r*n)/n},yr=(r,e,n)=>e===n?0:(r-e)/(n-e),gr=(r,e,n)=>{let t=n-e;return((r-e)%t+t)%t+e};function m(r,e){if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${e} must be a finite number, got ${r}`)}function p(r){return Math.abs(r)<1e-9}function i(r,e="Vector2D"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);m(r.x,`${e}.x`),m(r.y,`${e}.y`)}function f(r,e="Vector3D"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);m(r.x,`${e}.x`),m(r.y,`${e}.y`),m(r.z,`${e}.z`)}function Vr(r,e="Vector4D"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);m(r.x,`${e}.x`),m(r.y,`${e}.y`),m(r.z,`${e}.z`),m(r.w,`${e}.w`)}function g(r){i(r);let e=Math.sqrt(r.x*r.x+r.y*r.y);return p(e)?0:e}function I(r){f(r);let e=Math.sqrt(r.x*r.x+r.y*r.y+r.z*r.z);return p(e)?0:e}function wr(r){Vr(r);let e=Math.sqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.w*r.w);return p(e)?0:e}function zr(r){i(r);let e=g(r);if(p(e))throw new Error("Cannot normalize zero or near-zero vector");return{x:r.x/e,y:r.y/e}}function Mr(r){f(r);let e=I(r);if(p(e))throw new Error("Cannot normalize zero or near-zero vector");return{x:r.x/e,y:r.y/e,z:r.z/e}}function T(r,e){return i(r,"First vector"),i(e,"Second vector"),r.x*e.x+r.y*e.y}function Cr(r,e){return f(r,"First vector"),f(e,"Second vector"),r.x*e.x+r.y*e.y+r.z*e.z}function Er(r,e){return f(r,"First vector"),f(e,"Second vector"),{x:r.y*e.z-r.z*e.y,y:r.z*e.x-r.x*e.z,z:r.x*e.y-r.y*e.x}}function Nr(r,e){return i(r,"First vector"),i(e,"Second vector"),{x:r.x+e.x,y:r.y+e.y}}function Sr(r,e){return i(r,"First vector"),i(e,"Second vector"),{x:r.x-e.x,y:r.y-e.y}}function Rr(r,e){return i(r),m(e,"scalar"),{x:r.x*e,y:r.y*e}}function Fr(r,e){i(r,"First vector"),i(e,"Second vector");let n=T(r,e),t=g(r),o=g(e);if(p(t)||p(o))throw new Error("Cannot calculate angle with zero or near-zero vector");let u=Math.max(-1,Math.min(1,n/(t*o)));return Math.acos(u)}function Ir(r,e){i(r,"First point"),i(e,"Second point");let n=e.x-r.x,t=e.y-r.y,o=Math.sqrt(n*n+t*t);return p(o)?0:o}function Tr(r,e){f(r,"First point"),f(e,"Second point");let n=e.x-r.x,t=e.y-r.y,o=e.z-r.z,u=Math.sqrt(n*n+t*t+o*o);return p(u)?0:u}function Ar(r,e,n){return i(r,"Start vector"),i(e,"End vector"),m(n,"t"),{x:r.x+(e.x-r.x)*n,y:r.y+(e.y-r.y)*n}}function Pr(r,e){i(r),m(e,"angle");let n=Math.cos(e),t=Math.sin(e);return{x:r.x*n-r.y*t,y:r.x*t+r.y*n}}var S=2*Math.PI;function a(r){return Math.abs(r)<1e-10}function A(r,e){return Math.abs(r-e)<1e-10}function D(r){return{real:a(r.real)?0:r.real,imag:a(r.imag)?0:r.imag}}function b(r,e){if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${e} must be a finite number, got ${r}`)}function c(r,e="Complex number"){if(!r||typeof r!="object")throw new Error(`${e} must be an object`);b(r.real,`${e}.real`),b(r.imag,`${e}.imag`)}function V(r,e=0){return b(r,"real"),b(e,"imag"),D({real:r,imag:e})}function qr(r,e){return c(r,"First complex number"),c(e,"Second complex number"),D({real:r.real+e.real,imag:r.imag+e.imag})}function _r(r,e){return c(r,"First complex number"),c(e,"Second complex number"),D({real:r.real-e.real,imag:r.imag-e.imag})}function P(r,e){return c(r,"First complex number"),c(e,"Second complex number"),D({real:r.real*e.real-r.imag*e.imag,imag:r.real*e.imag+r.imag*e.real})}function Lr(r,e){c(r,"Numerator complex number"),c(e,"Denominator complex number");let n=e.real*e.real+e.imag*e.imag;if(a(n))throw new Error("Cannot divide by zero or near-zero complex number");return D({real:(r.real*e.real+r.imag*e.imag)/n,imag:(r.imag*e.real-r.real*e.imag)/n})}function z(r){c(r);let e=Math.sqrt(r.real*r.real+r.imag*r.imag);return a(e)?0:e}function $r(r){return c(r),D({real:r.real,imag:-r.imag})}function M(r){return c(r),a(r.real)&&a(r.imag)?0:Math.atan2(r.imag,r.real)}function q(r){return c(r),{magnitude:z(r),angle:M(r)}}function w(r,e){if(b(r,"magnitude"),b(e,"angle"),r<-1e-10)throw new Error("Magnitude must be non-negative");let n=e%S;n>Math.PI&&(n-=S),n<=-Math.PI&&(n+=S);let t=Math.max(0,r);return D({real:t*Math.cos(n),imag:t*Math.sin(n)})}function jr(r){if(c(r),a(r.real)&&a(r.imag)){let s=V(0,0);return[s,s]}let e=z(r),n=M(r),t=Math.sqrt(e),o=n/2,u=o+Math.PI;return[w(t,o),w(t,u)]}function Gr(r,e){if(c(r),b(e,"exponent"),a(e))return V(1,0);if(A(e,1))return V(r.real,r.imag);if(A(e,2))return P(r,r);if(a(r.real)&&a(r.imag)){if(e>0)return V(0,0);if(e<0)throw new Error("Cannot raise zero to a negative power")}let n=q(r),t=Math.pow(n.magnitude,e),o=t<-1e-10?Math.abs(t):Math.max(0,t),u=n.angle*e;return w(o,u)}function Br(r){c(r);let e=z(r);if(a(e))throw new Error("Cannot take logarithm of zero or near-zero complex number");let n=M(r);return D({real:Math.log(e),imag:n})}var C=3.141592653589793,Or=2.718281828459045,kr=1.618033988749894,Qr=1.4142135623730951,Zr=.7071067811865476,Xr=.6931471805599453,Yr=2.302585092994046,Hr=1.4426950408889634,Ur=.4342944819032518,Wr=360,Jr=2*C,Kr=400,vr=180/C,re=C/180,x={PI:C,E:Or,PHI:kr,SQRT2:Qr,SQRT1_2:Zr,LN2:Xr,LN10:Yr,LOG2E:Hr,LOG10E:Ur,DEGREES_IN_CIRCLE:Wr,RADIANS_IN_CIRCLE:Jr,GRADIANS_IN_CIRCLE:Kr,DEGREES_PER_RADIAN:vr,RADIANS_PER_DEGREE:re};function ee(r){return r*x.RADIANS_PER_DEGREE}function ne(r){return r*x.DEGREES_PER_RADIAN}function te(r){return r*(x.GRADIANS_IN_CIRCLE/x.DEGREES_IN_CIRCLE)}function oe(r){return r*(x.DEGREES_IN_CIRCLE/x.GRADIANS_IN_CIRCLE)}function ue(r){let e=x.RADIANS_IN_CIRCLE,n=r%e;return n<0&&(n+=e),n}function ie(r){let e=r%x.DEGREES_IN_CIRCLE;return e<0&&(e+=x.DEGREES_IN_CIRCLE),e}function ce(r){return Math.sin(r)}function me(r){return Math.cos(r)}function ae(r){let e=Math.cos(r);if(Math.abs(e)<1e-10)throw new Error("Tangent undefined for this angle (cosine is zero)");return Math.tan(r)}function se(r){if(r<-1||r>1)throw new Error("Arcsine is only defined for values between -1 and 1");return Math.asin(r)}function xe(r){if(r<-1||r>1)throw new Error("Arccosine is only defined for values between -1 and 1");return Math.acos(r)}function pe(r){return Math.atan(r)}function le(r,e){return Math.atan2(r,e)}function fe(r){return Math.sinh(r)}function De(r){return Math.cosh(r)}function be(r){return Math.tanh(r)}function de(r){return Math.asinh(r)}function he(r){if(r<1)throw new Error("Inverse hyperbolic cosine is only defined for x >= 1");return Math.acosh(r)}function ye(r){if(Math.abs(r)>=1)throw new Error("Inverse hyperbolic tangent is only defined for |x| < 1");return Math.atanh(r)}function ge(r){let e=Math.cos(r);if(Math.abs(e)<1e-10)throw new Error("Secant undefined for this angle (cosine is zero)");return 1/e}function Ve(r){let e=Math.sin(r);if(Math.abs(e)<1e-10)throw new Error("Cosecant undefined for this angle (sine is zero)");return 1/e}function we(r){let e=Math.tan(r);if(Math.abs(e)<1e-10)throw new Error("Cotangent undefined for this angle (tangent is zero)");return 1/e}export{O as abs,xe as acos,he as acosh,_ as add,qr as addComplex,pr as addFractions,Nr as addVectors2D,Fr as angleBetween2D,M as argumentComplex,se as asin,de as asinh,pe as atan,le as atan2,ye as atanh,v as average,mr as cbrt,Q as ceil,E as clamp,$r as conjugateComplex,me as cos,De as cosh,we as cot,Er as crossProduct3D,Ve as csc,te as degToGrad,ee as degToRad,Ir as distance2D,Tr as distance3D,$ as divide,Lr as divideComplex,T as dotProduct2D,Cr as dotProduct3D,xr as evaluatePolynomial,cr as exp,H as factorial,Z as floor,w as fromPolarComplex,y as gcd,oe as gradToDeg,F as invLerp,U as lcm,R as lerp,Ar as lerp2D,tr as ln,Br as lnComplex,ir as log,or as log10,ur as log2,g as magnitude2D,I as magnitude3D,wr as magnitude4D,z as magnitudeComplex,W as mapRange,K as max,er as median,J as min,j as modulo,P as multiplyComplex,lr as multiplyFractions,yr as normalize,zr as normalize2D,Mr as normalize3D,ie as normalizeDegrees,ue as normalizeRadians,ar as nthRoot,fr as percentage,G as power,Gr as powerComplex,nr as product,ne as radToDeg,dr as range,Pr as rotate2D,d as round,Rr as scaleVector2D,ge as sec,Y as sign,N as simplifyFraction,ce as sin,fe as sinh,sr as solveQuadratic,B as sqrt,jr as sqrtComplex,L as subtract,_r as subtractComplex,Sr as subtractVectors2D,rr as sum,ae as tan,be as tanh,Dr as toBase,br as toOrdinal,q as toPolarComplex,X as trunc,hr as truncateDecimals,gr as wrap};
@@ -0,0 +1 @@
1
+ "use strict";var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var f=(n,e)=>{for(var r in e)a(n,r,{get:e[r],enumerable:!0})},b=(n,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of c(e))!E.call(n,o)&&o!==r&&a(n,o,{get:()=>e[o],enumerable:!(i=u(e,o))||i.enumerable});return n};var h=n=>b(a({},"__esModule",{value:!0}),n);var W={};f(W,{acos:()=>Q,acosh:()=>F,asin:()=>O,asinh:()=>B,atan:()=>j,atan2:()=>H,atanh:()=>J,cos:()=>P,cosh:()=>q,cot:()=>V,csc:()=>U,degToGrad:()=>G,degToRad:()=>w,gradToDeg:()=>l,normalizeDegrees:()=>y,normalizeRadians:()=>L,radToDeg:()=>S,sec:()=>K,sin:()=>z,sinh:()=>k,tan:()=>T,tanh:()=>v});module.exports=h(W);var s=3.141592653589793,R=2.718281828459045,m=1.618033988749894,p=1.4142135623730951,d=.7071067811865476,x=.6931471805599453,I=2.302585092994046,_=1.4426950408889634,D=.4342944819032518,C=360,M=2*s,g=400,N=180/s,A=s/180,t={PI:s,E:R,PHI:m,SQRT2:p,SQRT1_2:d,LN2:x,LN10:I,LOG2E:_,LOG10E:D,DEGREES_IN_CIRCLE:C,RADIANS_IN_CIRCLE:M,GRADIANS_IN_CIRCLE:g,DEGREES_PER_RADIAN:N,RADIANS_PER_DEGREE:A};function w(n){return n*t.RADIANS_PER_DEGREE}function S(n){return n*t.DEGREES_PER_RADIAN}function G(n){return n*(t.GRADIANS_IN_CIRCLE/t.DEGREES_IN_CIRCLE)}function l(n){return n*(t.DEGREES_IN_CIRCLE/t.GRADIANS_IN_CIRCLE)}function L(n){let e=t.RADIANS_IN_CIRCLE,r=n%e;return r<0&&(r+=e),r}function y(n){let e=n%t.DEGREES_IN_CIRCLE;return e<0&&(e+=t.DEGREES_IN_CIRCLE),e}function z(n){return Math.sin(n)}function P(n){return Math.cos(n)}function T(n){let e=Math.cos(n);if(Math.abs(e)<1e-10)throw new Error("Tangent undefined for this angle (cosine is zero)");return Math.tan(n)}function O(n){if(n<-1||n>1)throw new Error("Arcsine is only defined for values between -1 and 1");return Math.asin(n)}function Q(n){if(n<-1||n>1)throw new Error("Arccosine is only defined for values between -1 and 1");return Math.acos(n)}function j(n){return Math.atan(n)}function H(n,e){return Math.atan2(n,e)}function k(n){return Math.sinh(n)}function q(n){return Math.cosh(n)}function v(n){return Math.tanh(n)}function B(n){return Math.asinh(n)}function F(n){if(n<1)throw new Error("Inverse hyperbolic cosine is only defined for x >= 1");return Math.acosh(n)}function J(n){if(Math.abs(n)>=1)throw new Error("Inverse hyperbolic tangent is only defined for |x| < 1");return Math.atanh(n)}function K(n){let e=Math.cos(n);if(Math.abs(e)<1e-10)throw new Error("Secant undefined for this angle (cosine is zero)");return 1/e}function U(n){let e=Math.sin(n);if(Math.abs(e)<1e-10)throw new Error("Cosecant undefined for this angle (sine is zero)");return 1/e}function V(n){let e=Math.tan(n);if(Math.abs(e)<1e-10)throw new Error("Cotangent undefined for this angle (tangent is zero)");return 1/e}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Trigonometric functions and angle conversions.
3
+ * @module TrigonometryFunctions
4
+ */
5
+ import type { Degrees, Radians } from '../types/basic.js';
6
+ /**
7
+ * Converts degrees to radians.
8
+ * @param degrees - Angle in degrees
9
+ * @returns Angle in radians
10
+ */
11
+ export declare function degToRad(degrees: number): Radians;
12
+ /**
13
+ * Converts radians to degrees.
14
+ * @param radians - Angle in radians
15
+ * @returns Angle in degrees
16
+ */
17
+ export declare function radToDeg(radians: number): Degrees;
18
+ /**
19
+ * Converts degrees to gradians.
20
+ * @param degrees - Angle in degrees
21
+ * @returns Angle in gradians
22
+ */
23
+ export declare function degToGrad(degrees: number): number;
24
+ /**
25
+ * Converts gradians to degrees.
26
+ * @param gradians - Angle in gradians
27
+ * @returns Angle in degrees
28
+ */
29
+ export declare function gradToDeg(gradians: number): Degrees;
30
+ /**
31
+ * Normalizes an angle to the range [0, 2π) radians.
32
+ * @param radians - Angle in radians
33
+ * @returns Normalized angle in radians
34
+ */
35
+ export declare function normalizeRadians(radians: number): Radians;
36
+ /**
37
+ * Normalizes an angle to the range [0, 360) degrees.
38
+ * @param degrees - Angle in degrees
39
+ * @returns Normalized angle in degrees
40
+ */
41
+ export declare function normalizeDegrees(degrees: number): Degrees;
42
+ /**
43
+ * Calculates the sine of an angle in radians.
44
+ * @param radians - Angle in radians
45
+ * @returns The sine value
46
+ */
47
+ export declare function sin(radians: number): number;
48
+ /**
49
+ * Calculates the cosine of an angle in radians.
50
+ * @param radians - Angle in radians
51
+ * @returns The cosine value
52
+ */
53
+ export declare function cos(radians: number): number;
54
+ /**
55
+ * Calculates the tangent of an angle in radians.
56
+ * @param radians - Angle in radians
57
+ * @returns The tangent value
58
+ * @throws {Error} If cosine is zero (angle is π/2 + nπ)
59
+ */
60
+ export declare function tan(radians: number): number;
61
+ /**
62
+ * Calculates the arcsine (inverse sine) in radians.
63
+ * @param value - Sine value between -1 and 1
64
+ * @returns Angle in radians
65
+ * @throws {Error} If value is outside [-1, 1]
66
+ */
67
+ export declare function asin(value: number): Radians;
68
+ /**
69
+ * Calculates the arccosine (inverse cosine) in radians.
70
+ * @param value - Cosine value between -1 and 1
71
+ * @returns Angle in radians
72
+ * @throws {Error} If value is outside [-1, 1]
73
+ */
74
+ export declare function acos(value: number): Radians;
75
+ /**
76
+ * Calculates the arctangent (inverse tangent) in radians.
77
+ * @param value - Tangent value
78
+ * @returns Angle in radians between -π/2 and π/2
79
+ */
80
+ export declare function atan(value: number): Radians;
81
+ /**
82
+ * Calculates the arctangent of y/x in radians, handling all quadrants.
83
+ * @param y - Numerator
84
+ * @param x - Denominator
85
+ * @returns Angle in radians between -π and π
86
+ */
87
+ export declare function atan2(y: number, x: number): Radians;
88
+ /**
89
+ * Calculates the hyperbolic sine.
90
+ * @param x - Input value
91
+ * @returns Hyperbolic sine
92
+ */
93
+ export declare function sinh(x: number): number;
94
+ /**
95
+ * Calculates the hyperbolic cosine.
96
+ * @param x - Input value
97
+ * @returns Hyperbolic cosine
98
+ */
99
+ export declare function cosh(x: number): number;
100
+ /**
101
+ * Calculates the hyperbolic tangent.
102
+ * @param x - Input value
103
+ * @returns Hyperbolic tangent
104
+ */
105
+ export declare function tanh(x: number): number;
106
+ /**
107
+ * Calculates the inverse hyperbolic sine.
108
+ * @param x - Input value
109
+ * @returns Inverse hyperbolic sine
110
+ */
111
+ export declare function asinh(x: number): number;
112
+ /**
113
+ * Calculates the inverse hyperbolic cosine.
114
+ * @param x - Input value >= 1
115
+ * @returns Inverse hyperbolic cosine
116
+ * @throws {Error} If x < 1
117
+ */
118
+ export declare function acosh(x: number): number;
119
+ /**
120
+ * Calculates the inverse hyperbolic tangent.
121
+ * @param x - Input value between -1 and 1 (exclusive)
122
+ * @returns Inverse hyperbolic tangent
123
+ * @throws {Error} If |x| >= 1
124
+ */
125
+ export declare function atanh(x: number): number;
126
+ /**
127
+ * Calculates the secant of an angle.
128
+ * @param radians - Angle in radians
129
+ * @returns The secant value
130
+ * @throws {Error} If cosine is zero
131
+ */
132
+ export declare function sec(radians: number): number;
133
+ /**
134
+ * Calculates the cosecant of an angle.
135
+ * @param radians - Angle in radians
136
+ * @returns The cosecant value
137
+ * @throws {Error} If sine is zero
138
+ */
139
+ export declare function csc(radians: number): number;
140
+ /**
141
+ * Calculates the cotangent of an angle.
142
+ * @param radians - Angle in radians
143
+ * @returns The cotangent value
144
+ * @throws {Error} If tangent is zero
145
+ */
146
+ export declare function cot(radians: number): number;
147
+ //# sourceMappingURL=trigo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigo.d.ts","sourceRoot":"","sources":["../../../../src/lib/maths/fn/trigo.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAKzD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM3C;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK3C;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK3C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAKvC;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAKvC;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM3C;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM3C;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM3C"}