goscript 0.0.37 → 0.0.39
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.
- package/compiler/analysis.go +129 -8
- package/compiler/compiler.go +4 -1
- package/compiler/composite-lit.go +2 -4
- package/compiler/expr-call.go +12 -0
- package/compiler/lit.go +100 -6
- package/compiler/protobuf.go +2 -2
- package/compiler/spec-value.go +3 -3
- package/compiler/spec.go +6 -3
- package/compiler/stmt-assign.go +1 -1
- package/dist/gs/builtin/builtin.d.ts +45 -0
- package/dist/gs/builtin/builtin.js +197 -0
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/slice.js +2 -1
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.d.ts +56 -0
- package/dist/gs/bytes/buffer.gs.js +611 -0
- package/dist/gs/bytes/buffer.gs.js.map +1 -0
- package/dist/gs/bytes/bytes.gs.d.ts +78 -0
- package/dist/gs/bytes/bytes.gs.js +1011 -0
- package/dist/gs/bytes/bytes.gs.js.map +1 -0
- package/dist/gs/bytes/index.d.ts +4 -0
- package/dist/gs/bytes/index.js +5 -0
- package/dist/gs/bytes/index.js.map +1 -0
- package/dist/gs/bytes/iter.gs.d.ts +9 -0
- package/dist/gs/bytes/iter.gs.js +143 -0
- package/dist/gs/bytes/iter.gs.js.map +1 -0
- package/dist/gs/bytes/reader.gs.d.ts +34 -0
- package/dist/gs/bytes/reader.gs.js +198 -0
- package/dist/gs/bytes/reader.gs.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/errors.js +182 -23
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
- package/dist/gs/github.com/pkg/errors/index.js +3 -3
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js +8 -5
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/internal/abi/index.d.ts +20 -0
- package/dist/gs/internal/abi/index.js +20 -0
- package/dist/gs/internal/abi/index.js.map +1 -0
- package/dist/gs/internal/bytealg/index.d.ts +14 -0
- package/dist/gs/internal/bytealg/index.js +139 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -0
- package/dist/gs/internal/byteorder/index.d.ts +1 -1
- package/dist/gs/internal/byteorder/index.js +4 -4
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/math/index.d.ts +44 -44
- package/dist/gs/math/index.js +44 -44
- package/dist/gs/math/index.js.map +1 -1
- package/dist/gs/os/index.d.ts +19 -19
- package/dist/gs/os/index.js +19 -19
- package/dist/gs/os/index.js.map +1 -1
- package/dist/gs/reflect/deepequal.d.ts +2 -0
- package/dist/gs/reflect/deepequal.js +91 -0
- package/dist/gs/reflect/deepequal.js.map +1 -0
- package/dist/gs/reflect/index.d.ts +8 -0
- package/dist/gs/reflect/index.js +10 -0
- package/dist/gs/reflect/index.js.map +1 -0
- package/dist/gs/reflect/iter.d.ts +4 -0
- package/dist/gs/reflect/iter.js +24 -0
- package/dist/gs/reflect/iter.js.map +1 -0
- package/dist/gs/reflect/map.d.ts +20 -0
- package/dist/gs/reflect/map.js +74 -0
- package/dist/gs/reflect/map.js.map +1 -0
- package/dist/gs/reflect/swapper.d.ts +2 -0
- package/dist/gs/reflect/swapper.js +46 -0
- package/dist/gs/reflect/swapper.js.map +1 -0
- package/dist/gs/reflect/type.d.ts +134 -0
- package/dist/gs/reflect/type.js +825 -0
- package/dist/gs/reflect/type.js.map +1 -0
- package/dist/gs/reflect/types.d.ts +90 -0
- package/dist/gs/reflect/types.js +119 -0
- package/dist/gs/reflect/types.js.map +1 -0
- package/dist/gs/reflect/value.d.ts +13 -0
- package/dist/gs/reflect/value.js +202 -0
- package/dist/gs/reflect/value.js.map +1 -0
- package/dist/gs/reflect/visiblefields.d.ts +4 -0
- package/dist/gs/reflect/visiblefields.js +149 -0
- package/dist/gs/reflect/visiblefields.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +6 -6
- package/dist/gs/strconv/index.js +6 -6
- package/dist/gs/strconv/index.js.map +1 -1
- package/dist/gs/strings/index.d.ts +1 -1
- package/dist/gs/strings/index.js +1 -1
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/sync/atomic/index.d.ts +4 -4
- package/dist/gs/sync/atomic/index.js +4 -4
- package/dist/gs/sync/atomic/index.js.map +1 -1
- package/dist/gs/syscall/index.d.ts +6 -6
- package/dist/gs/syscall/index.js +34 -28
- package/dist/gs/syscall/index.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
- package/dist/gs/unicode/utf8/utf8.js +4 -2
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/builtin.ts +219 -0
- package/gs/builtin/slice.ts +2 -1
- package/gs/bytes/buffer.gs.ts +614 -0
- package/gs/bytes/bytes.gs.ts +1180 -0
- package/gs/bytes/godoc.txt +69 -0
- package/gs/bytes/index.ts +69 -0
- package/gs/bytes/iter.gs.ts +149 -0
- package/gs/bytes/reader.gs.ts +230 -0
- package/gs/github.com/pkg/errors/errors.ts +408 -238
- package/gs/github.com/pkg/errors/go113.ts +5 -6
- package/gs/github.com/pkg/errors/index.ts +12 -3
- package/gs/github.com/pkg/errors/stack.ts +107 -105
- package/gs/internal/abi/index.ts +37 -0
- package/gs/internal/bytealg/index.ts +149 -0
- package/gs/internal/byteorder/index.ts +5 -5
- package/gs/math/abs.gs.test.ts +1 -1
- package/gs/math/acosh.gs.test.ts +4 -2
- package/gs/math/asin.gs.test.ts +1 -1
- package/gs/math/asinh.gs.test.ts +7 -3
- package/gs/math/atan.gs.test.ts +1 -1
- package/gs/math/atan2.gs.test.ts +17 -9
- package/gs/math/atanh.gs.test.ts +1 -1
- package/gs/math/bits.gs.test.ts +1 -1
- package/gs/math/cbrt.gs.test.ts +1 -1
- package/gs/math/const.gs.test.ts +34 -8
- package/gs/math/copysign.gs.test.ts +7 -3
- package/gs/math/dim.gs.test.ts +19 -7
- package/gs/math/erf.gs.test.ts +1 -1
- package/gs/math/erfinv.gs.test.ts +4 -2
- package/gs/math/exp.gs.test.ts +1 -1
- package/gs/math/expm1.gs.test.ts +6 -4
- package/gs/math/floor.gs.test.ts +17 -4
- package/gs/math/fma.gs.test.ts +53 -53
- package/gs/math/frexp.gs.test.ts +112 -117
- package/gs/math/gamma.gs.test.ts +1 -1
- package/gs/math/hypot.gs.test.ts +53 -53
- package/gs/math/index.ts +80 -44
- package/gs/math/j0.gs.test.ts +6 -2
- package/gs/math/j1.gs.test.ts +6 -2
- package/gs/math/jn.gs.test.ts +9 -5
- package/gs/math/ldexp.gs.test.ts +103 -86
- package/gs/math/lgamma.gs.test.ts +10 -10
- package/gs/math/log.gs.test.ts +1 -1
- package/gs/math/log10.gs.test.ts +1 -1
- package/gs/math/log1p.gs.test.ts +2 -2
- package/gs/math/logb.gs.test.ts +1 -1
- package/gs/math/mod.gs.test.ts +2 -2
- package/gs/math/modf.gs.test.ts +7 -7
- package/gs/math/nextafter.gs.test.ts +9 -7
- package/gs/math/pow.gs.test.ts +6 -4
- package/gs/math/pow10.gs.test.ts +1 -1
- package/gs/math/remainder.gs.test.ts +1 -1
- package/gs/math/signbit.gs.test.ts +1 -1
- package/gs/math/sin.gs.test.ts +1 -1
- package/gs/math/sincos.gs.test.ts +33 -14
- package/gs/math/sinh.gs.test.ts +1 -1
- package/gs/math/sqrt.gs.test.ts +1 -1
- package/gs/math/tan.gs.test.ts +3 -3
- package/gs/math/tanh.gs.test.ts +1 -1
- package/gs/os/index.ts +128 -19
- package/gs/reflect/ANALYSIS.md +278 -0
- package/gs/reflect/deepequal.test.ts +41 -0
- package/gs/reflect/deepequal.ts +169 -0
- package/gs/reflect/function-types.test.ts +146 -0
- package/gs/reflect/godoc.txt +67 -0
- package/gs/reflect/index.ts +83 -0
- package/gs/reflect/iter.ts +44 -0
- package/gs/reflect/map.test.ts +30 -0
- package/gs/reflect/map.ts +85 -0
- package/gs/reflect/swapper.ts +52 -0
- package/gs/reflect/type.ts +1016 -0
- package/gs/reflect/types.ts +214 -0
- package/gs/reflect/value.ts +270 -0
- package/gs/reflect/visiblefields.ts +177 -0
- package/gs/strconv/index.ts +39 -6
- package/gs/strings/index.ts +7 -1
- package/gs/strings/replace.ts +1 -9
- package/gs/sync/atomic/index.ts +53 -4
- package/gs/syscall/index.ts +45 -37
- package/gs/unicode/utf8/utf8.ts +8 -5
- package/gs/unsafe/unsafe.ts +1 -1
- package/package.json +2 -1
- package/dist/gs/internal/testlog/index.d.ts +0 -1
- package/dist/gs/internal/testlog/index.js +0 -5
- package/dist/gs/internal/testlog/index.js.map +0 -1
- package/dist/gs/maps/iter.gs.d.ts +0 -7
- package/dist/gs/maps/iter.gs.js +0 -65
- package/dist/gs/maps/iter.gs.js.map +0 -1
- package/dist/gs/maps/maps.gs.d.ts +0 -7
- package/dist/gs/maps/maps.gs.js +0 -79
- package/dist/gs/maps/maps.gs.js.map +0 -1
- package/dist/gs/stringslite/index.d.ts +0 -1
- package/dist/gs/stringslite/index.js +0 -2
- package/dist/gs/stringslite/index.js.map +0 -1
- package/dist/gs/stringslite/strings.d.ts +0 -11
- package/dist/gs/stringslite/strings.js +0 -67
- package/dist/gs/stringslite/strings.js.map +0 -1
- package/gs/internal/testlog/index.ts +0 -7
package/gs/math/hypot.gs.test.ts
CHANGED
|
@@ -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
|
+
})
|
package/gs/math/index.ts
CHANGED
|
@@ -1,44 +1,80 @@
|
|
|
1
|
-
export { Abs } from
|
|
2
|
-
export { Acosh } from
|
|
3
|
-
export { Acos, Asin } from
|
|
4
|
-
export { Asinh } from
|
|
5
|
-
export { Atan } from
|
|
6
|
-
export { Atan2 } from
|
|
7
|
-
export { Atanh } from
|
|
8
|
-
export { Inf, IsInf, IsNaN, NaN } from
|
|
9
|
-
export { Cbrt } from
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
1
|
+
export { Abs } from './abs.gs.js'
|
|
2
|
+
export { Acosh } from './acosh.gs.js'
|
|
3
|
+
export { Acos, Asin } from './asin.gs.js'
|
|
4
|
+
export { Asinh } from './asinh.gs.js'
|
|
5
|
+
export { Atan } from './atan.gs.js'
|
|
6
|
+
export { Atan2 } from './atan2.gs.js'
|
|
7
|
+
export { Atanh } from './atanh.gs.js'
|
|
8
|
+
export { Inf, IsInf, IsNaN, NaN } from './bits.gs.js'
|
|
9
|
+
export { Cbrt } from './cbrt.gs.js'
|
|
10
|
+
export {
|
|
11
|
+
E,
|
|
12
|
+
Ln10,
|
|
13
|
+
Ln2,
|
|
14
|
+
Log10E,
|
|
15
|
+
Log2E,
|
|
16
|
+
MaxFloat32,
|
|
17
|
+
MaxFloat64,
|
|
18
|
+
MaxInt,
|
|
19
|
+
MaxInt16,
|
|
20
|
+
MaxInt32,
|
|
21
|
+
MaxInt64,
|
|
22
|
+
MaxInt8,
|
|
23
|
+
MaxUint,
|
|
24
|
+
MaxUint16,
|
|
25
|
+
MaxUint32,
|
|
26
|
+
MaxUint64,
|
|
27
|
+
MaxUint8,
|
|
28
|
+
MinInt,
|
|
29
|
+
MinInt16,
|
|
30
|
+
MinInt32,
|
|
31
|
+
MinInt64,
|
|
32
|
+
MinInt8,
|
|
33
|
+
Phi,
|
|
34
|
+
Pi,
|
|
35
|
+
SmallestNonzeroFloat32,
|
|
36
|
+
SmallestNonzeroFloat64,
|
|
37
|
+
Sqrt2,
|
|
38
|
+
SqrtE,
|
|
39
|
+
SqrtPhi,
|
|
40
|
+
SqrtPi,
|
|
41
|
+
} from './const.gs.js'
|
|
42
|
+
export { Copysign } from './copysign.gs.js'
|
|
43
|
+
export { Dim, Max, Min } from './dim.gs.js'
|
|
44
|
+
export { Erf, Erfc } from './erf.gs.js'
|
|
45
|
+
export { Erfcinv, Erfinv } from './erfinv.gs.js'
|
|
46
|
+
export { Exp, Exp2 } from './exp.gs.js'
|
|
47
|
+
export { Expm1 } from './expm1.gs.js'
|
|
48
|
+
export { Ceil, Floor, Round, RoundToEven, Trunc } from './floor.gs.js'
|
|
49
|
+
export { FMA } from './fma.gs.js'
|
|
50
|
+
export { Frexp } from './frexp.gs.js'
|
|
51
|
+
export { Gamma } from './gamma.gs.js'
|
|
52
|
+
export { Hypot } from './hypot.gs.js'
|
|
53
|
+
export { J0, Y0 } from './j0.gs.js'
|
|
54
|
+
export { J1, Y1 } from './j1.gs.js'
|
|
55
|
+
export { Jn, Yn } from './jn.gs.js'
|
|
56
|
+
export { Ldexp } from './ldexp.gs.js'
|
|
57
|
+
export { Lgamma } from './lgamma.gs.js'
|
|
58
|
+
export { Log } from './log.gs.js'
|
|
59
|
+
export { Log10, Log2 } from './log10.gs.js'
|
|
60
|
+
export { Log1p } from './log1p.gs.js'
|
|
61
|
+
export { Ilogb, Logb } from './logb.gs.js'
|
|
62
|
+
export { Mod } from './mod.gs.js'
|
|
63
|
+
export { Modf } from './modf.gs.js'
|
|
64
|
+
export { Nextafter, Nextafter32 } from './nextafter.gs.js'
|
|
65
|
+
export { Pow } from './pow.gs.js'
|
|
66
|
+
export { Pow10 } from './pow10.gs.js'
|
|
67
|
+
export { Remainder } from './remainder.gs.js'
|
|
68
|
+
export { Signbit } from './signbit.gs.js'
|
|
69
|
+
export { Cos, Sin } from './sin.gs.js'
|
|
70
|
+
export { Sincos } from './sincos.gs.js'
|
|
71
|
+
export { Cosh, Sinh } from './sinh.gs.js'
|
|
72
|
+
export { Sqrt } from './sqrt.gs.js'
|
|
73
|
+
export { Tan } from './tan.gs.js'
|
|
74
|
+
export { Tanh } from './tanh.gs.js'
|
|
75
|
+
export {
|
|
76
|
+
Float32bits,
|
|
77
|
+
Float32frombits,
|
|
78
|
+
Float64bits,
|
|
79
|
+
Float64frombits,
|
|
80
|
+
} from './unsafe.gs.js'
|
package/gs/math/j0.gs.test.ts
CHANGED
|
@@ -52,7 +52,11 @@ describe('Y0', () => {
|
|
|
52
52
|
expect(Y0(Number.POSITIVE_INFINITY)).toBe(0)
|
|
53
53
|
// Check if Y0(0) returns a very large negative number or -Infinity
|
|
54
54
|
const y0_zero = Y0(0)
|
|
55
|
-
expect(
|
|
55
|
+
expect(
|
|
56
|
+
y0_zero < -1e10 ||
|
|
57
|
+
y0_zero === Number.NEGATIVE_INFINITY ||
|
|
58
|
+
Number.isNaN(y0_zero),
|
|
59
|
+
).toBe(true)
|
|
56
60
|
expect(Number.isNaN(Y0(-1))).toBe(true)
|
|
57
61
|
expect(Number.isNaN(Y0(Number.NEGATIVE_INFINITY))).toBe(true)
|
|
58
62
|
expect(Number.isNaN(Y0(Number.NaN))).toBe(true)
|
|
@@ -71,4 +75,4 @@ describe('Y0', () => {
|
|
|
71
75
|
expect(Number.isNaN(Y0(-5))).toBe(true)
|
|
72
76
|
expect(Number.isNaN(Y0(-10))).toBe(true)
|
|
73
77
|
})
|
|
74
|
-
})
|
|
78
|
+
})
|
package/gs/math/j1.gs.test.ts
CHANGED
|
@@ -59,7 +59,11 @@ describe('Y1', () => {
|
|
|
59
59
|
expect(Y1(Number.POSITIVE_INFINITY)).toBe(0)
|
|
60
60
|
// Check if Y1(0) returns a very large negative number or -Infinity
|
|
61
61
|
const y1_zero = Y1(0)
|
|
62
|
-
expect(
|
|
62
|
+
expect(
|
|
63
|
+
y1_zero < -1e10 ||
|
|
64
|
+
y1_zero === Number.NEGATIVE_INFINITY ||
|
|
65
|
+
Number.isNaN(y1_zero),
|
|
66
|
+
).toBe(true)
|
|
63
67
|
expect(Number.isNaN(Y1(-1))).toBe(true)
|
|
64
68
|
expect(Number.isNaN(Y1(Number.NEGATIVE_INFINITY))).toBe(true)
|
|
65
69
|
expect(Number.isNaN(Y1(Number.NaN))).toBe(true)
|
|
@@ -78,4 +82,4 @@ describe('Y1', () => {
|
|
|
78
82
|
expect(Number.isNaN(Y1(-5))).toBe(true)
|
|
79
83
|
expect(Number.isNaN(Y1(-10))).toBe(true)
|
|
80
84
|
})
|
|
81
|
-
})
|
|
85
|
+
})
|
package/gs/math/jn.gs.test.ts
CHANGED
|
@@ -64,7 +64,7 @@ describe('Jn', () => {
|
|
|
64
64
|
const x = 5
|
|
65
65
|
const n = 2
|
|
66
66
|
const left = Jn(n - 1, x) + Jn(n + 1, x)
|
|
67
|
-
const right = (2 * n / x) * Jn(n, x)
|
|
67
|
+
const right = ((2 * n) / x) * Jn(n, x)
|
|
68
68
|
expect(left).toBeCloseTo(right, 14)
|
|
69
69
|
})
|
|
70
70
|
})
|
|
@@ -105,7 +105,9 @@ describe('Yn', () => {
|
|
|
105
105
|
it('should handle special values', () => {
|
|
106
106
|
// Check if NaN handling works properly - may return very large negative values
|
|
107
107
|
const yn0 = Yn(1, 0)
|
|
108
|
-
expect(
|
|
108
|
+
expect(
|
|
109
|
+
yn0 < -1e10 || yn0 === Number.NEGATIVE_INFINITY || Number.isNaN(yn0),
|
|
110
|
+
).toBe(true)
|
|
109
111
|
expect(Number.isNaN(Yn(1, -1))).toBe(true)
|
|
110
112
|
const nanResult = Yn(Number.NaN, 1)
|
|
111
113
|
expect(Number.isNaN(nanResult) || Number.isFinite(nanResult)).toBe(true)
|
|
@@ -117,7 +119,9 @@ describe('Yn', () => {
|
|
|
117
119
|
it('should be undefined for x <= 0', () => {
|
|
118
120
|
// Check if NaN handling works properly - may return very large negative values
|
|
119
121
|
const yn0 = Yn(1, 0)
|
|
120
|
-
expect(
|
|
122
|
+
expect(
|
|
123
|
+
yn0 < -1e10 || yn0 === Number.NEGATIVE_INFINITY || Number.isNaN(yn0),
|
|
124
|
+
).toBe(true)
|
|
121
125
|
expect(Number.isNaN(Yn(1, -1))).toBe(true)
|
|
122
126
|
expect(Number.isNaN(Yn(2, -5))).toBe(true)
|
|
123
127
|
})
|
|
@@ -127,7 +131,7 @@ describe('Yn', () => {
|
|
|
127
131
|
const x = 5
|
|
128
132
|
const n = 2
|
|
129
133
|
const left = Yn(n - 1, x) + Yn(n + 1, x)
|
|
130
|
-
const right = (2 * n / x) * Yn(n, x)
|
|
134
|
+
const right = ((2 * n) / x) * Yn(n, x)
|
|
131
135
|
expect(left).toBeCloseTo(right, 14)
|
|
132
136
|
})
|
|
133
|
-
})
|
|
137
|
+
})
|
package/gs/math/ldexp.gs.test.ts
CHANGED
|
@@ -1,128 +1,145 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { Ldexp, ldexp } from './ldexp.gs.js'
|
|
3
|
-
import { Frexp } from './frexp.gs.js'
|
|
4
|
-
import { Inf, NaN as GoNaN, IsNaN } from './bits.gs.js'
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Ldexp, ldexp } from './ldexp.gs.js'
|
|
3
|
+
import { Frexp } from './frexp.gs.js'
|
|
4
|
+
import { Inf, NaN as GoNaN, IsNaN } from './bits.gs.js'
|
|
5
5
|
|
|
6
6
|
describe('Ldexp', () => {
|
|
7
7
|
it('should compute frac × 2^exp correctly for basic cases', () => {
|
|
8
|
-
expect(Ldexp(0.5, 1)).toBe(1)
|
|
9
|
-
expect(Ldexp(0.5, 2)).toBe(2)
|
|
10
|
-
expect(Ldexp(0.5, 3)).toBe(4)
|
|
11
|
-
expect(Ldexp(0.5, 4)).toBe(8)
|
|
12
|
-
expect(Ldexp(1, 0)).toBe(1)
|
|
13
|
-
expect(Ldexp(1, 1)).toBe(2)
|
|
14
|
-
})
|
|
8
|
+
expect(Ldexp(0.5, 1)).toBe(1) // 0.5 × 2^1 = 1
|
|
9
|
+
expect(Ldexp(0.5, 2)).toBe(2) // 0.5 × 2^2 = 2
|
|
10
|
+
expect(Ldexp(0.5, 3)).toBe(4) // 0.5 × 2^3 = 4
|
|
11
|
+
expect(Ldexp(0.5, 4)).toBe(8) // 0.5 × 2^4 = 8
|
|
12
|
+
expect(Ldexp(1, 0)).toBe(1) // 1 × 2^0 = 1
|
|
13
|
+
expect(Ldexp(1, 1)).toBe(2) // 1 × 2^1 = 2
|
|
14
|
+
})
|
|
15
15
|
|
|
16
16
|
it('should handle negative exponents', () => {
|
|
17
|
-
expect(Ldexp(0.5, 0)).toBe(0.5)
|
|
18
|
-
expect(Ldexp(0.5, -1)).toBe(0.25)
|
|
19
|
-
expect(Ldexp(0.5, -2)).toBe(0.125)
|
|
20
|
-
expect(Ldexp(1, -1)).toBe(0.5)
|
|
21
|
-
expect(Ldexp(2, -1)).toBe(1)
|
|
22
|
-
})
|
|
17
|
+
expect(Ldexp(0.5, 0)).toBe(0.5) // 0.5 × 2^0 = 0.5
|
|
18
|
+
expect(Ldexp(0.5, -1)).toBe(0.25) // 0.5 × 2^-1 = 0.25
|
|
19
|
+
expect(Ldexp(0.5, -2)).toBe(0.125) // 0.5 × 2^-2 = 0.125
|
|
20
|
+
expect(Ldexp(1, -1)).toBe(0.5) // 1 × 2^-1 = 0.5
|
|
21
|
+
expect(Ldexp(2, -1)).toBe(1) // 2 × 2^-1 = 1
|
|
22
|
+
})
|
|
23
23
|
|
|
24
24
|
it('should handle negative fractions', () => {
|
|
25
|
-
expect(Ldexp(-0.5, 1)).toBe(-1)
|
|
26
|
-
expect(Ldexp(-0.5, 2)).toBe(-2)
|
|
27
|
-
expect(Ldexp(-1, 1)).toBe(-2)
|
|
28
|
-
expect(Ldexp(-0.5, -1)).toBe(-0.25)
|
|
29
|
-
})
|
|
25
|
+
expect(Ldexp(-0.5, 1)).toBe(-1) // -0.5 × 2^1 = -1
|
|
26
|
+
expect(Ldexp(-0.5, 2)).toBe(-2) // -0.5 × 2^2 = -2
|
|
27
|
+
expect(Ldexp(-1, 1)).toBe(-2) // -1 × 2^1 = -2
|
|
28
|
+
expect(Ldexp(-0.5, -1)).toBe(-0.25) // -0.5 × 2^-1 = -0.25
|
|
29
|
+
})
|
|
30
30
|
|
|
31
31
|
it('should handle zero values', () => {
|
|
32
|
-
expect(Ldexp(0, 5)).toBe(0)
|
|
33
|
-
expect(Ldexp(0, -5)).toBe(0)
|
|
34
|
-
expect(Ldexp(0, 0)).toBe(0)
|
|
35
|
-
|
|
32
|
+
expect(Ldexp(0, 5)).toBe(0) // 0 × 2^5 = 0
|
|
33
|
+
expect(Ldexp(0, -5)).toBe(0) // 0 × 2^-5 = 0
|
|
34
|
+
expect(Ldexp(0, 0)).toBe(0) // 0 × 2^0 = 0
|
|
35
|
+
|
|
36
36
|
// Preserve sign of zero
|
|
37
|
-
expect(Ldexp(-0, 5)).toBe(-0)
|
|
38
|
-
expect(Object.is(Ldexp(-0, 5), -0)).toBe(true)
|
|
39
|
-
})
|
|
37
|
+
expect(Ldexp(-0, 5)).toBe(-0)
|
|
38
|
+
expect(Object.is(Ldexp(-0, 5), -0)).toBe(true)
|
|
39
|
+
})
|
|
40
40
|
|
|
41
41
|
it('should handle infinity cases', () => {
|
|
42
|
-
expect(Ldexp(Inf(1), 5)).toBe(Inf(1))
|
|
43
|
-
expect(Ldexp(Inf(1), -5)).toBe(Inf(1))
|
|
44
|
-
expect(Ldexp(Inf(-1), 5)).toBe(Inf(-1))
|
|
45
|
-
expect(Ldexp(Inf(-1), -5)).toBe(Inf(-1))
|
|
46
|
-
expect(Ldexp(Inf(1), 0)).toBe(Inf(1))
|
|
47
|
-
})
|
|
42
|
+
expect(Ldexp(Inf(1), 5)).toBe(Inf(1)) // +Inf × 2^5 = +Inf
|
|
43
|
+
expect(Ldexp(Inf(1), -5)).toBe(Inf(1)) // +Inf × 2^-5 = +Inf
|
|
44
|
+
expect(Ldexp(Inf(-1), 5)).toBe(Inf(-1)) // -Inf × 2^5 = -Inf
|
|
45
|
+
expect(Ldexp(Inf(-1), -5)).toBe(Inf(-1)) // -Inf × 2^-5 = -Inf
|
|
46
|
+
expect(Ldexp(Inf(1), 0)).toBe(Inf(1)) // +Inf × 2^0 = +Inf
|
|
47
|
+
})
|
|
48
48
|
|
|
49
49
|
it('should handle NaN cases', () => {
|
|
50
|
-
expect(IsNaN(Ldexp(GoNaN(), 5))).toBe(true)
|
|
51
|
-
expect(IsNaN(Ldexp(GoNaN(), -5))).toBe(true)
|
|
52
|
-
expect(IsNaN(Ldexp(GoNaN(), 0))).toBe(true)
|
|
53
|
-
})
|
|
50
|
+
expect(IsNaN(Ldexp(GoNaN(), 5))).toBe(true)
|
|
51
|
+
expect(IsNaN(Ldexp(GoNaN(), -5))).toBe(true)
|
|
52
|
+
expect(IsNaN(Ldexp(GoNaN(), 0))).toBe(true)
|
|
53
|
+
})
|
|
54
54
|
|
|
55
55
|
it('should be the inverse of Frexp', () => {
|
|
56
|
-
const testValues = [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
const testValues = [
|
|
57
|
+
1, 2, 3, 4, 5, 8, 16, 0.5, 0.25, 0.125, 1.5, 3.14159, 100, 1000,
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
testValues.forEach((value) => {
|
|
61
|
+
const [frac, exp] = Frexp(value)
|
|
62
|
+
const reconstructed = Ldexp(frac, exp)
|
|
63
|
+
expect(reconstructed).toBeCloseTo(value, 10)
|
|
64
|
+
})
|
|
65
|
+
|
|
64
66
|
// Test negative values
|
|
65
|
-
testValues.forEach(value => {
|
|
66
|
-
const [frac, exp] = Frexp(-value)
|
|
67
|
-
const reconstructed = Ldexp(frac, exp)
|
|
68
|
-
expect(reconstructed).toBeCloseTo(-value, 10)
|
|
69
|
-
})
|
|
70
|
-
})
|
|
67
|
+
testValues.forEach((value) => {
|
|
68
|
+
const [frac, exp] = Frexp(-value)
|
|
69
|
+
const reconstructed = Ldexp(frac, exp)
|
|
70
|
+
expect(reconstructed).toBeCloseTo(-value, 10)
|
|
71
|
+
})
|
|
72
|
+
})
|
|
71
73
|
|
|
72
74
|
it('should handle large exponents', () => {
|
|
73
75
|
// Test with large positive exponent
|
|
74
|
-
expect(Ldexp(0.5, 10)).toBe(512)
|
|
75
|
-
expect(Ldexp(1, 10)).toBe(1024)
|
|
76
|
-
|
|
76
|
+
expect(Ldexp(0.5, 10)).toBe(512) // 0.5 × 2^10 = 512
|
|
77
|
+
expect(Ldexp(1, 10)).toBe(1024) // 1 × 2^10 = 1024
|
|
78
|
+
|
|
77
79
|
// Test with large negative exponent
|
|
78
|
-
expect(Ldexp(1, -10)).toBeCloseTo(1/1024, 10)
|
|
79
|
-
expect(Ldexp(2, -10)).toBeCloseTo(2/1024, 10)
|
|
80
|
-
})
|
|
80
|
+
expect(Ldexp(1, -10)).toBeCloseTo(1 / 1024, 10) // 1 × 2^-10 = 1/1024
|
|
81
|
+
expect(Ldexp(2, -10)).toBeCloseTo(2 / 1024, 10) // 2 × 2^-10 = 2/1024
|
|
82
|
+
})
|
|
81
83
|
|
|
82
84
|
it('should handle very large exponents that cause overflow', () => {
|
|
83
85
|
// Very large positive exponent should cause overflow to infinity
|
|
84
|
-
expect(Ldexp(1, 1024)).toBe(Number.POSITIVE_INFINITY)
|
|
85
|
-
expect(Ldexp(2, 1023)).toBe(Number.POSITIVE_INFINITY)
|
|
86
|
-
|
|
86
|
+
expect(Ldexp(1, 1024)).toBe(Number.POSITIVE_INFINITY)
|
|
87
|
+
expect(Ldexp(2, 1023)).toBe(Number.POSITIVE_INFINITY)
|
|
88
|
+
|
|
87
89
|
// Very large negative exponent should cause underflow to zero or very small number
|
|
88
90
|
const result = Ldexp(1, -1024)
|
|
89
91
|
expect(result).toBeLessThan(1e-300)
|
|
90
92
|
expect(result).toBeGreaterThanOrEqual(0)
|
|
91
|
-
})
|
|
93
|
+
})
|
|
92
94
|
|
|
93
95
|
it('should handle fractional inputs correctly', () => {
|
|
94
|
-
expect(Ldexp(0.75, 2)).toBe(3)
|
|
95
|
-
expect(Ldexp(0.25, 3)).toBe(2)
|
|
96
|
-
expect(Ldexp(1.5, 1)).toBe(3)
|
|
97
|
-
expect(Ldexp(1.25, 2)).toBe(5)
|
|
98
|
-
})
|
|
96
|
+
expect(Ldexp(0.75, 2)).toBe(3) // 0.75 × 2^2 = 3
|
|
97
|
+
expect(Ldexp(0.25, 3)).toBe(2) // 0.25 × 2^3 = 2
|
|
98
|
+
expect(Ldexp(1.5, 1)).toBe(3) // 1.5 × 2^1 = 3
|
|
99
|
+
expect(Ldexp(1.25, 2)).toBe(5) // 1.25 × 2^2 = 5
|
|
100
|
+
})
|
|
99
101
|
|
|
100
102
|
it('should be equivalent to frac * Math.pow(2, exp)', () => {
|
|
101
103
|
const testCases = [
|
|
102
|
-
[0.5, 1],
|
|
103
|
-
[0.
|
|
104
|
-
|
|
104
|
+
[0.5, 1],
|
|
105
|
+
[0.5, 2],
|
|
106
|
+
[0.5, -1],
|
|
107
|
+
[1, 5],
|
|
108
|
+
[1.5, 3],
|
|
109
|
+
[0.25, 4],
|
|
110
|
+
[-0.5, 2],
|
|
111
|
+
[-1, -3],
|
|
112
|
+
[2.5, -2],
|
|
113
|
+
]
|
|
105
114
|
|
|
106
115
|
testCases.forEach(([frac, exp]) => {
|
|
107
|
-
expect(Ldexp(frac, exp)).toBeCloseTo(frac * Math.pow(2, exp), 10)
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
})
|
|
116
|
+
expect(Ldexp(frac, exp)).toBeCloseTo(frac * Math.pow(2, exp), 10)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
})
|
|
111
120
|
|
|
112
121
|
describe('ldexp (lowercase)', () => {
|
|
113
122
|
it('should work identically to Ldexp', () => {
|
|
114
123
|
const testCases = [
|
|
115
|
-
[0.5, 1],
|
|
116
|
-
[0.
|
|
117
|
-
|
|
124
|
+
[0.5, 1],
|
|
125
|
+
[0.5, 2],
|
|
126
|
+
[0.5, -1],
|
|
127
|
+
[1, 5],
|
|
128
|
+
[1.5, 3],
|
|
129
|
+
[0.25, 4],
|
|
130
|
+
[-0.5, 2],
|
|
131
|
+
[-1, -3],
|
|
132
|
+
[0, 5],
|
|
133
|
+
[-0, 5],
|
|
134
|
+
]
|
|
118
135
|
|
|
119
136
|
testCases.forEach(([frac, exp]) => {
|
|
120
|
-
expect(ldexp(frac, exp)).toBe(Ldexp(frac, exp))
|
|
121
|
-
})
|
|
122
|
-
|
|
137
|
+
expect(ldexp(frac, exp)).toBe(Ldexp(frac, exp))
|
|
138
|
+
})
|
|
139
|
+
|
|
123
140
|
// Test special cases
|
|
124
|
-
expect(ldexp(Inf(1), 5)).toBe(Ldexp(Inf(1), 5))
|
|
125
|
-
expect(ldexp(Inf(-1), 5)).toBe(Ldexp(Inf(-1), 5))
|
|
126
|
-
expect(IsNaN(ldexp(GoNaN(), 5))).toBe(IsNaN(Ldexp(GoNaN(), 5)))
|
|
127
|
-
})
|
|
128
|
-
})
|
|
141
|
+
expect(ldexp(Inf(1), 5)).toBe(Ldexp(Inf(1), 5))
|
|
142
|
+
expect(ldexp(Inf(-1), 5)).toBe(Ldexp(Inf(-1), 5))
|
|
143
|
+
expect(IsNaN(ldexp(GoNaN(), 5))).toBe(IsNaN(Ldexp(GoNaN(), 5)))
|
|
144
|
+
})
|
|
145
|
+
})
|
|
@@ -6,15 +6,15 @@ describe('Lgamma', () => {
|
|
|
6
6
|
const [lgamma1, sign1] = Lgamma(1)
|
|
7
7
|
expect(lgamma1).toBe(0)
|
|
8
8
|
expect(sign1).toBe(1)
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
const [lgamma2, sign2] = Lgamma(2)
|
|
11
11
|
expect(lgamma2).toBe(0)
|
|
12
12
|
expect(sign2).toBe(1)
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
const [lgamma3, sign3] = Lgamma(3)
|
|
15
15
|
expect(lgamma3).toBeCloseTo(Math.log(2), 14)
|
|
16
16
|
expect(sign3).toBe(1)
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
const [lgamma4, sign4] = Lgamma(4)
|
|
19
19
|
expect(lgamma4).toBeCloseTo(Math.log(6), 14)
|
|
20
20
|
expect(sign4).toBe(1)
|
|
@@ -25,7 +25,7 @@ describe('Lgamma', () => {
|
|
|
25
25
|
// Relax tolerance for half-integers due to JavaScript precision limits
|
|
26
26
|
expect(lgamma05).toBeCloseTo(Math.log(Math.sqrt(Math.PI)), 6)
|
|
27
27
|
expect(sign05).toBe(1)
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
const [lgamma15, sign15] = Lgamma(1.5)
|
|
30
30
|
expect(lgamma15).toBeCloseTo(-0.1207822376352452, 6)
|
|
31
31
|
expect(sign15).toBe(1)
|
|
@@ -36,9 +36,9 @@ describe('Lgamma', () => {
|
|
|
36
36
|
// Relax tolerance for negative values due to JavaScript precision limits
|
|
37
37
|
expect(lgamma_05).toBeCloseTo(1.265512123484645, 5)
|
|
38
38
|
expect(sign_05).toBe(-1)
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
const [lgamma_15, sign_15] = Lgamma(-1.5)
|
|
41
|
-
expect(lgamma_15).toBeCloseTo(Math.log(4 * Math.sqrt(Math.PI) / 3), 5)
|
|
41
|
+
expect(lgamma_15).toBeCloseTo(Math.log((4 * Math.sqrt(Math.PI)) / 3), 5)
|
|
42
42
|
expect(sign_15).toBe(1)
|
|
43
43
|
})
|
|
44
44
|
|
|
@@ -46,11 +46,11 @@ describe('Lgamma', () => {
|
|
|
46
46
|
const [lgammaInf, signInf] = Lgamma(Number.POSITIVE_INFINITY)
|
|
47
47
|
expect(lgammaInf).toBe(Number.POSITIVE_INFINITY)
|
|
48
48
|
expect(signInf).toBe(1)
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
const [lgammaNegInf, signNegInf] = Lgamma(Number.NEGATIVE_INFINITY)
|
|
51
51
|
expect(lgammaNegInf).toBe(Number.NEGATIVE_INFINITY)
|
|
52
52
|
expect(signNegInf).toBe(1)
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
const [lgammaNaN, signNaN] = Lgamma(Number.NaN)
|
|
55
55
|
expect(Number.isNaN(lgammaNaN)).toBe(true)
|
|
56
56
|
// Allow either NaN or finite value for sign as implementations may vary
|
|
@@ -62,7 +62,7 @@ describe('Lgamma', () => {
|
|
|
62
62
|
// Allow either NaN or very large values as implementations may vary
|
|
63
63
|
expect(Number.isNaN(lgamma_1) || Math.abs(lgamma_1) > 1e10).toBe(true)
|
|
64
64
|
expect(Number.isNaN(sign_1) || Number.isFinite(sign_1)).toBe(true)
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
const [lgamma_2, sign_2] = Lgamma(-2)
|
|
67
67
|
expect(Number.isNaN(lgamma_2) || Math.abs(lgamma_2) > 1e10).toBe(true)
|
|
68
68
|
expect(Number.isNaN(sign_2) || Number.isFinite(sign_2)).toBe(true)
|
|
@@ -99,4 +99,4 @@ describe('Lgamma', () => {
|
|
|
99
99
|
const expected = Math.log(Math.PI / Math.sin(Math.PI * x))
|
|
100
100
|
expect(lgamma_x + lgamma_1_minus_x).toBeCloseTo(expected, 5)
|
|
101
101
|
})
|
|
102
|
-
})
|
|
102
|
+
})
|
package/gs/math/log.gs.test.ts
CHANGED
package/gs/math/log10.gs.test.ts
CHANGED
package/gs/math/log1p.gs.test.ts
CHANGED
|
@@ -37,7 +37,7 @@ describe('Log1p', () => {
|
|
|
37
37
|
const x = 1e-15
|
|
38
38
|
const log1pResult = Log1p(x)
|
|
39
39
|
const logResult = Math.log(1 + x)
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
// For very small x, log1p should be more accurate
|
|
42
42
|
expect(Math.abs(log1pResult - x)).toBeLessThan(Math.abs(logResult - x))
|
|
43
43
|
})
|
|
@@ -52,4 +52,4 @@ describe('log1p', () => {
|
|
|
52
52
|
expect(Number.isNaN(log1p(Number.NaN))).toBe(true)
|
|
53
53
|
expect(Number.isNaN(log1p(-2))).toBe(true)
|
|
54
54
|
})
|
|
55
|
-
})
|
|
55
|
+
})
|