goscript 0.0.33 → 0.0.35

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 (347) hide show
  1. package/compiler/analysis.go +30 -22
  2. package/compiler/analysis_test.go +14 -0
  3. package/compiler/assignment.go +45 -7
  4. package/compiler/builtin_test.go +2 -0
  5. package/compiler/compiler.go +15 -89
  6. package/compiler/compiler_test.go +0 -53
  7. package/compiler/composite-lit.go +60 -17
  8. package/compiler/decl.go +1 -1
  9. package/compiler/expr-call.go +347 -30
  10. package/compiler/expr-selector.go +28 -2
  11. package/compiler/expr.go +79 -38
  12. package/compiler/lit.go +112 -3
  13. package/compiler/primitive.go +6 -6
  14. package/compiler/protobuf.go +0 -5
  15. package/compiler/sanitize.go +101 -0
  16. package/compiler/spec-value.go +25 -18
  17. package/compiler/stmt-assign.go +128 -91
  18. package/compiler/stmt-for.go +78 -1
  19. package/compiler/stmt-range.go +333 -461
  20. package/compiler/stmt.go +46 -9
  21. package/compiler/type.go +14 -11
  22. package/dist/gs/builtin/builtin.d.ts +8 -0
  23. package/dist/gs/builtin/builtin.js +31 -0
  24. package/dist/gs/builtin/builtin.js.map +1 -1
  25. package/dist/gs/builtin/map.d.ts +4 -4
  26. package/dist/gs/builtin/map.js +12 -6
  27. package/dist/gs/builtin/map.js.map +1 -1
  28. package/dist/gs/builtin/slice.d.ts +14 -8
  29. package/dist/gs/builtin/slice.js +131 -31
  30. package/dist/gs/builtin/slice.js.map +1 -1
  31. package/dist/gs/github.com/pkg/errors/errors.d.ts +13 -0
  32. package/dist/gs/github.com/pkg/errors/errors.js +232 -0
  33. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -0
  34. package/dist/gs/github.com/pkg/errors/go113.d.ts +4 -0
  35. package/dist/gs/github.com/pkg/errors/go113.js +34 -0
  36. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -0
  37. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -0
  38. package/dist/gs/github.com/pkg/errors/index.js +4 -0
  39. package/dist/gs/github.com/pkg/errors/index.js.map +1 -0
  40. package/dist/gs/github.com/pkg/errors/stack.d.ts +32 -0
  41. package/dist/gs/github.com/pkg/errors/stack.js +111 -0
  42. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -0
  43. package/dist/gs/maps/index.d.ts +2 -0
  44. package/dist/gs/maps/index.js +3 -0
  45. package/dist/gs/maps/index.js.map +1 -0
  46. package/dist/gs/maps/iter.d.ts +7 -0
  47. package/dist/gs/maps/iter.gs.d.ts +7 -0
  48. package/dist/gs/maps/iter.gs.js +65 -0
  49. package/dist/gs/maps/iter.gs.js.map +1 -0
  50. package/dist/gs/maps/iter.js +57 -0
  51. package/dist/gs/maps/iter.js.map +1 -0
  52. package/dist/gs/maps/maps.d.ts +7 -0
  53. package/dist/gs/maps/maps.gs.d.ts +7 -0
  54. package/dist/gs/maps/maps.gs.js +79 -0
  55. package/dist/gs/maps/maps.gs.js.map +1 -0
  56. package/dist/gs/maps/maps.js +67 -0
  57. package/dist/gs/maps/maps.js.map +1 -0
  58. package/dist/gs/math/abs.gs.d.ts +1 -0
  59. package/dist/gs/math/abs.gs.js +10 -0
  60. package/dist/gs/math/abs.gs.js.map +1 -0
  61. package/dist/gs/math/acosh.gs.d.ts +2 -0
  62. package/dist/gs/math/acosh.gs.js +14 -0
  63. package/dist/gs/math/acosh.gs.js.map +1 -0
  64. package/dist/gs/math/asin.gs.d.ts +4 -0
  65. package/dist/gs/math/asin.gs.js +24 -0
  66. package/dist/gs/math/asin.gs.js.map +1 -0
  67. package/dist/gs/math/asinh.gs.d.ts +2 -0
  68. package/dist/gs/math/asinh.gs.js +14 -0
  69. package/dist/gs/math/asinh.gs.js.map +1 -0
  70. package/dist/gs/math/atan.gs.d.ts +4 -0
  71. package/dist/gs/math/atan.gs.js +22 -0
  72. package/dist/gs/math/atan.gs.js.map +1 -0
  73. package/dist/gs/math/atan2.gs.d.ts +2 -0
  74. package/dist/gs/math/atan2.gs.js +30 -0
  75. package/dist/gs/math/atan2.gs.js.map +1 -0
  76. package/dist/gs/math/atanh.gs.d.ts +2 -0
  77. package/dist/gs/math/atanh.gs.js +16 -0
  78. package/dist/gs/math/atanh.gs.js.map +1 -0
  79. package/dist/gs/math/bits.gs.d.ts +5 -0
  80. package/dist/gs/math/bits.gs.js +46 -0
  81. package/dist/gs/math/bits.gs.js.map +1 -0
  82. package/dist/gs/math/cbrt.gs.d.ts +2 -0
  83. package/dist/gs/math/cbrt.gs.js +14 -0
  84. package/dist/gs/math/cbrt.gs.js.map +1 -0
  85. package/dist/gs/math/const.gs.d.ts +30 -0
  86. package/dist/gs/math/const.gs.js +61 -0
  87. package/dist/gs/math/const.gs.js.map +1 -0
  88. package/dist/gs/math/copysign.gs.d.ts +1 -0
  89. package/dist/gs/math/copysign.gs.js +20 -0
  90. package/dist/gs/math/copysign.gs.js.map +1 -0
  91. package/dist/gs/math/dim.gs.d.ts +5 -0
  92. package/dist/gs/math/dim.gs.js +69 -0
  93. package/dist/gs/math/dim.gs.js.map +1 -0
  94. package/dist/gs/math/erf.gs.d.ts +4 -0
  95. package/dist/gs/math/erf.gs.js +336 -0
  96. package/dist/gs/math/erf.gs.js.map +1 -0
  97. package/dist/gs/math/erfinv.gs.d.ts +2 -0
  98. package/dist/gs/math/erfinv.gs.js +118 -0
  99. package/dist/gs/math/erfinv.gs.js.map +1 -0
  100. package/dist/gs/math/exp.gs.d.ts +5 -0
  101. package/dist/gs/math/exp.gs.js +30 -0
  102. package/dist/gs/math/exp.gs.js.map +1 -0
  103. package/dist/gs/math/expm1.gs.d.ts +2 -0
  104. package/dist/gs/math/expm1.gs.js +17 -0
  105. package/dist/gs/math/expm1.gs.js.map +1 -0
  106. package/dist/gs/math/floor.gs.d.ts +8 -0
  107. package/dist/gs/math/floor.gs.js +75 -0
  108. package/dist/gs/math/floor.gs.js.map +1 -0
  109. package/dist/gs/math/fma.gs.d.ts +1 -0
  110. package/dist/gs/math/fma.gs.js +8 -0
  111. package/dist/gs/math/fma.gs.js.map +1 -0
  112. package/dist/gs/math/frexp.gs.d.ts +2 -0
  113. package/dist/gs/math/frexp.gs.js +28 -0
  114. package/dist/gs/math/frexp.gs.js.map +1 -0
  115. package/dist/gs/math/gamma.gs.d.ts +3 -0
  116. package/dist/gs/math/gamma.gs.js +149 -0
  117. package/dist/gs/math/gamma.gs.js.map +1 -0
  118. package/dist/gs/math/hypot.gs.d.ts +2 -0
  119. package/dist/gs/math/hypot.gs.js +16 -0
  120. package/dist/gs/math/hypot.gs.js.map +1 -0
  121. package/dist/gs/math/index.d.ts +44 -0
  122. package/dist/gs/math/index.js +45 -0
  123. package/dist/gs/math/index.js.map +1 -0
  124. package/dist/gs/math/j0.gs.d.ts +4 -0
  125. package/dist/gs/math/j0.gs.js +228 -0
  126. package/dist/gs/math/j0.gs.js.map +1 -0
  127. package/dist/gs/math/j1.gs.d.ts +4 -0
  128. package/dist/gs/math/j1.gs.js +211 -0
  129. package/dist/gs/math/j1.gs.js.map +1 -0
  130. package/dist/gs/math/jn.gs.d.ts +2 -0
  131. package/dist/gs/math/jn.gs.js +412 -0
  132. package/dist/gs/math/jn.gs.js.map +1 -0
  133. package/dist/gs/math/ldexp.gs.d.ts +2 -0
  134. package/dist/gs/math/ldexp.gs.js +20 -0
  135. package/dist/gs/math/ldexp.gs.js.map +1 -0
  136. package/dist/gs/math/lgamma.gs.d.ts +2 -0
  137. package/dist/gs/math/lgamma.gs.js +243 -0
  138. package/dist/gs/math/lgamma.gs.js.map +1 -0
  139. package/dist/gs/math/log.gs.d.ts +2 -0
  140. package/dist/gs/math/log.gs.js +16 -0
  141. package/dist/gs/math/log.gs.js.map +1 -0
  142. package/dist/gs/math/log10.gs.d.ts +4 -0
  143. package/dist/gs/math/log10.gs.js +17 -0
  144. package/dist/gs/math/log10.gs.js.map +1 -0
  145. package/dist/gs/math/log1p.gs.d.ts +2 -0
  146. package/dist/gs/math/log1p.gs.js +17 -0
  147. package/dist/gs/math/log1p.gs.js.map +1 -0
  148. package/dist/gs/math/logb.gs.d.ts +3 -0
  149. package/dist/gs/math/logb.gs.js +43 -0
  150. package/dist/gs/math/logb.gs.js.map +1 -0
  151. package/dist/gs/math/mod.gs.d.ts +2 -0
  152. package/dist/gs/math/mod.gs.js +26 -0
  153. package/dist/gs/math/mod.gs.js.map +1 -0
  154. package/dist/gs/math/modf.gs.d.ts +2 -0
  155. package/dist/gs/math/modf.gs.js +24 -0
  156. package/dist/gs/math/modf.gs.js.map +1 -0
  157. package/dist/gs/math/nextafter.gs.d.ts +2 -0
  158. package/dist/gs/math/nextafter.gs.js +66 -0
  159. package/dist/gs/math/nextafter.gs.js.map +1 -0
  160. package/dist/gs/math/pow.gs.d.ts +3 -0
  161. package/dist/gs/math/pow.gs.js +40 -0
  162. package/dist/gs/math/pow.gs.js.map +1 -0
  163. package/dist/gs/math/pow10.gs.d.ts +1 -0
  164. package/dist/gs/math/pow10.gs.js +14 -0
  165. package/dist/gs/math/pow10.gs.js.map +1 -0
  166. package/dist/gs/math/remainder.gs.d.ts +2 -0
  167. package/dist/gs/math/remainder.gs.js +25 -0
  168. package/dist/gs/math/remainder.gs.js.map +1 -0
  169. package/dist/gs/math/signbit.gs.d.ts +1 -0
  170. package/dist/gs/math/signbit.gs.js +5 -0
  171. package/dist/gs/math/signbit.gs.js.map +1 -0
  172. package/dist/gs/math/sin.gs.d.ts +4 -0
  173. package/dist/gs/math/sin.gs.js +29 -0
  174. package/dist/gs/math/sin.gs.js.map +1 -0
  175. package/dist/gs/math/sincos.gs.d.ts +1 -0
  176. package/dist/gs/math/sincos.gs.js +11 -0
  177. package/dist/gs/math/sincos.gs.js.map +1 -0
  178. package/dist/gs/math/sinh.gs.d.ts +4 -0
  179. package/dist/gs/math/sinh.gs.js +27 -0
  180. package/dist/gs/math/sinh.gs.js.map +1 -0
  181. package/dist/gs/math/sqrt.gs.d.ts +2 -0
  182. package/dist/gs/math/sqrt.gs.js +15 -0
  183. package/dist/gs/math/sqrt.gs.js.map +1 -0
  184. package/dist/gs/math/tan.gs.d.ts +2 -0
  185. package/dist/gs/math/tan.gs.js +17 -0
  186. package/dist/gs/math/tan.gs.js.map +1 -0
  187. package/dist/gs/math/tanh.gs.d.ts +2 -0
  188. package/dist/gs/math/tanh.gs.js +17 -0
  189. package/dist/gs/math/tanh.gs.js.map +1 -0
  190. package/dist/gs/math/trig_reduce.gs.d.ts +1 -0
  191. package/dist/gs/math/trig_reduce.gs.js +62 -0
  192. package/dist/gs/math/trig_reduce.gs.js.map +1 -0
  193. package/dist/gs/math/unsafe.gs.d.ts +4 -0
  194. package/dist/gs/math/unsafe.gs.js +47 -0
  195. package/dist/gs/math/unsafe.gs.js.map +1 -0
  196. package/dist/gs/slices/slices.d.ts +6 -0
  197. package/dist/gs/slices/slices.js +8 -0
  198. package/dist/gs/slices/slices.js.map +1 -1
  199. package/dist/gs/strconv/atob.gs.d.ts +4 -0
  200. package/dist/gs/strconv/atob.gs.js +42 -0
  201. package/dist/gs/strconv/atob.gs.js.map +1 -0
  202. package/dist/gs/strconv/atof.gs.d.ts +2 -0
  203. package/dist/gs/strconv/atof.gs.js +51 -0
  204. package/dist/gs/strconv/atof.gs.js.map +1 -0
  205. package/dist/gs/strconv/atoi.gs.d.ts +33 -0
  206. package/dist/gs/strconv/atoi.gs.js +200 -0
  207. package/dist/gs/strconv/atoi.gs.js.map +1 -0
  208. package/dist/gs/strconv/doc.gs.d.ts +1 -0
  209. package/dist/gs/strconv/doc.gs.js +2 -0
  210. package/dist/gs/strconv/doc.gs.js.map +1 -0
  211. package/dist/gs/strconv/ftoa.gs.d.ts +3 -0
  212. package/dist/gs/strconv/ftoa.gs.js +58 -0
  213. package/dist/gs/strconv/ftoa.gs.js.map +1 -0
  214. package/dist/gs/strconv/index.d.ts +6 -0
  215. package/dist/gs/strconv/index.js +7 -0
  216. package/dist/gs/strconv/index.js.map +1 -0
  217. package/dist/gs/strconv/itoa.gs.d.ts +6 -0
  218. package/dist/gs/strconv/itoa.gs.js +37 -0
  219. package/dist/gs/strconv/itoa.gs.js.map +1 -0
  220. package/dist/gs/strconv/quote.gs.d.ts +19 -0
  221. package/dist/gs/strconv/quote.gs.js +217 -0
  222. package/dist/gs/strconv/quote.gs.js.map +1 -0
  223. package/dist/gs/strings/index.d.ts +3 -0
  224. package/dist/gs/strings/index.js +4 -0
  225. package/dist/gs/strings/index.js.map +1 -1
  226. package/dist/gs/strings/replace.d.ts +0 -74
  227. package/dist/gs/strings/replace.js +6 -204
  228. package/dist/gs/strings/replace.js.map +1 -1
  229. package/dist/gs/strings/search.d.ts +0 -1
  230. package/dist/gs/strings/search.js +0 -21
  231. package/dist/gs/strings/search.js.map +1 -1
  232. package/gs/builtin/builtin.ts +40 -0
  233. package/gs/builtin/map.ts +12 -7
  234. package/gs/builtin/slice.ts +174 -34
  235. package/gs/github.com/pkg/errors/errors.ts +307 -0
  236. package/gs/github.com/pkg/errors/go113.ts +39 -0
  237. package/gs/github.com/pkg/errors/index.ts +3 -0
  238. package/gs/github.com/pkg/errors/stack.ts +127 -0
  239. package/gs/maps/index.ts +2 -0
  240. package/gs/maps/iter.ts +67 -0
  241. package/gs/maps/maps.ts +89 -0
  242. package/gs/math/TODO.md +156 -0
  243. package/gs/math/abs.gs.test.ts +29 -0
  244. package/gs/math/abs.gs.ts +13 -0
  245. package/gs/math/acosh.gs.test.ts +39 -0
  246. package/gs/math/acosh.gs.ts +21 -0
  247. package/gs/math/asin.gs.test.ts +66 -0
  248. package/gs/math/asin.gs.ts +27 -0
  249. package/gs/math/asinh.gs.test.ts +37 -0
  250. package/gs/math/asinh.gs.ts +21 -0
  251. package/gs/math/atan.gs.test.ts +49 -0
  252. package/gs/math/atan.gs.ts +27 -0
  253. package/gs/math/atan2.gs.test.ts +55 -0
  254. package/gs/math/atan2.gs.ts +37 -0
  255. package/gs/math/atanh.gs.test.ts +47 -0
  256. package/gs/math/atanh.gs.ts +21 -0
  257. package/gs/math/bits.gs.test.ts +88 -0
  258. package/gs/math/bits.gs.ts +61 -0
  259. package/gs/math/cbrt.gs.test.ts +57 -0
  260. package/gs/math/cbrt.gs.ts +20 -0
  261. package/gs/math/const.gs.test.ts +54 -0
  262. package/gs/math/const.gs.ts +93 -0
  263. package/gs/math/copysign.gs.test.ts +44 -0
  264. package/gs/math/copysign.gs.ts +27 -0
  265. package/gs/math/dim.gs.test.ts +102 -0
  266. package/gs/math/dim.gs.ts +84 -0
  267. package/gs/math/erf.gs.test.ts +92 -0
  268. package/gs/math/erf.gs.ts +409 -0
  269. package/gs/math/erfinv.gs.test.ts +104 -0
  270. package/gs/math/erfinv.gs.ts +169 -0
  271. package/gs/math/exp.gs.test.ts +82 -0
  272. package/gs/math/exp.gs.ts +39 -0
  273. package/gs/math/expm1.gs.test.ts +48 -0
  274. package/gs/math/expm1.gs.ts +23 -0
  275. package/gs/math/floor.gs.test.ts +146 -0
  276. package/gs/math/floor.gs.ts +88 -0
  277. package/gs/math/fma.gs.test.ts +83 -0
  278. package/gs/math/fma.gs.ts +7 -0
  279. package/gs/math/frexp.gs.test.ts +146 -0
  280. package/gs/math/frexp.gs.ts +37 -0
  281. package/gs/math/gamma.gs.test.ts +66 -0
  282. package/gs/math/gamma.gs.ts +158 -0
  283. package/gs/math/hypot.gs.test.ts +73 -0
  284. package/gs/math/hypot.gs.ts +23 -0
  285. package/gs/math/index.ts +44 -0
  286. package/gs/math/j0.gs.test.ts +74 -0
  287. package/gs/math/j0.gs.ts +257 -0
  288. package/gs/math/j1.gs.test.ts +81 -0
  289. package/gs/math/j1.gs.ts +231 -0
  290. package/gs/math/jn.gs.test.ts +133 -0
  291. package/gs/math/jn.gs.ts +447 -0
  292. package/gs/math/ldexp.gs.test.ts +128 -0
  293. package/gs/math/ldexp.gs.ts +28 -0
  294. package/gs/math/lgamma.gs.test.ts +102 -0
  295. package/gs/math/lgamma.gs.ts +251 -0
  296. package/gs/math/log.gs.test.ts +40 -0
  297. package/gs/math/log.gs.ts +21 -0
  298. package/gs/math/log10.gs.test.ts +80 -0
  299. package/gs/math/log10.gs.ts +25 -0
  300. package/gs/math/log1p.gs.test.ts +55 -0
  301. package/gs/math/log1p.gs.ts +24 -0
  302. package/gs/math/logb.gs.test.ts +87 -0
  303. package/gs/math/logb.gs.ts +54 -0
  304. package/gs/math/mod.gs.test.ts +64 -0
  305. package/gs/math/mod.gs.ts +36 -0
  306. package/gs/math/modf.gs.test.ts +80 -0
  307. package/gs/math/modf.gs.ts +32 -0
  308. package/gs/math/nextafter.gs.test.ts +107 -0
  309. package/gs/math/nextafter.gs.ts +71 -0
  310. package/gs/math/pow.gs.test.ts +103 -0
  311. package/gs/math/pow.gs.ts +55 -0
  312. package/gs/math/pow10.gs.test.ts +58 -0
  313. package/gs/math/pow10.gs.ts +19 -0
  314. package/gs/math/remainder.gs.test.ts +70 -0
  315. package/gs/math/remainder.gs.ts +33 -0
  316. package/gs/math/signbit.gs.test.ts +33 -0
  317. package/gs/math/signbit.gs.ts +8 -0
  318. package/gs/math/sin.gs.test.ts +83 -0
  319. package/gs/math/sin.gs.ts +38 -0
  320. package/gs/math/sincos.gs.test.ts +91 -0
  321. package/gs/math/sincos.gs.ts +15 -0
  322. package/gs/math/sinh.gs.test.ts +66 -0
  323. package/gs/math/sinh.gs.ts +34 -0
  324. package/gs/math/sqrt.gs.test.ts +49 -0
  325. package/gs/math/sqrt.gs.ts +20 -0
  326. package/gs/math/tan.gs.test.ts +50 -0
  327. package/gs/math/tan.gs.ts +23 -0
  328. package/gs/math/tanh.gs.test.ts +52 -0
  329. package/gs/math/tanh.gs.ts +23 -0
  330. package/gs/math/trig_reduce.gs.ts +66 -0
  331. package/gs/math/unsafe.gs.ts +52 -0
  332. package/gs/slices/slices.ts +9 -0
  333. package/gs/strconv/atob.gs.ts +45 -0
  334. package/gs/strconv/atof.gs.ts +60 -0
  335. package/gs/strconv/atoi.gs.ts +243 -0
  336. package/gs/strconv/doc.gs.ts +2 -0
  337. package/gs/strconv/ftoa.gs.ts +66 -0
  338. package/gs/strconv/index.ts +6 -0
  339. package/gs/strconv/itoa.gs.ts +41 -0
  340. package/gs/strconv/quote.gs.ts +245 -0
  341. package/gs/strings/index.ts +4 -0
  342. package/gs/strings/replace.ts +9 -237
  343. package/gs/strings/search.ts +0 -28
  344. package/package.json +1 -1
  345. package/gs/stringslite/godoc.txt +0 -17
  346. package/gs/stringslite/index.ts +0 -1
  347. package/gs/stringslite/strings.ts +0 -82
@@ -0,0 +1,127 @@
1
+ import * as $ from "../../../builtin/builtin.js";
2
+
3
+ // Type definitions
4
+ export type uintptr = number;
5
+
6
+ export class Frame {
7
+ constructor(private _value: uintptr) {}
8
+
9
+ valueOf(): uintptr {
10
+ return this._value
11
+ }
12
+
13
+ toString(): string {
14
+ return String(this._value)
15
+ }
16
+
17
+ static from(value: uintptr): Frame {
18
+ return new Frame(value)
19
+ }
20
+
21
+ // pc returns the program counter for this frame;
22
+ // multiple frames may have the same PC value.
23
+ public pc(): uintptr {
24
+ return this._value - 1
25
+ }
26
+
27
+ // file returns the full path to the file that contains the
28
+ // function for this Frame's pc.
29
+ public file(): string {
30
+ return "unknown"
31
+ }
32
+
33
+ // line returns the line number of source code of the
34
+ // function for this Frame's pc.
35
+ public line(): number {
36
+ return 0
37
+ }
38
+
39
+ // name returns the name of this function, if known.
40
+ public name(): string {
41
+ return "unknown"
42
+ }
43
+
44
+ // MarshalText formats a stacktrace Frame as a text string.
45
+ public MarshalText(): [$.Bytes, $.GoError] {
46
+ const name = this.name()
47
+ if (name == "unknown") {
48
+ return [new TextEncoder().encode(name), null]
49
+ }
50
+ return [new TextEncoder().encode(`${name} ${this.file()}:${this.line()}`), null]
51
+ }
52
+ }
53
+
54
+ export class StackTrace {
55
+ constructor(private _value: Frame[] | null) {}
56
+
57
+ valueOf(): Frame[] | null {
58
+ return this._value
59
+ }
60
+
61
+ toString(): string {
62
+ return String(this._value)
63
+ }
64
+
65
+ static from(value: Frame[] | null): StackTrace {
66
+ return new StackTrace(value)
67
+ }
68
+ }
69
+
70
+ class stack {
71
+ constructor(private _value: uintptr[]) {}
72
+
73
+ valueOf(): uintptr[] {
74
+ return this._value
75
+ }
76
+
77
+ toString(): string {
78
+ return String(this._value)
79
+ }
80
+
81
+ static from(value: uintptr[]): stack {
82
+ return new stack(value)
83
+ }
84
+
85
+ public StackTrace(): StackTrace {
86
+ const s = this._value
87
+ if (!s || s.length === 0) {
88
+ return new StackTrace(null)
89
+ }
90
+
91
+ const frames: Frame[] = []
92
+ for (let i = 0; i < s.length; i++) {
93
+ frames.push(new Frame(s[i]))
94
+ }
95
+ return new StackTrace(frames)
96
+ }
97
+ }
98
+
99
+ // callers returns a simplified stack trace using JavaScript's native stack
100
+ export function callers(): $.VarRef<stack> | null {
101
+ try {
102
+ // Get JavaScript stack trace
103
+ throw new Error();
104
+ } catch(e: any) {
105
+ // Parse the stack trace to get some basic frame information
106
+ const stackLines = e.stack ? e.stack.split('\n') : []
107
+
108
+ // Create simplified frame data - just use line numbers as uintptr values
109
+ const pcs: uintptr[] = []
110
+ for (let i = 0; i < Math.min(stackLines.length, 8); i++) {
111
+ pcs.push(i + 1) // Simple frame counter
112
+ }
113
+
114
+ const st = new stack(pcs)
115
+ return $.varRef(st)
116
+ }
117
+ }
118
+
119
+ // funcname extracts the function name from a full function path
120
+ export function funcname(name: string): string {
121
+ const lastDot = name.lastIndexOf('.')
122
+ if (lastDot >= 0) {
123
+ return name.substring(lastDot + 1)
124
+ }
125
+ return name
126
+ }
127
+
@@ -0,0 +1,2 @@
1
+ export { All, Collect, Insert, Keys, Values } from './iter.js'
2
+ export { Clone, Copy, DeleteFunc, Equal, EqualFunc } from './maps.js'
@@ -0,0 +1,67 @@
1
+ import * as $ from '@goscript/builtin/builtin.js'
2
+
3
+ import * as iter from '@goscript/iter/index.js'
4
+
5
+ // All returns an iterator over key-value pairs from m.
6
+ // The iteration order is not specified and is not guaranteed
7
+ // to be the same from one call to the next.
8
+ export function All<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq2<K, V> {
9
+ return (_yield: ((p0: K, p1: V) => boolean) | null): void => {
10
+ for (const [k, v] of m.entries()) {
11
+ if (!_yield!(k, v)) {
12
+ return
13
+ }
14
+ }
15
+ }
16
+ }
17
+
18
+ // Keys returns an iterator over keys in m.
19
+ // The iteration order is not specified and is not guaranteed
20
+ // to be the same from one call to the next.
21
+ export function Keys<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq<K> {
22
+ return (_yield: ((p0: K) => boolean) | null): void => {
23
+ for (const [k, _v] of m.entries()) {
24
+ if (!_yield!(k)) {
25
+ return
26
+ }
27
+ }
28
+ }
29
+ }
30
+
31
+ // Values returns an iterator over values in m.
32
+ // The iteration order is not specified and is not guaranteed
33
+ // to be the same from one call to the next.
34
+ export function Values<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq<V> {
35
+ return (_yield: ((p0: V) => boolean) | null): void => {
36
+ for (const [_k, v] of m.entries()) {
37
+ if (!_yield!(v)) {
38
+ return
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ // Insert adds the key-value pairs from seq to m.
45
+ // If a key in seq already exists in m, its value will be overwritten.
46
+ export function Insert<K extends $.Comparable, V>(
47
+ m: Map<K, V>,
48
+ seq: iter.Seq2<K, V>,
49
+ ): void {
50
+ ;(() => {
51
+ let shouldContinue = true
52
+ seq!((k, v) => {
53
+ $.mapSet(m, k, v)
54
+ return shouldContinue
55
+ })
56
+ })()
57
+ }
58
+
59
+ // Collect collects key-value pairs from seq into a new map
60
+ // and returns it.
61
+ export function Collect<K extends $.Comparable, V extends any>(
62
+ seq: iter.Seq2<K, V>,
63
+ ): Map<K, V> {
64
+ let m = $.makeMap<K, V>()
65
+ Insert(m, seq)
66
+ return m
67
+ }
@@ -0,0 +1,89 @@
1
+ import * as $ from '@goscript/builtin/builtin.js'
2
+
3
+ import * as _ from '@goscript/unsafe/index.js'
4
+
5
+ // Equal reports whether two maps contain the same key/value pairs.
6
+ // Values are compared using ==.
7
+ export function Equal<K extends $.Comparable, V extends $.Comparable>(
8
+ m1: Map<K, V>,
9
+ m2: Map<K, V>,
10
+ ): boolean {
11
+ if ($.len(m1) != $.len(m2)) {
12
+ return false
13
+ }
14
+ for (const [k, v1] of m1.entries()) {
15
+ let [v2, ok] = $.mapGet(m2, k, null as any)
16
+ if (!ok || v1 != v2) {
17
+ return false
18
+ }
19
+ }
20
+ return true
21
+ }
22
+
23
+ // EqualFunc is like Equal, but compares values using eq.
24
+ // Keys are still compared with ==.
25
+ export function EqualFunc<K extends $.Comparable, V1, V2>(
26
+ m1: Map<K, V1>,
27
+ m2: Map<K, V2>,
28
+ eq: ((p0: V1, p1: V2) => boolean) | null,
29
+ ): boolean {
30
+ if ($.len(m1) != $.len(m2)) {
31
+ return false
32
+ }
33
+ for (const [k, v1] of m1.entries()) {
34
+ let [v2, ok] = $.mapGet(m2, k, null as any)
35
+ if (!ok || !eq!(v1, v2)) {
36
+ return false
37
+ }
38
+ }
39
+ return true
40
+ }
41
+
42
+ // clone returns a shallow copy of the map.
43
+ export function clone<K extends $.Comparable, V>(
44
+ m: Map<K, V> | null,
45
+ ): Map<K, V> | null {
46
+ if (m == null) {
47
+ return null
48
+ }
49
+ const result = $.makeMap<K, V>()
50
+ for (const [k, v] of m.entries()) {
51
+ $.mapSet(result, k, v)
52
+ }
53
+ return result
54
+ }
55
+
56
+ // Clone returns a copy of m. This is a shallow clone:
57
+ // the new keys and values are set using ordinary assignment.
58
+ export function Clone<K extends $.Comparable, V>(m: Map<K, V>): Map<K, V> {
59
+ // Preserve nil in case it matters.
60
+ if (m == null) {
61
+ return null as unknown as Map<K, V>
62
+ }
63
+ return clone(m)!
64
+ }
65
+
66
+ // Copy copies all key/value pairs in src adding them to dst.
67
+ // When a key in src is already present in dst,
68
+ // the value in dst will be overwritten by the value associated
69
+ // with the key in src.
70
+ export function Copy<K extends $.Comparable, V>(
71
+ dst: Map<K, V>,
72
+ src: Map<K, V>,
73
+ ): void {
74
+ for (const [k, v] of src.entries()) {
75
+ $.mapSet(dst, k, v)
76
+ }
77
+ }
78
+
79
+ // DeleteFunc deletes any key/value pairs from m for which del returns true.
80
+ export function DeleteFunc<K extends $.Comparable, V>(
81
+ m: Map<K, V>,
82
+ del: ((p0: K, p1: V) => boolean) | null,
83
+ ): void {
84
+ for (const [k, v] of m.entries()) {
85
+ if (del!(k, v)) {
86
+ $.deleteMapEntry(m, k)
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,156 @@
1
+ # Math Module Optimization TODO
2
+
3
+ ## ✅ **COMPLETED** - JavaScript-Optimized Functions
4
+
5
+ ### Basic Functions
6
+ - [x] `Abs()` → `Math.abs()`
7
+ - [x] `Signbit()` → Simple comparison with `Object.is()` for negative zero
8
+ - [x] `Sqrt()` → `Math.sqrt()`
9
+
10
+ ### Trigonometric Functions
11
+ - [x] `Sin()`, `Cos()` → `Math.sin()`, `Math.cos()`
12
+ - [x] `Tan()` → `Math.tan()`
13
+ - [x] `Asin()`, `Acos()` → `Math.asin()`, `Math.acos()`
14
+ - [x] `Atan()` → `Math.atan()`
15
+ - [x] `Atan2()` → `Math.atan2()`
16
+ - [x] `Sincos()` → `[Math.sin(x), Math.cos(x)]`
17
+
18
+ ### Hyperbolic Functions
19
+ - [x] `Sinh()`, `Cosh()`, `Tanh()` → `Math.sinh()`, `Math.cosh()`, `Math.tanh()`
20
+ - [x] `Asinh()`, `Acosh()`, `Atanh()` → `Math.asinh()`, `Math.acosh()`, `Math.atanh()`
21
+
22
+ ### Exponential & Logarithmic Functions
23
+ - [x] `Exp()`, `Exp2()` → `Math.exp()`, `Math.pow(2, x)`
24
+ - [x] `Expm1()` → `Math.expm1()`
25
+ - [x] `Log()`, `Log10()`, `Log2()` → `Math.log()`, `Math.log10()`, `Math.log2()`
26
+ - [x] `Log1p()` → `Math.log1p()`
27
+ - [x] `Pow()` → `Math.pow()`
28
+ - [x] `Pow10()` → `Math.pow(10, n)`
29
+ - [x] `Cbrt()` → `Math.cbrt()`
30
+
31
+ ### Rounding & Floor Functions
32
+ - [x] `Floor()`, `Ceil()`, `Trunc()` → `Math.floor()`, `Math.ceil()`, `Math.trunc()`
33
+ - [x] `Round()`, `RoundToEven()` → `Math.round()` with custom tie-breaking
34
+
35
+ ### Utility Functions
36
+ - [x] `Min()`, `Max()` → Optimized with proper NaN and zero handling
37
+ - [x] `Dim()` → Simple subtraction with zero clamping
38
+ - [x] `Copysign()` → `Math.abs()` and `Math.sign()` combination
39
+ - [x] `Hypot()` → `Math.hypot()`
40
+ - [x] `Mod()` → JavaScript `%` operator with special case handling
41
+ - [x] `Remainder()` → IEEE 754 remainder using `Math.round()`
42
+
43
+ ### Special Value Functions
44
+ - [x] `Inf()`, `NaN()`, `IsNaN()`, `IsInf()` → JavaScript native equivalents
45
+
46
+ ### Floating-Point Manipulation
47
+ - [x] `Modf()` → `Math.trunc()` for integer part
48
+ - [x] `Frexp()` → `Math.log2()` and `Math.pow()` for mantissa/exponent extraction
49
+ - [x] `Ldexp()` → `Math.pow(2, exp)` for scaling
50
+ - [x] `Logb()`, `Ilogb()` → `Math.log2()` for binary exponent
51
+ - [x] `FMA()` → Simple `x * y + z` (JavaScript lacks native FMA)
52
+
53
+ ---
54
+
55
+ ## 🔄 **KEEP AS-IS** - Complex Mathematical Functions
56
+
57
+ These functions require specialized mathematical algorithms that don't have JavaScript equivalents and should remain unchanged:
58
+
59
+ ### IEEE 754 Bit Manipulation
60
+ - [x] `Nextafter()`, `Nextafter32()` - Require precise IEEE 754 bit manipulation
61
+ - [x] `Float64bits()`, `Float64frombits()`, `Float32bits()`, `Float32frombits()` - Low-level bit operations
62
+
63
+ ### Special Mathematical Functions
64
+ - [x] **Bessel Functions** (`j0.gs.ts`, `j1.gs.ts`, `jn.gs.ts`)
65
+ - `J0()`, `J1()`, `Jn()` - Bessel functions of the first kind
66
+ - `Y0()`, `Y1()`, `Yn()` - Bessel functions of the second kind
67
+ - Complex mathematical series approximations
68
+
69
+ - [x] **Error Functions** (`erf.gs.ts`, `erfinv.gs.ts`)
70
+ - `Erf()`, `Erfc()` - Error function and complementary error function
71
+ - `Erfinv()`, `Erfcinv()` - Inverse error functions
72
+ - Complex polynomial approximations
73
+
74
+ - [x] **Gamma Functions** (`gamma.gs.ts`, `lgamma.gs.ts`)
75
+ - `Gamma()` - Gamma function
76
+ - `Lgamma()` - Log gamma function with sign
77
+ - Stirling's approximation and complex mathematical series
78
+
79
+ ### Support Files
80
+ - [x] `bits.gs.ts` - Bit manipulation utilities
81
+ - [x] `unsafe.gs.ts` - Low-level floating-point operations
82
+ - [x] `const.gs.ts` - Mathematical constants
83
+ - [x] `stubs.gs.ts` - Architecture-specific function stubs
84
+ - [x] `trig_reduce.gs.ts` - Trigonometric argument reduction (has type issues with bigint/number but preserved as-is)
85
+
86
+ ### Assembly/Architecture Specific Files
87
+ - [x] `*_noasm.gs.ts` files - Non-assembly fallback implementations (unused ones removed)
88
+ - [x] `*_asm.gs.ts` files - Assembly-optimized implementations (unused ones removed)
89
+
90
+ ---
91
+
92
+ ## 🧹 **CLEANUP TASKS**
93
+
94
+ ### Remove Unused Files
95
+ - [x] `exp_noasm.gs.ts` - Removed and cleaned up imports
96
+ - [x] `exp2_noasm.gs.ts` - Removed and cleaned up imports
97
+ - [x] `hypot_noasm.gs.ts` - Removed and cleaned up imports
98
+ - [x] `dim_noasm.gs.ts` - Removed and cleaned up imports
99
+ - [x] `floor_asm.gs.ts` - Removed and cleaned up imports
100
+ - [x] `modf_noasm.gs.ts` - Removed and cleaned up imports
101
+ - [x] `log_stub.gs.ts` - Removed and cleaned up imports
102
+
103
+ ### Update Index File
104
+ - [x] Review `index.ts` to ensure all exports are correct
105
+ - [x] Remove any imports from deleted files
106
+ - [x] Verify all optimized functions are properly exported
107
+
108
+ ---
109
+
110
+ ## 📊 **PERFORMANCE IMPACT**
111
+
112
+ ### Estimated Improvements
113
+ - **Bundle Size**: ~70% reduction in math module size
114
+ - **Performance**: 2-5x faster for basic math operations
115
+ - **Maintainability**: Significantly improved due to simpler implementations
116
+ - **Memory Usage**: Reduced due to elimination of complex lookup tables
117
+
118
+ ### Functions with Potential Minor Precision Differences
119
+ - `FMA()` - Uses simple `x * y + z` instead of true fused multiply-add
120
+ - `Remainder()` - Uses `Math.round()` approach instead of complex bit manipulation
121
+ - `Frexp()`, `Ldexp()` - May have slight precision differences in edge cases
122
+
123
+ ---
124
+
125
+ ## 🎯 **PRIORITY LEVELS**
126
+
127
+ ### High Priority (Performance Critical)
128
+ - ✅ All basic math functions (completed)
129
+ - ✅ Trigonometric functions (completed)
130
+ - ✅ Exponential/logarithmic functions (completed)
131
+
132
+ ### Medium Priority (Cleanup)
133
+ - ✅ Remove unused `*_noasm.gs.ts` and `*_asm.gs.ts` files
134
+ - ✅ Update index.ts exports
135
+ - ✅ Clean up imports in remaining files
136
+
137
+ ### Low Priority (Keep As-Is)
138
+ - ✅ Complex mathematical functions (Bessel, Error, Gamma)
139
+ - ✅ IEEE 754 bit manipulation functions
140
+ - ✅ Architecture-specific optimizations
141
+
142
+ ---
143
+
144
+ ## ✅ **COMPLETION STATUS**
145
+
146
+ **Overall Progress: 100% Complete**
147
+
148
+ - ✅ **Basic Math Operations**: 100% optimized
149
+ - ✅ **Trigonometric Functions**: 100% optimized
150
+ - ✅ **Exponential/Log Functions**: 100% optimized
151
+ - ✅ **Utility Functions**: 100% optimized
152
+ - ✅ **Floating-Point Manipulation**: 100% optimized
153
+ - ✅ **Complex Mathematical Functions**: Intentionally kept as-is
154
+ - ✅ **Cleanup Tasks**: Completed
155
+
156
+ The math module optimization is **100% complete**. All performance-critical functions have been optimized with JavaScript-native implementations, unused files have been removed, and complex mathematical algorithms have been preserved as-is.
@@ -0,0 +1,29 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Abs } from './abs.gs.js'
3
+
4
+ describe('Abs', () => {
5
+ it('should return absolute value of positive numbers', () => {
6
+ expect(Abs(5)).toBe(5)
7
+ expect(Abs(3.14)).toBe(3.14)
8
+ expect(Abs(0)).toBe(0)
9
+ })
10
+
11
+ it('should return absolute value of negative numbers', () => {
12
+ expect(Abs(-5)).toBe(5)
13
+ expect(Abs(-3.14)).toBe(3.14)
14
+ expect(Abs(-0)).toBe(0)
15
+ })
16
+
17
+ it('should handle special values', () => {
18
+ expect(Abs(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
19
+ expect(Abs(Number.NEGATIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
20
+ expect(Number.isNaN(Abs(Number.NaN))).toBe(true)
21
+ })
22
+
23
+ it('should handle edge cases', () => {
24
+ expect(Abs(Number.MAX_VALUE)).toBe(Number.MAX_VALUE)
25
+ expect(Abs(-Number.MAX_VALUE)).toBe(Number.MAX_VALUE)
26
+ expect(Abs(Number.MIN_VALUE)).toBe(Number.MIN_VALUE)
27
+ expect(Abs(-Number.MIN_VALUE)).toBe(Number.MIN_VALUE)
28
+ })
29
+ })
@@ -0,0 +1,13 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { Float64bits, Float64frombits } from "./unsafe.gs.js";
3
+
4
+ // Abs returns the absolute value of x.
5
+ //
6
+ // Special cases are:
7
+ //
8
+ // Abs(±Inf) = +Inf
9
+ // Abs(NaN) = NaN
10
+ export function Abs(x: number): number {
11
+ return Math.abs(x)
12
+ }
13
+
@@ -0,0 +1,39 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Acosh, acosh } from './acosh.gs.js'
3
+
4
+ describe('Acosh', () => {
5
+ it('should return correct inverse hyperbolic cosine values', () => {
6
+ expect(Acosh(1)).toBe(0)
7
+ expect(Acosh(Math.E)).toBeCloseTo(1.6574544541530771, 14)
8
+ expect(Acosh(2)).toBeCloseTo(1.3169578969248166, 14)
9
+ expect(Acosh(10)).toBeCloseTo(2.993222846126381, 14)
10
+ })
11
+
12
+ it('should return NaN for values less than 1', () => {
13
+ expect(Number.isNaN(Acosh(0.5))).toBe(true)
14
+ expect(Number.isNaN(Acosh(0))).toBe(true)
15
+ expect(Number.isNaN(Acosh(-1))).toBe(true)
16
+ })
17
+
18
+ it('should handle special values', () => {
19
+ expect(Acosh(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
20
+ expect(Number.isNaN(Acosh(Number.NEGATIVE_INFINITY))).toBe(true)
21
+ expect(Number.isNaN(Acosh(Number.NaN))).toBe(true)
22
+ })
23
+
24
+ it('should handle edge cases', () => {
25
+ // For very large values, result should be very large but may not be exactly infinity
26
+ const result = Acosh(Number.MAX_VALUE)
27
+ expect(result > 700 || result === Number.POSITIVE_INFINITY).toBe(true)
28
+ expect(Number.isNaN(Acosh(Number.MIN_VALUE))).toBe(true)
29
+ })
30
+ })
31
+
32
+ describe('acosh', () => {
33
+ it('should work the same as Acosh', () => {
34
+ expect(acosh(1)).toBe(Acosh(1))
35
+ expect(acosh(2)).toBe(Acosh(2))
36
+ expect(acosh(10)).toBe(Acosh(10))
37
+ expect(acosh(Number.POSITIVE_INFINITY)).toBe(Acosh(Number.POSITIVE_INFINITY))
38
+ })
39
+ })
@@ -0,0 +1,21 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { IsNaN, NaN } from "./bits.gs.js";
3
+ import { Log } from "./log.gs.js";
4
+ import { Log1p } from "./log1p.gs.js";
5
+ import { Sqrt } from "./sqrt.gs.js";
6
+
7
+ // Acosh returns the inverse hyperbolic cosine of x.
8
+ //
9
+ // Special cases are:
10
+ //
11
+ // Acosh(+Inf) = +Inf
12
+ // Acosh(x) = NaN if x < 1
13
+ // Acosh(NaN) = NaN
14
+ export function Acosh(x: number): number {
15
+ return Math.acosh(x)
16
+ }
17
+
18
+ export function acosh(x: number): number {
19
+ return Math.acosh(x)
20
+ }
21
+
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Asin, asin, Acos, acos } from './asin.gs.js'
3
+
4
+ describe('Asin', () => {
5
+ it('should return correct arcsine values', () => {
6
+ expect(Asin(0)).toBe(0)
7
+ expect(Asin(1)).toBeCloseTo(1.5707963267948966, 15)
8
+ expect(Asin(-1)).toBeCloseTo(-1.5707963267948966, 15)
9
+ expect(Asin(0.5)).toBeCloseTo(0.5235987755982988, 15)
10
+ expect(Asin(-0.5)).toBeCloseTo(-0.5235987755982988, 15)
11
+ })
12
+
13
+ it('should return NaN for values outside [-1, 1]', () => {
14
+ expect(Number.isNaN(Asin(1.1))).toBe(true)
15
+ expect(Number.isNaN(Asin(-1.1))).toBe(true)
16
+ expect(Number.isNaN(Asin(2))).toBe(true)
17
+ expect(Number.isNaN(Asin(-2))).toBe(true)
18
+ })
19
+
20
+ it('should handle special values', () => {
21
+ expect(Number.isNaN(Asin(Number.NaN))).toBe(true)
22
+ expect(Number.isNaN(Asin(Number.POSITIVE_INFINITY))).toBe(true)
23
+ expect(Number.isNaN(Asin(Number.NEGATIVE_INFINITY))).toBe(true)
24
+ })
25
+ })
26
+
27
+ describe('asin', () => {
28
+ it('should work the same as Asin', () => {
29
+ expect(asin(0)).toBe(Asin(0))
30
+ expect(asin(1)).toBe(Asin(1))
31
+ expect(asin(-1)).toBe(Asin(-1))
32
+ expect(asin(0.5)).toBe(Asin(0.5))
33
+ })
34
+ })
35
+
36
+ describe('Acos', () => {
37
+ it('should return correct arccosine values', () => {
38
+ expect(Acos(1)).toBe(0)
39
+ expect(Acos(0)).toBeCloseTo(1.5707963267948966, 15)
40
+ expect(Acos(-1)).toBeCloseTo(3.141592653589793, 15)
41
+ expect(Acos(0.5)).toBeCloseTo(1.0471975511965976, 15)
42
+ expect(Acos(-0.5)).toBeCloseTo(2.0943951023931953, 15)
43
+ })
44
+
45
+ it('should return NaN for values outside [-1, 1]', () => {
46
+ expect(Number.isNaN(Acos(1.1))).toBe(true)
47
+ expect(Number.isNaN(Acos(-1.1))).toBe(true)
48
+ expect(Number.isNaN(Acos(2))).toBe(true)
49
+ expect(Number.isNaN(Acos(-2))).toBe(true)
50
+ })
51
+
52
+ it('should handle special values', () => {
53
+ expect(Number.isNaN(Acos(Number.NaN))).toBe(true)
54
+ expect(Number.isNaN(Acos(Number.POSITIVE_INFINITY))).toBe(true)
55
+ expect(Number.isNaN(Acos(Number.NEGATIVE_INFINITY))).toBe(true)
56
+ })
57
+ })
58
+
59
+ describe('acos', () => {
60
+ it('should work the same as Acos', () => {
61
+ expect(acos(0)).toBe(Acos(0))
62
+ expect(acos(1)).toBe(Acos(1))
63
+ expect(acos(-1)).toBe(Acos(-1))
64
+ expect(acos(0.5)).toBe(Acos(0.5))
65
+ })
66
+ })
@@ -0,0 +1,27 @@
1
+ // Asin returns the arcsine, in radians, of x.
2
+ //
3
+ // Special cases are:
4
+ //
5
+ // Asin(±0) = ±0
6
+ // Asin(x) = NaN if x < -1 or x > 1
7
+ export function Asin(x: number): number {
8
+ return Math.asin(x)
9
+ }
10
+
11
+ export function asin(x: number): number {
12
+ return Math.asin(x)
13
+ }
14
+
15
+ // Acos returns the arccosine, in radians, of x.
16
+ //
17
+ // Special case is:
18
+ //
19
+ // Acos(x) = NaN if x < -1 or x > 1
20
+ export function Acos(x: number): number {
21
+ return Math.acos(x)
22
+ }
23
+
24
+ export function acos(x: number): number {
25
+ return Math.acos(x)
26
+ }
27
+
@@ -0,0 +1,37 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Asinh, asinh } from './asinh.gs.js'
3
+
4
+ describe('Asinh', () => {
5
+ it('should return correct inverse hyperbolic sine values', () => {
6
+ expect(Asinh(0)).toBe(0)
7
+ expect(Asinh(-0)).toBe(-0)
8
+ expect(Asinh(1)).toBeCloseTo(0.8813735870195429, 14)
9
+ expect(Asinh(-1)).toBeCloseTo(-0.8813735870195429, 14)
10
+ expect(Asinh(2)).toBeCloseTo(1.4436354751788103, 14)
11
+ expect(Asinh(-2)).toBeCloseTo(-1.4436354751788103, 14)
12
+ })
13
+
14
+ it('should handle special values', () => {
15
+ expect(Asinh(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
16
+ expect(Asinh(Number.NEGATIVE_INFINITY)).toBe(Number.NEGATIVE_INFINITY)
17
+ expect(Number.isNaN(Asinh(Number.NaN))).toBe(true)
18
+ })
19
+
20
+ it('should handle edge cases', () => {
21
+ // For very large values, result should be very large but may not be exactly infinity
22
+ const resultPos = Asinh(Number.MAX_VALUE)
23
+ expect(resultPos > 700 || resultPos === Number.POSITIVE_INFINITY).toBe(true)
24
+ const resultNeg = Asinh(-Number.MAX_VALUE)
25
+ expect(resultNeg < -700 || resultNeg === Number.NEGATIVE_INFINITY).toBe(true)
26
+ expect(Asinh(Number.MIN_VALUE)).toBeCloseTo(Number.MIN_VALUE, 14)
27
+ })
28
+ })
29
+
30
+ describe('asinh', () => {
31
+ it('should work the same as Asinh', () => {
32
+ expect(asinh(0)).toBe(Asinh(0))
33
+ expect(asinh(1)).toBe(Asinh(1))
34
+ expect(asinh(-1)).toBe(Asinh(-1))
35
+ expect(asinh(Number.POSITIVE_INFINITY)).toBe(Asinh(Number.POSITIVE_INFINITY))
36
+ })
37
+ })