goscript 0.0.37 → 0.0.38

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 (196) hide show
  1. package/compiler/analysis.go +129 -8
  2. package/compiler/compiler.go +4 -1
  3. package/compiler/composite-lit.go +2 -4
  4. package/compiler/lit.go +83 -0
  5. package/compiler/protobuf.go +2 -2
  6. package/compiler/spec-value.go +3 -3
  7. package/compiler/spec.go +6 -3
  8. package/compiler/stmt-assign.go +1 -1
  9. package/dist/gs/builtin/slice.js +2 -1
  10. package/dist/gs/builtin/slice.js.map +1 -1
  11. package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
  12. package/dist/gs/github.com/pkg/errors/errors.js +182 -23
  13. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
  14. package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
  15. package/dist/gs/github.com/pkg/errors/go113.js +1 -1
  16. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
  17. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
  18. package/dist/gs/github.com/pkg/errors/index.js +3 -3
  19. package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
  20. package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
  21. package/dist/gs/github.com/pkg/errors/stack.js +8 -5
  22. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
  23. package/dist/gs/internal/abi/index.d.ts +20 -0
  24. package/dist/gs/internal/abi/index.js +20 -0
  25. package/dist/gs/internal/abi/index.js.map +1 -0
  26. package/dist/gs/internal/bytealg/index.d.ts +2 -0
  27. package/dist/gs/internal/bytealg/index.js +33 -0
  28. package/dist/gs/internal/bytealg/index.js.map +1 -0
  29. package/dist/gs/internal/byteorder/index.d.ts +1 -1
  30. package/dist/gs/internal/byteorder/index.js +4 -4
  31. package/dist/gs/internal/byteorder/index.js.map +1 -1
  32. package/dist/gs/math/index.d.ts +44 -44
  33. package/dist/gs/math/index.js +44 -44
  34. package/dist/gs/math/index.js.map +1 -1
  35. package/dist/gs/os/index.d.ts +19 -19
  36. package/dist/gs/os/index.js +19 -19
  37. package/dist/gs/os/index.js.map +1 -1
  38. package/dist/gs/reflect/abi.d.ts +59 -0
  39. package/dist/gs/reflect/abi.gs.d.ts +59 -0
  40. package/dist/gs/reflect/abi.gs.js +79 -0
  41. package/dist/gs/reflect/abi.gs.js.map +1 -0
  42. package/dist/gs/reflect/abi.js +79 -0
  43. package/dist/gs/reflect/abi.js.map +1 -0
  44. package/dist/gs/reflect/badlinkname.d.ts +52 -0
  45. package/dist/gs/reflect/badlinkname.gs.d.ts +52 -0
  46. package/dist/gs/reflect/badlinkname.gs.js +72 -0
  47. package/dist/gs/reflect/badlinkname.gs.js.map +1 -0
  48. package/dist/gs/reflect/badlinkname.js +72 -0
  49. package/dist/gs/reflect/badlinkname.js.map +1 -0
  50. package/dist/gs/reflect/deepequal.d.ts +1 -0
  51. package/dist/gs/reflect/deepequal.gs.d.ts +25 -0
  52. package/dist/gs/reflect/deepequal.gs.js +308 -0
  53. package/dist/gs/reflect/deepequal.gs.js.map +1 -0
  54. package/dist/gs/reflect/deepequal.js +139 -0
  55. package/dist/gs/reflect/deepequal.js.map +1 -0
  56. package/dist/gs/reflect/float32reg_generic.gs.d.ts +2 -0
  57. package/dist/gs/reflect/float32reg_generic.gs.js +10 -0
  58. package/dist/gs/reflect/float32reg_generic.gs.js.map +1 -0
  59. package/dist/gs/reflect/index.d.ts +8 -0
  60. package/dist/gs/reflect/index.gs.d.ts +1 -0
  61. package/dist/gs/reflect/index.gs.js +3 -0
  62. package/dist/gs/reflect/index.gs.js.map +1 -0
  63. package/dist/gs/reflect/index.js +10 -0
  64. package/dist/gs/reflect/index.js.map +1 -0
  65. package/dist/gs/reflect/iter.d.ts +4 -0
  66. package/dist/gs/reflect/iter.gs.d.ts +3 -0
  67. package/dist/gs/reflect/iter.gs.js +24 -0
  68. package/dist/gs/reflect/iter.gs.js.map +1 -0
  69. package/dist/gs/reflect/iter.js +24 -0
  70. package/dist/gs/reflect/iter.js.map +1 -0
  71. package/dist/gs/reflect/makefunc.gs.d.ts +34 -0
  72. package/dist/gs/reflect/makefunc.gs.js +288 -0
  73. package/dist/gs/reflect/makefunc.gs.js.map +1 -0
  74. package/dist/gs/reflect/map.d.ts +14 -0
  75. package/dist/gs/reflect/map.js +70 -0
  76. package/dist/gs/reflect/map.js.map +1 -0
  77. package/dist/gs/reflect/map_swiss.gs.d.ts +14 -0
  78. package/dist/gs/reflect/map_swiss.gs.js +70 -0
  79. package/dist/gs/reflect/map_swiss.gs.js.map +1 -0
  80. package/dist/gs/reflect/reflect.gs.d.ts +132 -0
  81. package/dist/gs/reflect/reflect.gs.js +437 -0
  82. package/dist/gs/reflect/reflect.gs.js.map +1 -0
  83. package/dist/gs/reflect/swapper.d.ts +2 -0
  84. package/dist/gs/reflect/swapper.gs.d.ts +1 -0
  85. package/dist/gs/reflect/swapper.gs.js +32 -0
  86. package/dist/gs/reflect/swapper.gs.js.map +1 -0
  87. package/dist/gs/reflect/swapper.js +46 -0
  88. package/dist/gs/reflect/swapper.js.map +1 -0
  89. package/dist/gs/reflect/type.d.ts +126 -0
  90. package/dist/gs/reflect/type.gs.d.ts +4 -0
  91. package/dist/gs/reflect/type.gs.js +21 -0
  92. package/dist/gs/reflect/type.gs.js.map +1 -0
  93. package/dist/gs/reflect/type.js +825 -0
  94. package/dist/gs/reflect/type.js.map +1 -0
  95. package/dist/gs/reflect/types.d.ts +90 -0
  96. package/dist/gs/reflect/types.js +119 -0
  97. package/dist/gs/reflect/types.js.map +1 -0
  98. package/dist/gs/reflect/value.d.ts +13 -0
  99. package/dist/gs/reflect/value.gs.d.ts +4 -0
  100. package/dist/gs/reflect/value.gs.js +12 -0
  101. package/dist/gs/reflect/value.gs.js.map +1 -0
  102. package/dist/gs/reflect/value.js +201 -0
  103. package/dist/gs/reflect/value.js.map +1 -0
  104. package/dist/gs/reflect/visiblefields.d.ts +4 -0
  105. package/dist/gs/reflect/visiblefields.gs.d.ts +3 -0
  106. package/dist/gs/reflect/visiblefields.gs.js +123 -0
  107. package/dist/gs/reflect/visiblefields.gs.js.map +1 -0
  108. package/dist/gs/reflect/visiblefields.js +143 -0
  109. package/dist/gs/reflect/visiblefields.js.map +1 -0
  110. package/dist/gs/strconv/index.d.ts +6 -6
  111. package/dist/gs/strconv/index.js +6 -6
  112. package/dist/gs/strconv/index.js.map +1 -1
  113. package/dist/gs/strings/index.d.ts +1 -1
  114. package/dist/gs/strings/index.js +1 -1
  115. package/dist/gs/strings/index.js.map +1 -1
  116. package/dist/gs/strings/replace.js.map +1 -1
  117. package/dist/gs/sync/atomic/index.d.ts +4 -4
  118. package/dist/gs/sync/atomic/index.js +4 -4
  119. package/dist/gs/sync/atomic/index.js.map +1 -1
  120. package/dist/gs/syscall/index.d.ts +6 -6
  121. package/dist/gs/syscall/index.js +34 -28
  122. package/dist/gs/syscall/index.js.map +1 -1
  123. package/dist/gs/unsafe/unsafe.js.map +1 -1
  124. package/gs/builtin/slice.ts +2 -1
  125. package/gs/github.com/pkg/errors/errors.ts +408 -238
  126. package/gs/github.com/pkg/errors/go113.ts +5 -6
  127. package/gs/github.com/pkg/errors/index.ts +12 -3
  128. package/gs/github.com/pkg/errors/stack.ts +107 -105
  129. package/gs/internal/abi/index.ts +37 -0
  130. package/gs/internal/bytealg/index.ts +34 -0
  131. package/gs/internal/byteorder/index.ts +5 -5
  132. package/gs/math/abs.gs.test.ts +1 -1
  133. package/gs/math/acosh.gs.test.ts +4 -2
  134. package/gs/math/asin.gs.test.ts +1 -1
  135. package/gs/math/asinh.gs.test.ts +7 -3
  136. package/gs/math/atan.gs.test.ts +1 -1
  137. package/gs/math/atan2.gs.test.ts +17 -9
  138. package/gs/math/atanh.gs.test.ts +1 -1
  139. package/gs/math/bits.gs.test.ts +1 -1
  140. package/gs/math/cbrt.gs.test.ts +1 -1
  141. package/gs/math/const.gs.test.ts +34 -8
  142. package/gs/math/copysign.gs.test.ts +7 -3
  143. package/gs/math/dim.gs.test.ts +19 -7
  144. package/gs/math/erf.gs.test.ts +1 -1
  145. package/gs/math/erfinv.gs.test.ts +4 -2
  146. package/gs/math/exp.gs.test.ts +1 -1
  147. package/gs/math/expm1.gs.test.ts +6 -4
  148. package/gs/math/floor.gs.test.ts +17 -4
  149. package/gs/math/fma.gs.test.ts +53 -53
  150. package/gs/math/frexp.gs.test.ts +112 -117
  151. package/gs/math/gamma.gs.test.ts +1 -1
  152. package/gs/math/hypot.gs.test.ts +53 -53
  153. package/gs/math/index.ts +80 -44
  154. package/gs/math/j0.gs.test.ts +6 -2
  155. package/gs/math/j1.gs.test.ts +6 -2
  156. package/gs/math/jn.gs.test.ts +9 -5
  157. package/gs/math/ldexp.gs.test.ts +103 -86
  158. package/gs/math/lgamma.gs.test.ts +10 -10
  159. package/gs/math/log.gs.test.ts +1 -1
  160. package/gs/math/log10.gs.test.ts +1 -1
  161. package/gs/math/log1p.gs.test.ts +2 -2
  162. package/gs/math/logb.gs.test.ts +1 -1
  163. package/gs/math/mod.gs.test.ts +2 -2
  164. package/gs/math/modf.gs.test.ts +7 -7
  165. package/gs/math/nextafter.gs.test.ts +9 -7
  166. package/gs/math/pow.gs.test.ts +6 -4
  167. package/gs/math/pow10.gs.test.ts +1 -1
  168. package/gs/math/remainder.gs.test.ts +1 -1
  169. package/gs/math/signbit.gs.test.ts +1 -1
  170. package/gs/math/sin.gs.test.ts +1 -1
  171. package/gs/math/sincos.gs.test.ts +33 -14
  172. package/gs/math/sinh.gs.test.ts +1 -1
  173. package/gs/math/sqrt.gs.test.ts +1 -1
  174. package/gs/math/tan.gs.test.ts +3 -3
  175. package/gs/math/tanh.gs.test.ts +1 -1
  176. package/gs/os/index.ts +128 -19
  177. package/gs/reflect/ANALYSIS.md +278 -0
  178. package/gs/reflect/deepequal.ts +154 -0
  179. package/gs/reflect/function-types.test.ts +146 -0
  180. package/gs/reflect/godoc.txt +67 -0
  181. package/gs/reflect/index.ts +83 -0
  182. package/gs/reflect/iter.ts +44 -0
  183. package/gs/reflect/map.ts +81 -0
  184. package/gs/reflect/swapper.ts +52 -0
  185. package/gs/reflect/type.ts +1012 -0
  186. package/gs/reflect/types.ts +214 -0
  187. package/gs/reflect/value.ts +264 -0
  188. package/gs/reflect/visiblefields.ts +173 -0
  189. package/gs/strconv/index.ts +39 -6
  190. package/gs/strings/index.ts +7 -1
  191. package/gs/strings/replace.ts +1 -9
  192. package/gs/sync/atomic/index.ts +53 -4
  193. package/gs/syscall/index.ts +45 -37
  194. package/gs/unsafe/unsafe.ts +1 -1
  195. package/package.json +2 -1
  196. package/gs/internal/testlog/index.ts +0 -7
@@ -30,7 +30,9 @@ describe('Erfinv', () => {
30
30
  })
31
31
 
32
32
  it('should be the inverse of Erf', () => {
33
- const testValues = [0, 0.1, 0.3, 0.5, 0.7, 0.9, -0.1, -0.3, -0.5, -0.7, -0.9]
33
+ const testValues = [
34
+ 0, 0.1, 0.3, 0.5, 0.7, 0.9, -0.1, -0.3, -0.5, -0.7, -0.9,
35
+ ]
34
36
  for (const x of testValues) {
35
37
  const y = Erfinv(x)
36
38
  // Relax precision tolerance for JavaScript floating-point differences
@@ -101,4 +103,4 @@ describe('Erfcinv', () => {
101
103
  expect(Erfcinv(0.0001)).toBeGreaterThan(2.5)
102
104
  expect(Erfcinv(1.9999)).toBeLessThan(-2.5)
103
105
  })
104
- })
106
+ })
@@ -79,4 +79,4 @@ describe('expmulti', () => {
79
79
  expect(expmulti(0, 0, 1)).toBe(2)
80
80
  expect(expmulti(1, 0, 1)).toBeCloseTo(Math.E * 2, 14)
81
81
  })
82
- })
82
+ })
@@ -11,7 +11,7 @@ describe('Expm1', () => {
11
11
 
12
12
  it('should return correct values for normal inputs', () => {
13
13
  expect(Expm1(1)).toBeCloseTo(Math.E - 1, 15)
14
- expect(Expm1(-1)).toBeCloseTo(1/Math.E - 1, 15)
14
+ expect(Expm1(-1)).toBeCloseTo(1 / Math.E - 1, 15)
15
15
  expect(Expm1(2)).toBeCloseTo(Math.E * Math.E - 1, 14)
16
16
  expect(Expm1(0.5)).toBeCloseTo(Math.sqrt(Math.E) - 1, 15)
17
17
  })
@@ -31,9 +31,11 @@ describe('Expm1', () => {
31
31
  const x = 1e-15
32
32
  const expm1Result = Expm1(x)
33
33
  const expMinus1Result = Math.exp(x) - 1
34
-
34
+
35
35
  // For very small x, expm1 should be more accurate
36
- expect(Math.abs(expm1Result - x)).toBeLessThan(Math.abs(expMinus1Result - x))
36
+ expect(Math.abs(expm1Result - x)).toBeLessThan(
37
+ Math.abs(expMinus1Result - x),
38
+ )
37
39
  })
38
40
  })
39
41
 
@@ -45,4 +47,4 @@ describe('expm1', () => {
45
47
  expect(expm1(0.5)).toBe(Expm1(0.5))
46
48
  expect(Number.isNaN(expm1(Number.NaN))).toBe(true)
47
49
  })
48
- })
50
+ })
@@ -1,5 +1,14 @@
1
1
  import { describe, it, expect } from 'vitest'
2
- import { Floor, floor, Ceil, ceil, Trunc, trunc, Round, RoundToEven } from './floor.gs.js'
2
+ import {
3
+ Floor,
4
+ floor,
5
+ Ceil,
6
+ ceil,
7
+ Trunc,
8
+ trunc,
9
+ Round,
10
+ RoundToEven,
11
+ } from './floor.gs.js'
3
12
 
4
13
  describe('Floor', () => {
5
14
  it('should return correct floor values', () => {
@@ -28,7 +37,9 @@ describe('floor', () => {
28
37
  it('should work the same as Floor', () => {
29
38
  expect(floor(4.8)).toBe(Floor(4.8))
30
39
  expect(floor(-4.2)).toBe(Floor(-4.2))
31
- expect(floor(Number.POSITIVE_INFINITY)).toBe(Floor(Number.POSITIVE_INFINITY))
40
+ expect(floor(Number.POSITIVE_INFINITY)).toBe(
41
+ Floor(Number.POSITIVE_INFINITY),
42
+ )
32
43
  })
33
44
  })
34
45
 
@@ -90,7 +101,9 @@ describe('trunc', () => {
90
101
  it('should work the same as Trunc', () => {
91
102
  expect(trunc(4.8)).toBe(Trunc(4.8))
92
103
  expect(trunc(-4.2)).toBe(Trunc(-4.2))
93
- expect(trunc(Number.POSITIVE_INFINITY)).toBe(Trunc(Number.POSITIVE_INFINITY))
104
+ expect(trunc(Number.POSITIVE_INFINITY)).toBe(
105
+ Trunc(Number.POSITIVE_INFINITY),
106
+ )
94
107
  })
95
108
  })
96
109
 
@@ -143,4 +156,4 @@ describe('RoundToEven', () => {
143
156
  expect(RoundToEven(0)).toBe(0)
144
157
  expect(RoundToEven(-0)).toBe(-0)
145
158
  })
146
- })
159
+ })
@@ -1,83 +1,83 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { FMA } from './fma.gs.js';
3
- import { Inf, NaN as GoNaN, IsNaN } from './bits.gs.js';
1
+ import { describe, it, expect } from 'vitest'
2
+ import { FMA } from './fma.gs.js'
3
+ import { Inf, NaN as GoNaN, IsNaN } from './bits.gs.js'
4
4
 
5
5
  describe('FMA', () => {
6
6
  it('should compute fused multiply-add correctly for basic cases', () => {
7
- expect(FMA(2, 3, 4)).toBe(10); // 2*3 + 4 = 10
8
- expect(FMA(1.5, 2, 0.5)).toBe(3.5); // 1.5*2 + 0.5 = 3.5
9
- expect(FMA(0.1, 0.2, 0.3)).toBeCloseTo(0.32, 10); // 0.1*0.2 + 0.3 = 0.32
10
- expect(FMA(-2, 3, 1)).toBe(-5); // -2*3 + 1 = -5
11
- });
7
+ expect(FMA(2, 3, 4)).toBe(10) // 2*3 + 4 = 10
8
+ expect(FMA(1.5, 2, 0.5)).toBe(3.5) // 1.5*2 + 0.5 = 3.5
9
+ expect(FMA(0.1, 0.2, 0.3)).toBeCloseTo(0.32, 10) // 0.1*0.2 + 0.3 = 0.32
10
+ expect(FMA(-2, 3, 1)).toBe(-5) // -2*3 + 1 = -5
11
+ })
12
12
 
13
13
  it('should handle zero values', () => {
14
- expect(FMA(0, 5, 3)).toBe(3); // 0*5 + 3 = 3
15
- expect(FMA(5, 0, 3)).toBe(3); // 5*0 + 3 = 3
16
- expect(FMA(5, 3, 0)).toBe(15); // 5*3 + 0 = 15
17
- expect(FMA(0, 0, 0)).toBe(0); // 0*0 + 0 = 0
18
- expect(FMA(0, 0, 5)).toBe(5); // 0*0 + 5 = 5
19
- });
14
+ expect(FMA(0, 5, 3)).toBe(3) // 0*5 + 3 = 3
15
+ expect(FMA(5, 0, 3)).toBe(3) // 5*0 + 3 = 3
16
+ expect(FMA(5, 3, 0)).toBe(15) // 5*3 + 0 = 15
17
+ expect(FMA(0, 0, 0)).toBe(0) // 0*0 + 0 = 0
18
+ expect(FMA(0, 0, 5)).toBe(5) // 0*0 + 5 = 5
19
+ })
20
20
 
21
21
  it('should handle negative values', () => {
22
- expect(FMA(-2, -3, 4)).toBe(10); // -2*-3 + 4 = 10
23
- expect(FMA(-2, 3, -4)).toBe(-10); // -2*3 + -4 = -10
24
- expect(FMA(2, -3, -4)).toBe(-10); // 2*-3 + -4 = -10
25
- expect(FMA(-2, -3, -4)).toBe(2); // -2*-3 + -4 = 2
26
- });
22
+ expect(FMA(-2, -3, 4)).toBe(10) // -2*-3 + 4 = 10
23
+ expect(FMA(-2, 3, -4)).toBe(-10) // -2*3 + -4 = -10
24
+ expect(FMA(2, -3, -4)).toBe(-10) // 2*-3 + -4 = -10
25
+ expect(FMA(-2, -3, -4)).toBe(2) // -2*-3 + -4 = 2
26
+ })
27
27
 
28
28
  it('should handle infinity cases', () => {
29
- expect(FMA(Inf(1), 2, 3)).toBe(Inf(1)); // +Inf * 2 + 3 = +Inf
30
- expect(FMA(2, Inf(1), 3)).toBe(Inf(1)); // 2 * +Inf + 3 = +Inf
31
- expect(FMA(2, 3, Inf(1))).toBe(Inf(1)); // 2 * 3 + +Inf = +Inf
32
- expect(FMA(Inf(-1), 2, 3)).toBe(Inf(-1)); // -Inf * 2 + 3 = -Inf
33
- expect(FMA(Inf(1), Inf(1), 3)).toBe(Inf(1)); // +Inf * +Inf + 3 = +Inf
34
- expect(FMA(Inf(-1), Inf(-1), 3)).toBe(Inf(1)); // -Inf * -Inf + 3 = +Inf
35
- });
29
+ expect(FMA(Inf(1), 2, 3)).toBe(Inf(1)) // +Inf * 2 + 3 = +Inf
30
+ expect(FMA(2, Inf(1), 3)).toBe(Inf(1)) // 2 * +Inf + 3 = +Inf
31
+ expect(FMA(2, 3, Inf(1))).toBe(Inf(1)) // 2 * 3 + +Inf = +Inf
32
+ expect(FMA(Inf(-1), 2, 3)).toBe(Inf(-1)) // -Inf * 2 + 3 = -Inf
33
+ expect(FMA(Inf(1), Inf(1), 3)).toBe(Inf(1)) // +Inf * +Inf + 3 = +Inf
34
+ expect(FMA(Inf(-1), Inf(-1), 3)).toBe(Inf(1)) // -Inf * -Inf + 3 = +Inf
35
+ })
36
36
 
37
37
  it('should handle NaN cases', () => {
38
- expect(IsNaN(FMA(GoNaN(), 2, 3))).toBe(true);
39
- expect(IsNaN(FMA(2, GoNaN(), 3))).toBe(true);
40
- expect(IsNaN(FMA(2, 3, GoNaN()))).toBe(true);
41
- expect(IsNaN(FMA(GoNaN(), GoNaN(), GoNaN()))).toBe(true);
42
- });
38
+ expect(IsNaN(FMA(GoNaN(), 2, 3))).toBe(true)
39
+ expect(IsNaN(FMA(2, GoNaN(), 3))).toBe(true)
40
+ expect(IsNaN(FMA(2, 3, GoNaN()))).toBe(true)
41
+ expect(IsNaN(FMA(GoNaN(), GoNaN(), GoNaN()))).toBe(true)
42
+ })
43
43
 
44
44
  it('should handle special infinity and zero combinations', () => {
45
45
  // Inf * 0 should produce NaN
46
- expect(IsNaN(FMA(Inf(1), 0, 5))).toBe(true);
47
- expect(IsNaN(FMA(0, Inf(1), 5))).toBe(true);
48
-
46
+ expect(IsNaN(FMA(Inf(1), 0, 5))).toBe(true)
47
+ expect(IsNaN(FMA(0, Inf(1), 5))).toBe(true)
48
+
49
49
  // But if the addition part is also infinity, behavior depends on implementation
50
- expect(IsNaN(FMA(Inf(1), 0, Inf(1)))).toBe(true);
51
- });
50
+ expect(IsNaN(FMA(Inf(1), 0, Inf(1)))).toBe(true)
51
+ })
52
52
 
53
53
  it('should handle cancellation cases', () => {
54
54
  // Cases where x*y and z cancel out
55
- expect(FMA(2, 3, -6)).toBe(0); // 2*3 + (-6) = 0
56
- expect(FMA(-5, 4, 20)).toBe(0); // -5*4 + 20 = 0
57
- expect(FMA(0.5, 0.2, -0.1)).toBeCloseTo(0, 10); // 0.5*0.2 + (-0.1) = 0
58
- });
55
+ expect(FMA(2, 3, -6)).toBe(0) // 2*3 + (-6) = 0
56
+ expect(FMA(-5, 4, 20)).toBe(0) // -5*4 + 20 = 0
57
+ expect(FMA(0.5, 0.2, -0.1)).toBeCloseTo(0, 10) // 0.5*0.2 + (-0.1) = 0
58
+ })
59
59
 
60
60
  it('should handle very large and small numbers', () => {
61
- const large = 1e100;
62
- const small = 1e-100;
63
-
61
+ const large = 1e100
62
+ const small = 1e-100
63
+
64
64
  // Relax tolerance for very large/small number calculations
65
65
  const result1 = FMA(large, small, 1)
66
- expect(result1).toBeCloseTo(2, 0); // large*small is approximately 1, so result is approximately 2
67
- expect(FMA(small, small, large)).toBeCloseTo(large, 5); // small*small is negligible
68
- expect(FMA(large, large, -large * large)).toBeCloseTo(0, 5); // cancellation
69
- });
66
+ expect(result1).toBeCloseTo(2, 0) // large*small is approximately 1, so result is approximately 2
67
+ expect(FMA(small, small, large)).toBeCloseTo(large, 5) // small*small is negligible
68
+ expect(FMA(large, large, -large * large)).toBeCloseTo(0, 5) // cancellation
69
+ })
70
70
 
71
71
  it('should be equivalent to x * y + z for simple cases', () => {
72
72
  const testCases = [
73
73
  [1, 2, 3],
74
74
  [0.5, 0.25, 0.125],
75
75
  [-1, 2, -3],
76
- [10, 0.1, 5]
77
- ];
76
+ [10, 0.1, 5],
77
+ ]
78
78
 
79
79
  testCases.forEach(([x, y, z]) => {
80
- expect(FMA(x, y, z)).toBeCloseTo(x * y + z, 10);
81
- });
82
- });
83
- });
80
+ expect(FMA(x, y, z)).toBeCloseTo(x * y + z, 10)
81
+ })
82
+ })
83
+ })
@@ -1,146 +1,141 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { Frexp, frexp } from './frexp.gs.js';
3
- import { Inf, NaN as GoNaN, IsNaN } from './bits.gs.js';
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Frexp, frexp } from './frexp.gs.js'
3
+ import { Inf, NaN as GoNaN, IsNaN } from './bits.gs.js'
4
4
 
5
5
  describe('Frexp', () => {
6
6
  it('should break numbers into normalized fraction and exponent', () => {
7
7
  // Test basic cases where we can verify the math
8
- let [frac, exp] = Frexp(8);
9
- expect(frac).toBeCloseTo(0.5, 10);
10
- expect(exp).toBe(4); // 8 = 0.5 * 2^4
11
-
12
- [frac, exp] = Frexp(1);
13
- expect(frac).toBeCloseTo(0.5, 10);
14
- expect(exp).toBe(1); // 1 = 0.5 * 2^1
15
-
16
- [frac, exp] = Frexp(2);
17
- expect(frac).toBeCloseTo(0.5, 10);
18
- expect(exp).toBe(2); // 2 = 0.5 * 2^2
19
-
20
- [frac, exp] = Frexp(4);
21
- expect(frac).toBeCloseTo(0.5, 10);
22
- expect(exp).toBe(3); // 4 = 0.5 * 2^3
23
- });
8
+ let [frac, exp] = Frexp(8)
9
+ expect(frac).toBeCloseTo(0.5, 10)
10
+ expect(exp).toBe(4) // 8 = 0.5 * 2^4
11
+ ;[frac, exp] = Frexp(1)
12
+ expect(frac).toBeCloseTo(0.5, 10)
13
+ expect(exp).toBe(1) // 1 = 0.5 * 2^1
14
+ ;[frac, exp] = Frexp(2)
15
+ expect(frac).toBeCloseTo(0.5, 10)
16
+ expect(exp).toBe(2) // 2 = 0.5 * 2^2
17
+ ;[frac, exp] = Frexp(4)
18
+ expect(frac).toBeCloseTo(0.5, 10)
19
+ expect(exp).toBe(3) // 4 = 0.5 * 2^3
20
+ })
24
21
 
25
22
  it('should handle fractional numbers', () => {
26
- let [frac, exp] = Frexp(0.5);
27
- expect(frac).toBeCloseTo(0.5, 10);
28
- expect(exp).toBe(0); // 0.5 = 0.5 * 2^0
29
-
30
- [frac, exp] = Frexp(0.25);
31
- expect(frac).toBeCloseTo(0.5, 10);
32
- expect(exp).toBe(-1); // 0.25 = 0.5 * 2^-1
33
-
34
- [frac, exp] = Frexp(0.125);
35
- expect(frac).toBeCloseTo(0.5, 10);
36
- expect(exp).toBe(-2); // 0.125 = 0.5 * 2^-2
37
- });
23
+ let [frac, exp] = Frexp(0.5)
24
+ expect(frac).toBeCloseTo(0.5, 10)
25
+ expect(exp).toBe(0) // 0.5 = 0.5 * 2^0
26
+ ;[frac, exp] = Frexp(0.25)
27
+ expect(frac).toBeCloseTo(0.5, 10)
28
+ expect(exp).toBe(-1) // 0.25 = 0.5 * 2^-1
29
+ ;[frac, exp] = Frexp(0.125)
30
+ expect(frac).toBeCloseTo(0.5, 10)
31
+ expect(exp).toBe(-2) // 0.125 = 0.5 * 2^-2
32
+ })
38
33
 
39
34
  it('should handle negative numbers', () => {
40
- let [frac, exp] = Frexp(-8);
41
- expect(frac).toBeCloseTo(-0.5, 10);
42
- expect(exp).toBe(4); // -8 = -0.5 * 2^4
43
-
44
- [frac, exp] = Frexp(-1);
45
- expect(frac).toBeCloseTo(-0.5, 10);
46
- expect(exp).toBe(1); // -1 = -0.5 * 2^1
47
-
48
- [frac, exp] = Frexp(-0.5);
49
- expect(frac).toBeCloseTo(-0.5, 10);
50
- expect(exp).toBe(0); // -0.5 = -0.5 * 2^0
51
- });
35
+ let [frac, exp] = Frexp(-8)
36
+ expect(frac).toBeCloseTo(-0.5, 10)
37
+ expect(exp).toBe(4) // -8 = -0.5 * 2^4
38
+ ;[frac, exp] = Frexp(-1)
39
+ expect(frac).toBeCloseTo(-0.5, 10)
40
+ expect(exp).toBe(1) // -1 = -0.5 * 2^1
41
+ ;[frac, exp] = Frexp(-0.5)
42
+ expect(frac).toBeCloseTo(-0.5, 10)
43
+ expect(exp).toBe(0) // -0.5 = -0.5 * 2^0
44
+ })
52
45
 
53
46
  it('should handle zero values', () => {
54
- let [frac, exp] = Frexp(0);
55
- expect(frac).toBe(0);
56
- expect(exp).toBe(0);
57
-
58
- [frac, exp] = Frexp(-0);
59
- expect(frac).toBe(-0);
60
- expect(exp).toBe(0);
61
- expect(Object.is(frac, -0)).toBe(true); // Preserve sign of zero
62
- });
47
+ let [frac, exp] = Frexp(0)
48
+ expect(frac).toBe(0)
49
+ expect(exp).toBe(0)
50
+ ;[frac, exp] = Frexp(-0)
51
+ expect(frac).toBe(-0)
52
+ expect(exp).toBe(0)
53
+ expect(Object.is(frac, -0)).toBe(true) // Preserve sign of zero
54
+ })
63
55
 
64
56
  it('should handle infinity cases', () => {
65
- let [frac, exp] = Frexp(Inf(1));
66
- expect(frac).toBe(Inf(1));
67
- expect(exp).toBe(0);
68
-
69
- [frac, exp] = Frexp(Inf(-1));
70
- expect(frac).toBe(Inf(-1));
71
- expect(exp).toBe(0);
72
- });
57
+ let [frac, exp] = Frexp(Inf(1))
58
+ expect(frac).toBe(Inf(1))
59
+ expect(exp).toBe(0)
60
+ ;[frac, exp] = Frexp(Inf(-1))
61
+ expect(frac).toBe(Inf(-1))
62
+ expect(exp).toBe(0)
63
+ })
73
64
 
74
65
  it('should handle NaN cases', () => {
75
- let [frac, _exp] = Frexp(GoNaN());
76
- expect(IsNaN(frac)).toBe(true);
77
- expect(_exp).toBe(0);
78
- });
66
+ let [frac, _exp] = Frexp(GoNaN())
67
+ expect(IsNaN(frac)).toBe(true)
68
+ expect(_exp).toBe(0)
69
+ })
79
70
 
80
71
  it('should satisfy the fundamental property f = frac * 2^exp', () => {
81
- const testValues = [1, 2, 3, 4, 5, 8, 16, 0.5, 0.25, 0.125, 1.5, 3.14159, 100, 1000];
82
-
83
- testValues.forEach(value => {
84
- const [frac, exp] = Frexp(value);
85
- const reconstructed = frac * Math.pow(2, exp);
86
- expect(reconstructed).toBeCloseTo(value, 10);
87
- });
88
-
72
+ const testValues = [
73
+ 1, 2, 3, 4, 5, 8, 16, 0.5, 0.25, 0.125, 1.5, 3.14159, 100, 1000,
74
+ ]
75
+
76
+ testValues.forEach((value) => {
77
+ const [frac, exp] = Frexp(value)
78
+ const reconstructed = frac * Math.pow(2, exp)
79
+ expect(reconstructed).toBeCloseTo(value, 10)
80
+ })
81
+
89
82
  // Test negative values
90
- testValues.forEach(value => {
91
- const [frac, exp] = Frexp(-value);
92
- const reconstructed = frac * Math.pow(2, exp);
93
- expect(reconstructed).toBeCloseTo(-value, 10);
94
- });
95
- });
83
+ testValues.forEach((value) => {
84
+ const [frac, exp] = Frexp(-value)
85
+ const reconstructed = frac * Math.pow(2, exp)
86
+ expect(reconstructed).toBeCloseTo(-value, 10)
87
+ })
88
+ })
96
89
 
97
90
  it('should ensure fraction is in range [0.5, 1) for positive numbers', () => {
98
- const testValues = [1, 2, 3, 4, 5, 8, 16, 0.5, 0.25, 0.125, 1.5, 3.14159, 100, 1000];
99
-
100
- testValues.forEach(value => {
101
- const [frac, _exp] = Frexp(value);
91
+ const testValues = [
92
+ 1, 2, 3, 4, 5, 8, 16, 0.5, 0.25, 0.125, 1.5, 3.14159, 100, 1000,
93
+ ]
94
+
95
+ testValues.forEach((value) => {
96
+ const [frac, _exp] = Frexp(value)
102
97
  if (value !== 0) {
103
- expect(Math.abs(frac)).toBeGreaterThanOrEqual(0.5);
104
- expect(Math.abs(frac)).toBeLessThan(1);
98
+ expect(Math.abs(frac)).toBeGreaterThanOrEqual(0.5)
99
+ expect(Math.abs(frac)).toBeLessThan(1)
105
100
  }
106
- });
107
- });
101
+ })
102
+ })
108
103
 
109
104
  it('should handle very large numbers', () => {
110
- const large = 1e100;
111
- const [frac, exp] = Frexp(large);
112
- expect(Math.abs(frac)).toBeGreaterThanOrEqual(0.5);
113
- expect(Math.abs(frac)).toBeLessThan(1);
114
- expect(frac * Math.pow(2, exp)).toBeCloseTo(large, 5);
115
- });
105
+ const large = 1e100
106
+ const [frac, exp] = Frexp(large)
107
+ expect(Math.abs(frac)).toBeGreaterThanOrEqual(0.5)
108
+ expect(Math.abs(frac)).toBeLessThan(1)
109
+ expect(frac * Math.pow(2, exp)).toBeCloseTo(large, 5)
110
+ })
116
111
 
117
112
  it('should handle very small numbers', () => {
118
- const small = 1e-100;
119
- const [frac, exp] = Frexp(small);
120
- expect(Math.abs(frac)).toBeGreaterThanOrEqual(0.5);
121
- expect(Math.abs(frac)).toBeLessThan(1);
122
- expect(frac * Math.pow(2, exp)).toBeCloseTo(small, 110);
123
- });
124
- });
113
+ const small = 1e-100
114
+ const [frac, exp] = Frexp(small)
115
+ expect(Math.abs(frac)).toBeGreaterThanOrEqual(0.5)
116
+ expect(Math.abs(frac)).toBeLessThan(1)
117
+ expect(frac * Math.pow(2, exp)).toBeCloseTo(small, 110)
118
+ })
119
+ })
125
120
 
126
121
  describe('frexp (lowercase)', () => {
127
122
  it('should work identically to Frexp', () => {
128
- const testValues = [0, 1, 2, 4, 8, 0.5, 0.25, -1, -2, 3.14159];
129
-
130
- testValues.forEach(value => {
131
- const [frac1, exp1] = Frexp(value);
132
- const [frac2, exp2] = frexp(value);
133
- expect(frac1).toBe(frac2);
134
- expect(exp1).toBe(exp2);
135
- });
136
-
123
+ const testValues = [0, 1, 2, 4, 8, 0.5, 0.25, -1, -2, 3.14159]
124
+
125
+ testValues.forEach((value) => {
126
+ const [frac1, exp1] = Frexp(value)
127
+ const [frac2, exp2] = frexp(value)
128
+ expect(frac1).toBe(frac2)
129
+ expect(exp1).toBe(exp2)
130
+ })
131
+
137
132
  // Test special cases
138
- expect(frexp(Inf(1))).toEqual(Frexp(Inf(1)));
139
- expect(frexp(Inf(-1))).toEqual(Frexp(Inf(-1)));
140
-
141
- const [fracNaN1, expNaN1] = frexp(GoNaN());
142
- const [fracNaN2, expNaN2] = Frexp(GoNaN());
143
- expect(IsNaN(fracNaN1)).toBe(IsNaN(fracNaN2));
144
- expect(expNaN1).toBe(expNaN2);
145
- });
146
- });
133
+ expect(frexp(Inf(1))).toEqual(Frexp(Inf(1)))
134
+ expect(frexp(Inf(-1))).toEqual(Frexp(Inf(-1)))
135
+
136
+ const [fracNaN1, expNaN1] = frexp(GoNaN())
137
+ const [fracNaN2, expNaN2] = Frexp(GoNaN())
138
+ expect(IsNaN(fracNaN1)).toBe(IsNaN(fracNaN2))
139
+ expect(expNaN1).toBe(expNaN2)
140
+ })
141
+ })
@@ -63,4 +63,4 @@ describe('Gamma', () => {
63
63
  const expected = Math.PI / Math.sin(Math.PI * x)
64
64
  expect(gamma_x * gamma_1_minus_x).toBeCloseTo(expected, 10)
65
65
  })
66
- })
66
+ })
@@ -1,73 +1,73 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { Hypot, hypot } from './hypot.gs.js';
3
- import { Inf, NaN as GoNaN, IsNaN, IsInf } from './bits.gs.js';
1
+ import { describe, it, expect } from 'vitest'
2
+ import { Hypot, hypot } from './hypot.gs.js'
3
+ import { Inf, NaN as GoNaN, IsNaN, IsInf } from './bits.gs.js'
4
4
 
5
5
  describe('Hypot', () => {
6
6
  it('should calculate hypotenuse correctly for basic cases', () => {
7
- expect(Hypot(3, 4)).toBeCloseTo(5, 10);
8
- expect(Hypot(5, 12)).toBeCloseTo(13, 10);
9
- expect(Hypot(8, 15)).toBeCloseTo(17, 10);
10
- expect(Hypot(1, 1)).toBeCloseTo(Math.sqrt(2), 10);
11
- });
7
+ expect(Hypot(3, 4)).toBeCloseTo(5, 10)
8
+ expect(Hypot(5, 12)).toBeCloseTo(13, 10)
9
+ expect(Hypot(8, 15)).toBeCloseTo(17, 10)
10
+ expect(Hypot(1, 1)).toBeCloseTo(Math.sqrt(2), 10)
11
+ })
12
12
 
13
13
  it('should handle zero values', () => {
14
- expect(Hypot(0, 0)).toBe(0);
15
- expect(Hypot(0, 5)).toBe(5);
16
- expect(Hypot(5, 0)).toBe(5);
17
- expect(Hypot(0, -5)).toBe(5);
18
- expect(Hypot(-5, 0)).toBe(5);
19
- });
14
+ expect(Hypot(0, 0)).toBe(0)
15
+ expect(Hypot(0, 5)).toBe(5)
16
+ expect(Hypot(5, 0)).toBe(5)
17
+ expect(Hypot(0, -5)).toBe(5)
18
+ expect(Hypot(-5, 0)).toBe(5)
19
+ })
20
20
 
21
21
  it('should handle negative values', () => {
22
- expect(Hypot(-3, 4)).toBeCloseTo(5, 10);
23
- expect(Hypot(3, -4)).toBeCloseTo(5, 10);
24
- expect(Hypot(-3, -4)).toBeCloseTo(5, 10);
25
- expect(Hypot(-5, -12)).toBeCloseTo(13, 10);
26
- });
22
+ expect(Hypot(-3, 4)).toBeCloseTo(5, 10)
23
+ expect(Hypot(3, -4)).toBeCloseTo(5, 10)
24
+ expect(Hypot(-3, -4)).toBeCloseTo(5, 10)
25
+ expect(Hypot(-5, -12)).toBeCloseTo(13, 10)
26
+ })
27
27
 
28
28
  it('should handle infinity cases', () => {
29
- expect(Hypot(Inf(1), 5)).toBe(Inf(1));
30
- expect(Hypot(5, Inf(1))).toBe(Inf(1));
31
- expect(Hypot(Inf(-1), 5)).toBe(Inf(1));
32
- expect(Hypot(5, Inf(-1))).toBe(Inf(1));
33
- expect(Hypot(Inf(1), Inf(1))).toBe(Inf(1));
34
- expect(Hypot(Inf(-1), Inf(-1))).toBe(Inf(1));
35
- });
29
+ expect(Hypot(Inf(1), 5)).toBe(Inf(1))
30
+ expect(Hypot(5, Inf(1))).toBe(Inf(1))
31
+ expect(Hypot(Inf(-1), 5)).toBe(Inf(1))
32
+ expect(Hypot(5, Inf(-1))).toBe(Inf(1))
33
+ expect(Hypot(Inf(1), Inf(1))).toBe(Inf(1))
34
+ expect(Hypot(Inf(-1), Inf(-1))).toBe(Inf(1))
35
+ })
36
36
 
37
37
  it('should handle NaN cases', () => {
38
- expect(IsNaN(Hypot(GoNaN(), 5))).toBe(true);
39
- expect(IsNaN(Hypot(5, GoNaN()))).toBe(true);
40
- expect(IsNaN(Hypot(GoNaN(), GoNaN()))).toBe(true);
41
- });
38
+ expect(IsNaN(Hypot(GoNaN(), 5))).toBe(true)
39
+ expect(IsNaN(Hypot(5, GoNaN()))).toBe(true)
40
+ expect(IsNaN(Hypot(GoNaN(), GoNaN()))).toBe(true)
41
+ })
42
42
 
43
43
  it('should handle very large values without overflow', () => {
44
- const large = 1e150;
45
- const result = Hypot(large, large);
46
- expect(result).toBeCloseTo(large * Math.sqrt(2), 5);
47
- expect(IsInf(result, 0)).toBe(false);
48
- });
44
+ const large = 1e150
45
+ const result = Hypot(large, large)
46
+ expect(result).toBeCloseTo(large * Math.sqrt(2), 5)
47
+ expect(IsInf(result, 0)).toBe(false)
48
+ })
49
49
 
50
50
  it('should handle very small values without underflow', () => {
51
- const small = 1e-150;
52
- const result = Hypot(small, small);
53
- expect(result).toBeCloseTo(small * Math.sqrt(2), 160);
54
- expect(result).toBeGreaterThan(0);
55
- });
51
+ const small = 1e-150
52
+ const result = Hypot(small, small)
53
+ expect(result).toBeCloseTo(small * Math.sqrt(2), 160)
54
+ expect(result).toBeGreaterThan(0)
55
+ })
56
56
 
57
57
  it('should be commutative', () => {
58
- expect(Hypot(3, 4)).toBe(Hypot(4, 3));
59
- expect(Hypot(-3, 4)).toBe(Hypot(4, -3));
60
- expect(Hypot(1.5, 2.5)).toBe(Hypot(2.5, 1.5));
61
- });
62
- });
58
+ expect(Hypot(3, 4)).toBe(Hypot(4, 3))
59
+ expect(Hypot(-3, 4)).toBe(Hypot(4, -3))
60
+ expect(Hypot(1.5, 2.5)).toBe(Hypot(2.5, 1.5))
61
+ })
62
+ })
63
63
 
64
64
  describe('hypot (lowercase)', () => {
65
65
  it('should work identically to Hypot', () => {
66
- expect(hypot(3, 4)).toBe(Hypot(3, 4));
67
- expect(hypot(5, 12)).toBe(Hypot(5, 12));
68
- expect(hypot(0, 0)).toBe(Hypot(0, 0));
69
- expect(hypot(-3, 4)).toBe(Hypot(-3, 4));
70
- expect(hypot(Inf(1), 5)).toBe(Hypot(Inf(1), 5));
71
- expect(IsNaN(hypot(GoNaN(), 5))).toBe(IsNaN(Hypot(GoNaN(), 5)));
72
- });
73
- });
66
+ expect(hypot(3, 4)).toBe(Hypot(3, 4))
67
+ expect(hypot(5, 12)).toBe(Hypot(5, 12))
68
+ expect(hypot(0, 0)).toBe(Hypot(0, 0))
69
+ expect(hypot(-3, 4)).toBe(Hypot(-3, 4))
70
+ expect(hypot(Inf(1), 5)).toBe(Hypot(Inf(1), 5))
71
+ expect(IsNaN(hypot(GoNaN(), 5))).toBe(IsNaN(Hypot(GoNaN(), 5)))
72
+ })
73
+ })