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,21 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { IsInf, IsNaN } 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
+ // Asinh returns the inverse hyperbolic sine of x.
8
+ //
9
+ // Special cases are:
10
+ //
11
+ // Asinh(±0) = ±0
12
+ // Asinh(±Inf) = ±Inf
13
+ // Asinh(NaN) = NaN
14
+ export function Asinh(x: number): number {
15
+ return Math.asinh(x)
16
+ }
17
+
18
+ export function asinh(x: number): number {
19
+ return Math.asinh(x)
20
+ }
21
+
@@ -0,0 +1,49 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Atan, atan, xatan, satan } from './atan.gs.js'
3
+
4
+ describe('Atan', () => {
5
+ it('should return correct arctangent values', () => {
6
+ expect(Atan(0)).toBe(0)
7
+ expect(Atan(1)).toBeCloseTo(0.7853981633974483, 15)
8
+ expect(Atan(-1)).toBeCloseTo(-0.7853981633974483, 15)
9
+ expect(Atan(Math.sqrt(3))).toBeCloseTo(Math.PI / 3, 15)
10
+ expect(Atan(1 / Math.sqrt(3))).toBeCloseTo(Math.PI / 6, 15)
11
+ })
12
+
13
+ it('should handle special values', () => {
14
+ expect(Atan(Number.POSITIVE_INFINITY)).toBeCloseTo(Math.PI / 2, 15)
15
+ expect(Atan(Number.NEGATIVE_INFINITY)).toBeCloseTo(-Math.PI / 2, 15)
16
+ expect(Number.isNaN(Atan(Number.NaN))).toBe(true)
17
+ })
18
+
19
+ it('should handle edge cases', () => {
20
+ expect(Atan(Number.MAX_VALUE)).toBeCloseTo(Math.PI / 2, 15)
21
+ expect(Atan(-Number.MAX_VALUE)).toBeCloseTo(-Math.PI / 2, 15)
22
+ expect(Atan(Number.MIN_VALUE)).toBeCloseTo(Number.MIN_VALUE, 15)
23
+ })
24
+ })
25
+
26
+ describe('atan', () => {
27
+ it('should work the same as Atan', () => {
28
+ expect(atan(0)).toBe(Atan(0))
29
+ expect(atan(1)).toBe(Atan(1))
30
+ expect(atan(-1)).toBe(Atan(-1))
31
+ expect(atan(Number.POSITIVE_INFINITY)).toBe(Atan(Number.POSITIVE_INFINITY))
32
+ })
33
+ })
34
+
35
+ describe('xatan', () => {
36
+ it('should work for values in range [0, 0.66]', () => {
37
+ expect(xatan(0)).toBe(0)
38
+ expect(xatan(0.5)).toBeCloseTo(Math.atan(0.5), 15)
39
+ expect(xatan(0.66)).toBeCloseTo(Math.atan(0.66), 15)
40
+ })
41
+ })
42
+
43
+ describe('satan', () => {
44
+ it('should work for positive values', () => {
45
+ expect(satan(0)).toBe(0)
46
+ expect(satan(1)).toBeCloseTo(Math.atan(1), 15)
47
+ expect(satan(2)).toBeCloseTo(Math.atan(2), 15)
48
+ })
49
+ })
@@ -0,0 +1,27 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+
3
+ // xatan evaluates a series valid in the range [0, 0.66].
4
+ export function xatan(x: number): number {
5
+ return Math.atan(x)
6
+ }
7
+
8
+ // satan reduces its argument (known to be positive)
9
+ // to the range [0, 0.66] and calls xatan.
10
+ export function satan(x: number): number {
11
+ return Math.atan(x)
12
+ }
13
+
14
+ // Atan returns the arctangent, in radians, of x.
15
+ //
16
+ // Special cases are:
17
+ //
18
+ // Atan(±0) = ±0
19
+ // Atan(±Inf) = ±Pi/2
20
+ export function Atan(x: number): number {
21
+ return Math.atan(x)
22
+ }
23
+
24
+ export function atan(x: number): number {
25
+ return Math.atan(x)
26
+ }
27
+
@@ -0,0 +1,55 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Atan2, atan2 } from './atan2.gs.js'
3
+
4
+ describe('Atan2', () => {
5
+ it('should return correct arctangent values for basic cases', () => {
6
+ expect(Atan2(1, 1)).toBeCloseTo(Math.PI / 4, 15)
7
+ expect(Atan2(1, -1)).toBeCloseTo(3 * Math.PI / 4, 15)
8
+ expect(Atan2(-1, 1)).toBeCloseTo(-Math.PI / 4, 15)
9
+ expect(Atan2(-1, -1)).toBeCloseTo(-3 * Math.PI / 4, 15)
10
+ })
11
+
12
+ it('should handle zero cases correctly', () => {
13
+ expect(Atan2(0, 1)).toBe(0)
14
+ expect(Atan2(0, -1)).toBeCloseTo(Math.PI, 15)
15
+ expect(Atan2(1, 0)).toBeCloseTo(Math.PI / 2, 15)
16
+ expect(Atan2(-1, 0)).toBeCloseTo(-Math.PI / 2, 15)
17
+ })
18
+
19
+ it('should handle infinity cases', () => {
20
+ expect(Atan2(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)).toBeCloseTo(Math.PI / 4, 15)
21
+ expect(Atan2(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY)).toBeCloseTo(-Math.PI / 4, 15)
22
+ expect(Atan2(Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY)).toBeCloseTo(3 * Math.PI / 4, 15)
23
+ expect(Atan2(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY)).toBeCloseTo(-3 * Math.PI / 4, 15)
24
+
25
+ expect(Atan2(1, Number.POSITIVE_INFINITY)).toBe(0)
26
+ expect(Atan2(1, Number.NEGATIVE_INFINITY)).toBeCloseTo(Math.PI, 15)
27
+ expect(Atan2(-1, Number.NEGATIVE_INFINITY)).toBeCloseTo(-Math.PI, 15)
28
+
29
+ expect(Atan2(Number.POSITIVE_INFINITY, 1)).toBeCloseTo(Math.PI / 2, 15)
30
+ expect(Atan2(Number.NEGATIVE_INFINITY, 1)).toBeCloseTo(-Math.PI / 2, 15)
31
+ })
32
+
33
+ it('should handle NaN cases', () => {
34
+ expect(Number.isNaN(Atan2(Number.NaN, 1))).toBe(true)
35
+ expect(Number.isNaN(Atan2(1, Number.NaN))).toBe(true)
36
+ expect(Number.isNaN(Atan2(Number.NaN, Number.NaN))).toBe(true)
37
+ })
38
+
39
+ it('should handle signed zero correctly', () => {
40
+ expect(Atan2(0, 1)).toBe(0)
41
+ expect(Atan2(-0, 1)).toBe(-0)
42
+ expect(Atan2(0, -1)).toBeCloseTo(Math.PI, 15)
43
+ expect(Atan2(-0, -1)).toBeCloseTo(-Math.PI, 15)
44
+ })
45
+ })
46
+
47
+ describe('atan2', () => {
48
+ it('should work the same as Atan2', () => {
49
+ expect(atan2(1, 1)).toBe(Atan2(1, 1))
50
+ expect(atan2(1, -1)).toBe(Atan2(1, -1))
51
+ expect(atan2(-1, 1)).toBe(Atan2(-1, 1))
52
+ expect(atan2(-1, -1)).toBe(Atan2(-1, -1))
53
+ expect(atan2(0, 1)).toBe(Atan2(0, 1))
54
+ })
55
+ })
@@ -0,0 +1,37 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { Atan } from "./atan.gs.js";
3
+ import { IsInf, IsNaN, NaN } from "./bits.gs.js";
4
+ import { Copysign } from "./copysign.gs.js";
5
+ import { Signbit } from "./signbit.gs.js";
6
+
7
+ // Atan2 returns the arc tangent of y/x, using
8
+ // the signs of the two to determine the quadrant
9
+ // of the return value.
10
+ //
11
+ // Special cases are (in order):
12
+ //
13
+ // Atan2(y, NaN) = NaN
14
+ // Atan2(NaN, x) = NaN
15
+ // Atan2(+0, x>=0) = +0
16
+ // Atan2(-0, x>=0) = -0
17
+ // Atan2(+0, x<=-0) = +Pi
18
+ // Atan2(-0, x<=-0) = -Pi
19
+ // Atan2(y>0, 0) = +Pi/2
20
+ // Atan2(y<0, 0) = -Pi/2
21
+ // Atan2(+Inf, +Inf) = +Pi/4
22
+ // Atan2(-Inf, +Inf) = -Pi/4
23
+ // Atan2(+Inf, -Inf) = 3Pi/4
24
+ // Atan2(-Inf, -Inf) = -3Pi/4
25
+ // Atan2(y, +Inf) = 0
26
+ // Atan2(y>0, -Inf) = +Pi
27
+ // Atan2(y<0, -Inf) = -Pi
28
+ // Atan2(+Inf, x) = +Pi/2
29
+ // Atan2(-Inf, x) = -Pi/2
30
+ export function Atan2(y: number, x: number): number {
31
+ return Math.atan2(y, x)
32
+ }
33
+
34
+ export function atan2(y: number, x: number): number {
35
+ return Math.atan2(y, x)
36
+ }
37
+
@@ -0,0 +1,47 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Atanh, atanh } from './atanh.gs.js'
3
+
4
+ describe('Atanh', () => {
5
+ it('should return correct inverse hyperbolic tangent values', () => {
6
+ expect(Atanh(0)).toBe(0)
7
+ expect(Atanh(-0)).toBe(-0)
8
+ expect(Atanh(0.5)).toBeCloseTo(0.5493061443340549, 15)
9
+ expect(Atanh(-0.5)).toBeCloseTo(-0.5493061443340549, 15)
10
+ expect(Atanh(0.9)).toBeCloseTo(1.4722194895832204, 15)
11
+ expect(Atanh(-0.9)).toBeCloseTo(-1.4722194895832204, 15)
12
+ })
13
+
14
+ it('should return infinity for boundary values', () => {
15
+ expect(Atanh(1)).toBe(Number.POSITIVE_INFINITY)
16
+ expect(Atanh(-1)).toBe(Number.NEGATIVE_INFINITY)
17
+ })
18
+
19
+ it('should return NaN for values outside [-1, 1]', () => {
20
+ expect(Number.isNaN(Atanh(1.1))).toBe(true)
21
+ expect(Number.isNaN(Atanh(-1.1))).toBe(true)
22
+ expect(Number.isNaN(Atanh(2))).toBe(true)
23
+ expect(Number.isNaN(Atanh(-2))).toBe(true)
24
+ })
25
+
26
+ it('should handle special values', () => {
27
+ expect(Number.isNaN(Atanh(Number.POSITIVE_INFINITY))).toBe(true)
28
+ expect(Number.isNaN(Atanh(Number.NEGATIVE_INFINITY))).toBe(true)
29
+ expect(Number.isNaN(Atanh(Number.NaN))).toBe(true)
30
+ })
31
+
32
+ it('should handle edge cases', () => {
33
+ expect(Number.isNaN(Atanh(Number.MAX_VALUE))).toBe(true)
34
+ expect(Number.isNaN(Atanh(-Number.MAX_VALUE))).toBe(true)
35
+ expect(Atanh(Number.MIN_VALUE)).toBeCloseTo(Number.MIN_VALUE, 15)
36
+ })
37
+ })
38
+
39
+ describe('atanh', () => {
40
+ it('should work the same as Atanh', () => {
41
+ expect(atanh(0)).toBe(Atanh(0))
42
+ expect(atanh(0.5)).toBe(Atanh(0.5))
43
+ expect(atanh(-0.5)).toBe(Atanh(-0.5))
44
+ expect(atanh(1)).toBe(Atanh(1))
45
+ expect(atanh(-1)).toBe(Atanh(-1))
46
+ })
47
+ })
@@ -0,0 +1,21 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { Inf, IsNaN, NaN } from "./bits.gs.js";
3
+ import { Log1p } from "./log1p.gs.js";
4
+
5
+ // Atanh returns the inverse hyperbolic tangent of x.
6
+ //
7
+ // Special cases are:
8
+ //
9
+ // Atanh(1) = +Inf
10
+ // Atanh(±0) = ±0
11
+ // Atanh(-1) = -Inf
12
+ // Atanh(x) = NaN if x < -1 or x > 1
13
+ // Atanh(NaN) = NaN
14
+ export function Atanh(x: number): number {
15
+ return Math.atanh(x)
16
+ }
17
+
18
+ export function atanh(x: number): number {
19
+ return Math.atanh(x)
20
+ }
21
+
@@ -0,0 +1,88 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Inf, NaN as MathNaN, IsNaN, IsInf, normalize } from './bits.gs.js'
3
+
4
+ describe('Inf', () => {
5
+ it('should return positive infinity for positive sign', () => {
6
+ expect(Inf(1)).toBe(Number.POSITIVE_INFINITY)
7
+ expect(Inf(100)).toBe(Number.POSITIVE_INFINITY)
8
+ })
9
+
10
+ it('should return negative infinity for negative sign', () => {
11
+ expect(Inf(-1)).toBe(Number.NEGATIVE_INFINITY)
12
+ expect(Inf(-100)).toBe(Number.NEGATIVE_INFINITY)
13
+ })
14
+
15
+ it('should return positive infinity for zero sign', () => {
16
+ expect(Inf(0)).toBe(Number.POSITIVE_INFINITY)
17
+ })
18
+ })
19
+
20
+ describe('NaN', () => {
21
+ it('should return NaN', () => {
22
+ expect(Number.isNaN(MathNaN())).toBe(true)
23
+ })
24
+ })
25
+
26
+ describe('IsNaN', () => {
27
+ it('should identify NaN correctly', () => {
28
+ expect(IsNaN(Number.NaN)).toBe(true)
29
+ expect(IsNaN(MathNaN())).toBe(true)
30
+ })
31
+
32
+ it('should return false for non-NaN values', () => {
33
+ expect(IsNaN(0)).toBe(false)
34
+ expect(IsNaN(1)).toBe(false)
35
+ expect(IsNaN(-1)).toBe(false)
36
+ expect(IsNaN(Number.POSITIVE_INFINITY)).toBe(false)
37
+ expect(IsNaN(Number.NEGATIVE_INFINITY)).toBe(false)
38
+ })
39
+ })
40
+
41
+ describe('IsInf', () => {
42
+ it('should identify positive infinity when sign > 0', () => {
43
+ expect(IsInf(Number.POSITIVE_INFINITY, 1)).toBe(true)
44
+ expect(IsInf(Number.NEGATIVE_INFINITY, 1)).toBe(false)
45
+ expect(IsInf(1, 1)).toBe(false)
46
+ })
47
+
48
+ it('should identify negative infinity when sign < 0', () => {
49
+ expect(IsInf(Number.NEGATIVE_INFINITY, -1)).toBe(true)
50
+ expect(IsInf(Number.POSITIVE_INFINITY, -1)).toBe(false)
51
+ expect(IsInf(-1, -1)).toBe(false)
52
+ })
53
+
54
+ it('should identify any infinity when sign == 0', () => {
55
+ expect(IsInf(Number.POSITIVE_INFINITY, 0)).toBe(true)
56
+ expect(IsInf(Number.NEGATIVE_INFINITY, 0)).toBe(true)
57
+ expect(IsInf(1, 0)).toBe(false)
58
+ expect(IsInf(Number.NaN, 0)).toBe(false)
59
+ })
60
+ })
61
+
62
+ describe('normalize', () => {
63
+ it('should return input for normal numbers', () => {
64
+ const [y, exp] = normalize(1.5)
65
+ expect(y).toBe(1.5)
66
+ expect(exp).toBe(0)
67
+ })
68
+
69
+ it('should normalize subnormal numbers', () => {
70
+ const smallValue = 1e-320 // A subnormal number
71
+ const [y, exp] = normalize(smallValue)
72
+ expect(Math.abs(y)).toBeCloseTo(smallValue * Math.pow(2, 52), 10)
73
+ expect(exp).toBe(-52)
74
+ expect(y * Math.pow(2, exp)).toBeCloseTo(smallValue, 300)
75
+ })
76
+
77
+ it('should handle negative values', () => {
78
+ const [y, exp] = normalize(-1.5)
79
+ expect(y).toBe(-1.5)
80
+ expect(exp).toBe(0)
81
+ })
82
+
83
+ it('should handle zero', () => {
84
+ const [y, exp] = normalize(0)
85
+ expect(y).toBe(0)
86
+ expect(exp).toBe(-52)
87
+ })
88
+ })
@@ -0,0 +1,61 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { Abs } from "./abs.gs.js";
3
+ import { Float64frombits } from "./unsafe.gs.js";
4
+
5
+ let uvnan: number = 0x7FF8000000000001
6
+
7
+ let uvinf: number = 0x7FF0000000000000
8
+
9
+ let uvneginf: number = 0xFFF0000000000000
10
+
11
+ let uvone: number = 0x3FF0000000000000
12
+
13
+ let mask: number = 0x7FF
14
+
15
+ let shift: number = 64 - 11 - 1
16
+
17
+ let bias: number = 1023
18
+
19
+ let signMask: number = Number.MAX_SAFE_INTEGER
20
+
21
+ let fracMask: number = (1 << 52) - 1
22
+
23
+ // Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.
24
+ export function Inf(sign: number): number {
25
+ return sign >= 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY
26
+ }
27
+
28
+ // NaN returns an IEEE 754 "not-a-number" value.
29
+ export function NaN(): number {
30
+ return Number.NaN
31
+ }
32
+
33
+ // IsNaN reports whether f is an IEEE 754 "not-a-number" value.
34
+ export function IsNaN(f: number): boolean {
35
+ return Number.isNaN(f)
36
+ }
37
+
38
+ // IsInf reports whether f is an infinity, according to sign.
39
+ // If sign > 0, IsInf reports whether f is positive infinity.
40
+ // If sign < 0, IsInf reports whether f is negative infinity.
41
+ // If sign == 0, IsInf reports whether f is either infinity.
42
+ export function IsInf(f: number, sign: number): boolean {
43
+ if (sign > 0) {
44
+ return f === Number.POSITIVE_INFINITY
45
+ } else if (sign < 0) {
46
+ return f === Number.NEGATIVE_INFINITY
47
+ } else {
48
+ return !Number.isFinite(f) && !Number.isNaN(f)
49
+ }
50
+ }
51
+
52
+ // normalize returns a normal number y and exponent exp
53
+ // satisfying x == y × 2**exp. It assumes x is finite and non-zero.
54
+ export function normalize(x: number): [number, number] {
55
+ const SmallestNormal = 2.2250738585072014e-308
56
+ if (Math.abs(x) < SmallestNormal) {
57
+ return [x * (1 << 52), -52]
58
+ }
59
+ return [x, 0]
60
+ }
61
+
@@ -0,0 +1,57 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Cbrt, cbrt } from './cbrt.gs.js'
3
+
4
+ describe('Cbrt', () => {
5
+ it('should return correct cube root values', () => {
6
+ expect(Cbrt(0)).toBe(0)
7
+ expect(Cbrt(-0)).toBe(-0)
8
+ expect(Cbrt(1)).toBe(1)
9
+ expect(Cbrt(8)).toBe(2)
10
+ expect(Cbrt(27)).toBe(3)
11
+ expect(Cbrt(64)).toBe(4)
12
+ expect(Cbrt(125)).toBe(5)
13
+ })
14
+
15
+ it('should handle negative values', () => {
16
+ expect(Cbrt(-1)).toBe(-1)
17
+ expect(Cbrt(-8)).toBe(-2)
18
+ expect(Cbrt(-27)).toBe(-3)
19
+ expect(Cbrt(-64)).toBe(-4)
20
+ expect(Cbrt(-125)).toBe(-5)
21
+ })
22
+
23
+ it('should handle fractional values', () => {
24
+ expect(Cbrt(0.125)).toBeCloseTo(0.5, 14)
25
+ expect(Cbrt(0.001)).toBeCloseTo(0.1, 14)
26
+ expect(Cbrt(2)).toBeCloseTo(1.2599210498948732, 15)
27
+ expect(Cbrt(3)).toBeCloseTo(1.4422495703074083, 15)
28
+ })
29
+
30
+ it('should handle special values', () => {
31
+ expect(Cbrt(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
32
+ expect(Cbrt(Number.NEGATIVE_INFINITY)).toBe(Number.NEGATIVE_INFINITY)
33
+ expect(Number.isNaN(Cbrt(Number.NaN))).toBe(true)
34
+ })
35
+
36
+ it('should handle edge cases', () => {
37
+ expect(Cbrt(Number.MAX_VALUE)).toBeCloseTo(5.643803094122362e102, 90)
38
+ expect(Cbrt(Number.MIN_VALUE)).toBeCloseTo(3.725290298461914e-109, 100)
39
+ expect(Cbrt(-Number.MAX_VALUE)).toBeCloseTo(-5.643803094122362e102, 90)
40
+ })
41
+
42
+ it('should handle very small values', () => {
43
+ expect(Cbrt(1e-100)).toBeCloseTo(2.154434690031884e-34, 30)
44
+ expect(Cbrt(-1e-100)).toBeCloseTo(-2.154434690031884e-34, 30)
45
+ })
46
+ })
47
+
48
+ describe('cbrt', () => {
49
+ it('should work the same as Cbrt', () => {
50
+ expect(cbrt(0)).toBe(Cbrt(0))
51
+ expect(cbrt(1)).toBe(Cbrt(1))
52
+ expect(cbrt(8)).toBe(Cbrt(8))
53
+ expect(cbrt(-8)).toBe(Cbrt(-8))
54
+ expect(cbrt(Number.POSITIVE_INFINITY)).toBe(Cbrt(Number.POSITIVE_INFINITY))
55
+ expect(cbrt(0.125)).toBe(Cbrt(0.125))
56
+ })
57
+ })
@@ -0,0 +1,20 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { IsInf, IsNaN } from "./bits.gs.js";
3
+
4
+ import { Float64bits, Float64frombits } from "./unsafe.gs.js";
5
+
6
+ // Cbrt returns the cube root of x.
7
+ //
8
+ // Special cases are:
9
+ //
10
+ // Cbrt(±0) = ±0
11
+ // Cbrt(±Inf) = ±Inf
12
+ // Cbrt(NaN) = NaN
13
+ export function Cbrt(x: number): number {
14
+ return Math.cbrt(x)
15
+ }
16
+
17
+ export function cbrt(x: number): number {
18
+ return Math.cbrt(x)
19
+ }
20
+
@@ -0,0 +1,54 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ E, Pi, Phi, Sqrt2, SqrtE, SqrtPi, SqrtPhi, Ln2, Log2E, Ln10, Log10E,
4
+ MaxFloat32, SmallestNonzeroFloat32, MaxFloat64, SmallestNonzeroFloat64,
5
+ MaxInt, MinInt, MaxInt8, MinInt8, MaxInt16, MinInt16, MaxInt32, MinInt32,
6
+ MaxInt64, MinInt64, MaxUint, MaxUint8, MaxUint16, MaxUint32, MaxUint64
7
+ } from './const.gs.js'
8
+
9
+ describe('Mathematical Constants', () => {
10
+ it('should have correct mathematical constants', () => {
11
+ expect(E).toBe(Math.E)
12
+ expect(Pi).toBe(Math.PI)
13
+ expect(Sqrt2).toBe(Math.SQRT2)
14
+ expect(SqrtE).toBe(Math.sqrt(Math.E))
15
+ expect(SqrtPi).toBe(Math.sqrt(Math.PI))
16
+ expect(Ln2).toBe(Math.LN2)
17
+ expect(Log2E).toBe(Math.LOG2E)
18
+ expect(Ln10).toBe(Math.LN10)
19
+ expect(Log10E).toBe(Math.LOG10E)
20
+ })
21
+
22
+ it('should have correct Phi (golden ratio)', () => {
23
+ expect(Phi).toBeCloseTo(1.618033988749895, 15)
24
+ expect(SqrtPhi).toBeCloseTo(Math.sqrt(1.618033988749895), 15)
25
+ })
26
+
27
+ it('should have correct float limits', () => {
28
+ expect(MaxFloat32).toBe(3.4028234663852886e+38)
29
+ expect(SmallestNonzeroFloat32).toBe(1.401298464324817e-45)
30
+ expect(MaxFloat64).toBe(Number.MAX_VALUE)
31
+ expect(SmallestNonzeroFloat64).toBe(Number.MIN_VALUE)
32
+ })
33
+
34
+ it('should have correct integer limits', () => {
35
+ expect(MaxInt8).toBe(127)
36
+ expect(MinInt8).toBe(-128)
37
+ expect(MaxInt16).toBe(32767)
38
+ expect(MinInt16).toBe(-32768)
39
+ expect(MaxInt32).toBe(2147483647)
40
+ expect(MinInt32).toBe(-2147483648)
41
+ expect(MaxUint8).toBe(255)
42
+ expect(MaxUint16).toBe(65535)
43
+ expect(MaxUint32).toBe(4294967295)
44
+ })
45
+
46
+ it('should have correct bigint limits', () => {
47
+ expect(MaxInt).toBe(9223372036854775807n)
48
+ expect(MinInt).toBe(-9223372036854775808n)
49
+ expect(MaxInt64).toBe(9223372036854775807n)
50
+ expect(MinInt64).toBe(-9223372036854775808n)
51
+ expect(MaxUint).toBe(0xFFFFFFFFFFFFFFFFn)
52
+ expect(MaxUint64).toBe(0xFFFFFFFFFFFFFFFFn)
53
+ })
54
+ })
@@ -0,0 +1,93 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+
3
+ // https://oeis.org/A001113
4
+ export let E: number = Math.E
5
+
6
+ // https://oeis.org/A000796
7
+ export let Pi: number = Math.PI
8
+
9
+ // https://oeis.org/A001622
10
+ export let Phi: number = 1.61803398874989484820458683436563811772030917980576286213544862
11
+
12
+ // https://oeis.org/A002193
13
+ export let Sqrt2: number = Math.SQRT2
14
+
15
+ // https://oeis.org/A019774
16
+ export let SqrtE: number = Math.sqrt(Math.E)
17
+
18
+ // https://oeis.org/A002161
19
+ export let SqrtPi: number = Math.sqrt(Math.PI)
20
+
21
+ // https://oeis.org/A139339
22
+ export let SqrtPhi: number = Math.sqrt(1.61803398874989484820458683436563811772030917980576286213544862)
23
+
24
+ // https://oeis.org/A002162
25
+ export let Ln2: number = Math.LN2
26
+
27
+ export let Log2E: number = Math.LOG2E
28
+
29
+ // https://oeis.org/A002392
30
+ export let Ln10: number = Math.LN10
31
+
32
+ export let Log10E: number = Math.LOG10E
33
+
34
+ // 3.40282346638528859811704183484516925440e+38
35
+ export let MaxFloat32: number = 3.4028234663852886e+38
36
+
37
+ // 1.401298464324817070923729583289916131280e-45
38
+ export let SmallestNonzeroFloat32: number = 1.401298464324817e-45
39
+
40
+ // 1.79769313486231570814527423731704356798070e+308
41
+ export let MaxFloat64: number = Number.MAX_VALUE
42
+
43
+ // 4.9406564584124654417656879286822137236505980e-324
44
+ export let SmallestNonzeroFloat64: number = Number.MIN_VALUE
45
+
46
+ // 32 or 64
47
+ let intSize: number = (32 << ((~(0 as number) >> 63)))
48
+
49
+ // MaxInt32 or MaxInt64 depending on intSize.
50
+ export let MaxInt: bigint = 9223372036854775807n
51
+
52
+ // MinInt32 or MinInt64 depending on intSize.
53
+ export let MinInt: bigint = -9223372036854775808n
54
+
55
+ // 127
56
+ export let MaxInt8: number = 127
57
+
58
+ // -128
59
+ export let MinInt8: number = -128
60
+
61
+ // 32767
62
+ export let MaxInt16: number = 32767
63
+
64
+ // -32768
65
+ export let MinInt16: number = -32768
66
+
67
+ // 2147483647
68
+ export let MaxInt32: number = 2147483647
69
+
70
+ // -2147483648
71
+ export let MinInt32: number = -2147483648
72
+
73
+ // 9223372036854775807
74
+ export let MaxInt64: bigint = 9223372036854775807n
75
+
76
+ // -9223372036854775808
77
+ export let MinInt64: bigint = -9223372036854775808n
78
+
79
+ // MaxUint32 or MaxUint64 depending on intSize.
80
+ export let MaxUint: bigint = 0xFFFFFFFFFFFFFFFFn
81
+
82
+ // 255
83
+ export let MaxUint8: number = 255
84
+
85
+ // 65535
86
+ export let MaxUint16: number = 65535
87
+
88
+ // 4294967295
89
+ export let MaxUint32: number = 4294967295
90
+
91
+ // 18446744073709551615
92
+ export let MaxUint64: bigint = 0xFFFFFFFFFFFFFFFFn
93
+
@@ -0,0 +1,44 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Copysign } from './copysign.gs.js'
3
+
4
+ describe('Copysign', () => {
5
+ it('should return value with magnitude of f and sign of sign', () => {
6
+ expect(Copysign(5, 1)).toBe(5)
7
+ expect(Copysign(5, -1)).toBe(-5)
8
+ expect(Copysign(-5, 1)).toBe(5)
9
+ expect(Copysign(-5, -1)).toBe(-5)
10
+ })
11
+
12
+ it('should handle zero values correctly', () => {
13
+ expect(Copysign(0, 1)).toBe(0)
14
+ expect(Copysign(0, -1)).toBe(-0)
15
+ expect(Copysign(-0, 1)).toBe(0)
16
+ expect(Copysign(-0, -1)).toBe(-0)
17
+ })
18
+
19
+ it('should handle infinity values', () => {
20
+ expect(Copysign(Number.POSITIVE_INFINITY, 1)).toBe(Number.POSITIVE_INFINITY)
21
+ expect(Copysign(Number.POSITIVE_INFINITY, -1)).toBe(Number.NEGATIVE_INFINITY)
22
+ expect(Copysign(Number.NEGATIVE_INFINITY, 1)).toBe(Number.POSITIVE_INFINITY)
23
+ expect(Copysign(Number.NEGATIVE_INFINITY, -1)).toBe(Number.NEGATIVE_INFINITY)
24
+ })
25
+
26
+ it('should handle NaN values', () => {
27
+ expect(Number.isNaN(Copysign(Number.NaN, 1))).toBe(true)
28
+ expect(Number.isNaN(Copysign(Number.NaN, -1))).toBe(true)
29
+ expect(Copysign(5, Number.NaN)).toBe(5) // NaN is positive
30
+ })
31
+
32
+ it('should handle fractional values', () => {
33
+ expect(Copysign(3.14, 1)).toBe(3.14)
34
+ expect(Copysign(3.14, -1)).toBe(-3.14)
35
+ expect(Copysign(-3.14, 1)).toBe(3.14)
36
+ expect(Copysign(-3.14, -1)).toBe(-3.14)
37
+ })
38
+
39
+ it('should handle edge cases with signed zero', () => {
40
+ expect(Object.is(Copysign(5, -0), -5)).toBe(true)
41
+ expect(Object.is(Copysign(-5, -0), -5)).toBe(true)
42
+ expect(Object.is(Copysign(0, -0), -0)).toBe(true)
43
+ })
44
+ })