goscript 0.0.34 → 0.0.36
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 +28 -20
- package/compiler/analysis_test.go +14 -0
- package/compiler/assignment.go +19 -7
- package/compiler/compiler.go +15 -99
- package/compiler/composite-lit.go +60 -17
- package/compiler/decl.go +1 -1
- package/compiler/expr-call.go +233 -35
- package/compiler/expr-selector.go +28 -2
- package/compiler/expr.go +13 -37
- package/compiler/lit.go +111 -2
- package/compiler/primitive.go +6 -6
- package/compiler/protobuf.go +0 -5
- package/compiler/sanitize.go +101 -0
- package/compiler/spec-struct.go +41 -8
- package/compiler/spec-value.go +29 -18
- package/compiler/stmt-assign.go +22 -1
- package/compiler/stmt.go +26 -9
- package/compiler/type.go +3 -3
- package/dist/gs/builtin/builtin.d.ts +3 -2
- package/dist/gs/builtin/builtin.js +2 -1
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +7 -1
- package/dist/gs/builtin/slice.js +112 -22
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/errors.d.ts +13 -0
- package/dist/gs/github.com/pkg/errors/errors.js +232 -0
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/go113.d.ts +4 -0
- package/dist/gs/github.com/pkg/errors/go113.js +34 -0
- package/dist/gs/github.com/pkg/errors/go113.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/index.d.ts +3 -0
- package/dist/gs/github.com/pkg/errors/index.js +4 -0
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/stack.d.ts +32 -0
- package/dist/gs/github.com/pkg/errors/stack.js +111 -0
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -0
- package/dist/gs/maps/index.d.ts +2 -2
- package/dist/gs/maps/index.js +2 -2
- package/dist/gs/maps/index.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +7 -0
- package/dist/gs/maps/iter.js +57 -0
- package/dist/gs/maps/iter.js.map +1 -0
- package/dist/gs/maps/maps.d.ts +7 -0
- package/dist/gs/maps/maps.js +67 -0
- package/dist/gs/maps/maps.js.map +1 -0
- package/dist/gs/math/abs.gs.d.ts +1 -0
- package/dist/gs/math/abs.gs.js +10 -0
- package/dist/gs/math/abs.gs.js.map +1 -0
- package/dist/gs/math/acosh.gs.d.ts +2 -0
- package/dist/gs/math/acosh.gs.js +14 -0
- package/dist/gs/math/acosh.gs.js.map +1 -0
- package/dist/gs/math/asin.gs.d.ts +4 -0
- package/dist/gs/math/asin.gs.js +24 -0
- package/dist/gs/math/asin.gs.js.map +1 -0
- package/dist/gs/math/asinh.gs.d.ts +2 -0
- package/dist/gs/math/asinh.gs.js +14 -0
- package/dist/gs/math/asinh.gs.js.map +1 -0
- package/dist/gs/math/atan.gs.d.ts +4 -0
- package/dist/gs/math/atan.gs.js +22 -0
- package/dist/gs/math/atan.gs.js.map +1 -0
- package/dist/gs/math/atan2.gs.d.ts +2 -0
- package/dist/gs/math/atan2.gs.js +30 -0
- package/dist/gs/math/atan2.gs.js.map +1 -0
- package/dist/gs/math/atanh.gs.d.ts +2 -0
- package/dist/gs/math/atanh.gs.js +16 -0
- package/dist/gs/math/atanh.gs.js.map +1 -0
- package/dist/gs/math/bits.gs.d.ts +5 -0
- package/dist/gs/math/bits.gs.js +46 -0
- package/dist/gs/math/bits.gs.js.map +1 -0
- package/dist/gs/math/cbrt.gs.d.ts +2 -0
- package/dist/gs/math/cbrt.gs.js +14 -0
- package/dist/gs/math/cbrt.gs.js.map +1 -0
- package/dist/gs/math/const.gs.d.ts +30 -0
- package/dist/gs/math/const.gs.js +61 -0
- package/dist/gs/math/const.gs.js.map +1 -0
- package/dist/gs/math/copysign.gs.d.ts +1 -0
- package/dist/gs/math/copysign.gs.js +20 -0
- package/dist/gs/math/copysign.gs.js.map +1 -0
- package/dist/gs/math/dim.gs.d.ts +5 -0
- package/dist/gs/math/dim.gs.js +69 -0
- package/dist/gs/math/dim.gs.js.map +1 -0
- package/dist/gs/math/erf.gs.d.ts +4 -0
- package/dist/gs/math/erf.gs.js +336 -0
- package/dist/gs/math/erf.gs.js.map +1 -0
- package/dist/gs/math/erfinv.gs.d.ts +2 -0
- package/dist/gs/math/erfinv.gs.js +118 -0
- package/dist/gs/math/erfinv.gs.js.map +1 -0
- package/dist/gs/math/exp.gs.d.ts +5 -0
- package/dist/gs/math/exp.gs.js +30 -0
- package/dist/gs/math/exp.gs.js.map +1 -0
- package/dist/gs/math/expm1.gs.d.ts +2 -0
- package/dist/gs/math/expm1.gs.js +17 -0
- package/dist/gs/math/expm1.gs.js.map +1 -0
- package/dist/gs/math/floor.gs.d.ts +8 -0
- package/dist/gs/math/floor.gs.js +75 -0
- package/dist/gs/math/floor.gs.js.map +1 -0
- package/dist/gs/math/fma.gs.d.ts +1 -0
- package/dist/gs/math/fma.gs.js +8 -0
- package/dist/gs/math/fma.gs.js.map +1 -0
- package/dist/gs/math/frexp.gs.d.ts +2 -0
- package/dist/gs/math/frexp.gs.js +28 -0
- package/dist/gs/math/frexp.gs.js.map +1 -0
- package/dist/gs/math/gamma.gs.d.ts +3 -0
- package/dist/gs/math/gamma.gs.js +149 -0
- package/dist/gs/math/gamma.gs.js.map +1 -0
- package/dist/gs/math/hypot.gs.d.ts +2 -0
- package/dist/gs/math/hypot.gs.js +16 -0
- package/dist/gs/math/hypot.gs.js.map +1 -0
- package/dist/gs/math/index.d.ts +44 -0
- package/dist/gs/math/index.js +45 -0
- package/dist/gs/math/index.js.map +1 -0
- package/dist/gs/math/j0.gs.d.ts +4 -0
- package/dist/gs/math/j0.gs.js +228 -0
- package/dist/gs/math/j0.gs.js.map +1 -0
- package/dist/gs/math/j1.gs.d.ts +4 -0
- package/dist/gs/math/j1.gs.js +211 -0
- package/dist/gs/math/j1.gs.js.map +1 -0
- package/dist/gs/math/jn.gs.d.ts +2 -0
- package/dist/gs/math/jn.gs.js +412 -0
- package/dist/gs/math/jn.gs.js.map +1 -0
- package/dist/gs/math/ldexp.gs.d.ts +2 -0
- package/dist/gs/math/ldexp.gs.js +20 -0
- package/dist/gs/math/ldexp.gs.js.map +1 -0
- package/dist/gs/math/lgamma.gs.d.ts +2 -0
- package/dist/gs/math/lgamma.gs.js +243 -0
- package/dist/gs/math/lgamma.gs.js.map +1 -0
- package/dist/gs/math/log.gs.d.ts +2 -0
- package/dist/gs/math/log.gs.js +16 -0
- package/dist/gs/math/log.gs.js.map +1 -0
- package/dist/gs/math/log10.gs.d.ts +4 -0
- package/dist/gs/math/log10.gs.js +17 -0
- package/dist/gs/math/log10.gs.js.map +1 -0
- package/dist/gs/math/log1p.gs.d.ts +2 -0
- package/dist/gs/math/log1p.gs.js +17 -0
- package/dist/gs/math/log1p.gs.js.map +1 -0
- package/dist/gs/math/logb.gs.d.ts +3 -0
- package/dist/gs/math/logb.gs.js +43 -0
- package/dist/gs/math/logb.gs.js.map +1 -0
- package/dist/gs/math/mod.gs.d.ts +2 -0
- package/dist/gs/math/mod.gs.js +26 -0
- package/dist/gs/math/mod.gs.js.map +1 -0
- package/dist/gs/math/modf.gs.d.ts +2 -0
- package/dist/gs/math/modf.gs.js +24 -0
- package/dist/gs/math/modf.gs.js.map +1 -0
- package/dist/gs/math/nextafter.gs.d.ts +2 -0
- package/dist/gs/math/nextafter.gs.js +66 -0
- package/dist/gs/math/nextafter.gs.js.map +1 -0
- package/dist/gs/math/pow.gs.d.ts +3 -0
- package/dist/gs/math/pow.gs.js +40 -0
- package/dist/gs/math/pow.gs.js.map +1 -0
- package/dist/gs/math/pow10.gs.d.ts +1 -0
- package/dist/gs/math/pow10.gs.js +14 -0
- package/dist/gs/math/pow10.gs.js.map +1 -0
- package/dist/gs/math/remainder.gs.d.ts +2 -0
- package/dist/gs/math/remainder.gs.js +25 -0
- package/dist/gs/math/remainder.gs.js.map +1 -0
- package/dist/gs/math/signbit.gs.d.ts +1 -0
- package/dist/gs/math/signbit.gs.js +5 -0
- package/dist/gs/math/signbit.gs.js.map +1 -0
- package/dist/gs/math/sin.gs.d.ts +4 -0
- package/dist/gs/math/sin.gs.js +29 -0
- package/dist/gs/math/sin.gs.js.map +1 -0
- package/dist/gs/math/sincos.gs.d.ts +1 -0
- package/dist/gs/math/sincos.gs.js +11 -0
- package/dist/gs/math/sincos.gs.js.map +1 -0
- package/dist/gs/math/sinh.gs.d.ts +4 -0
- package/dist/gs/math/sinh.gs.js +27 -0
- package/dist/gs/math/sinh.gs.js.map +1 -0
- package/dist/gs/math/sqrt.gs.d.ts +2 -0
- package/dist/gs/math/sqrt.gs.js +15 -0
- package/dist/gs/math/sqrt.gs.js.map +1 -0
- package/dist/gs/math/tan.gs.d.ts +2 -0
- package/dist/gs/math/tan.gs.js +17 -0
- package/dist/gs/math/tan.gs.js.map +1 -0
- package/dist/gs/math/tanh.gs.d.ts +2 -0
- package/dist/gs/math/tanh.gs.js +17 -0
- package/dist/gs/math/tanh.gs.js.map +1 -0
- package/dist/gs/math/trig_reduce.gs.d.ts +1 -0
- package/dist/gs/math/trig_reduce.gs.js +62 -0
- package/dist/gs/math/trig_reduce.gs.js.map +1 -0
- package/dist/gs/math/unsafe.gs.d.ts +4 -0
- package/dist/gs/math/unsafe.gs.js +47 -0
- package/dist/gs/math/unsafe.gs.js.map +1 -0
- package/dist/gs/strconv/atob.gs.d.ts +4 -0
- package/dist/gs/strconv/atob.gs.js +42 -0
- package/dist/gs/strconv/atob.gs.js.map +1 -0
- package/dist/gs/strconv/atof.gs.d.ts +2 -0
- package/dist/gs/strconv/atof.gs.js +51 -0
- package/dist/gs/strconv/atof.gs.js.map +1 -0
- package/dist/gs/strconv/atoi.gs.d.ts +33 -0
- package/dist/gs/strconv/atoi.gs.js +200 -0
- package/dist/gs/strconv/atoi.gs.js.map +1 -0
- package/dist/gs/strconv/doc.gs.d.ts +1 -0
- package/dist/gs/strconv/doc.gs.js +2 -0
- package/dist/gs/strconv/doc.gs.js.map +1 -0
- package/dist/gs/strconv/ftoa.gs.d.ts +3 -0
- package/dist/gs/strconv/ftoa.gs.js +58 -0
- package/dist/gs/strconv/ftoa.gs.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +6 -0
- package/dist/gs/strconv/index.js +7 -0
- package/dist/gs/strconv/index.js.map +1 -0
- package/dist/gs/strconv/itoa.gs.d.ts +6 -0
- package/dist/gs/strconv/itoa.gs.js +37 -0
- package/dist/gs/strconv/itoa.gs.js.map +1 -0
- package/dist/gs/strconv/quote.gs.d.ts +19 -0
- package/dist/gs/strconv/quote.gs.js +217 -0
- package/dist/gs/strconv/quote.gs.js.map +1 -0
- package/dist/gs/strings/index.d.ts +3 -0
- package/dist/gs/strings/index.js +4 -0
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/strings/replace.d.ts +0 -74
- package/dist/gs/strings/replace.js +6 -204
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/search.d.ts +0 -1
- package/dist/gs/strings/search.js +0 -21
- package/dist/gs/strings/search.js.map +1 -1
- package/dist/gs/sync/atomic/doc.gs.d.ts +28 -0
- package/dist/gs/sync/atomic/doc.gs.js +265 -0
- package/dist/gs/sync/atomic/doc.gs.js.map +1 -0
- package/dist/gs/sync/atomic/doc_64.gs.d.ts +15 -0
- package/dist/gs/sync/atomic/doc_64.gs.js +165 -0
- package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -0
- package/dist/gs/sync/atomic/index.d.ts +4 -0
- package/dist/gs/sync/atomic/index.js +5 -0
- package/dist/gs/sync/atomic/index.js.map +1 -0
- package/dist/gs/sync/atomic/type.gs.d.ts +130 -0
- package/dist/gs/sync/atomic/type.gs.js +433 -0
- package/dist/gs/sync/atomic/type.gs.js.map +1 -0
- package/dist/gs/sync/atomic/value.gs.d.ts +19 -0
- package/dist/gs/sync/atomic/value.gs.js +116 -0
- package/dist/gs/sync/atomic/value.gs.js.map +1 -0
- package/dist/gs/unsafe/unsafe.d.ts +1 -0
- package/dist/gs/unsafe/unsafe.js +5 -0
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/builtin.ts +9 -7
- package/gs/builtin/map.ts +5 -1
- package/gs/builtin/slice.ts +152 -24
- package/gs/github.com/pkg/errors/errors.ts +307 -0
- package/gs/github.com/pkg/errors/go113.ts +39 -0
- package/gs/github.com/pkg/errors/index.ts +3 -0
- package/gs/github.com/pkg/errors/stack.ts +127 -0
- package/gs/maps/index.ts +2 -2
- package/gs/maps/iter.ts +67 -0
- package/gs/maps/maps.ts +89 -0
- package/gs/math/TODO.md +156 -0
- package/gs/math/abs.gs.test.ts +29 -0
- package/gs/math/abs.gs.ts +13 -0
- package/gs/math/acosh.gs.test.ts +39 -0
- package/gs/math/acosh.gs.ts +21 -0
- package/gs/math/asin.gs.test.ts +66 -0
- package/gs/math/asin.gs.ts +27 -0
- package/gs/math/asinh.gs.test.ts +37 -0
- package/gs/math/asinh.gs.ts +21 -0
- package/gs/math/atan.gs.test.ts +49 -0
- package/gs/math/atan.gs.ts +27 -0
- package/gs/math/atan2.gs.test.ts +55 -0
- package/gs/math/atan2.gs.ts +37 -0
- package/gs/math/atanh.gs.test.ts +47 -0
- package/gs/math/atanh.gs.ts +21 -0
- package/gs/math/bits.gs.test.ts +88 -0
- package/gs/math/bits.gs.ts +61 -0
- package/gs/math/cbrt.gs.test.ts +57 -0
- package/gs/math/cbrt.gs.ts +20 -0
- package/gs/math/const.gs.test.ts +54 -0
- package/gs/math/const.gs.ts +93 -0
- package/gs/math/copysign.gs.test.ts +44 -0
- package/gs/math/copysign.gs.ts +27 -0
- package/gs/math/dim.gs.test.ts +102 -0
- package/gs/math/dim.gs.ts +84 -0
- package/gs/math/erf.gs.test.ts +92 -0
- package/gs/math/erf.gs.ts +409 -0
- package/gs/math/erfinv.gs.test.ts +104 -0
- package/gs/math/erfinv.gs.ts +169 -0
- package/gs/math/exp.gs.test.ts +82 -0
- package/gs/math/exp.gs.ts +39 -0
- package/gs/math/expm1.gs.test.ts +48 -0
- package/gs/math/expm1.gs.ts +23 -0
- package/gs/math/floor.gs.test.ts +146 -0
- package/gs/math/floor.gs.ts +88 -0
- package/gs/math/fma.gs.test.ts +83 -0
- package/gs/math/fma.gs.ts +7 -0
- package/gs/math/frexp.gs.test.ts +146 -0
- package/gs/math/frexp.gs.ts +37 -0
- package/gs/math/gamma.gs.test.ts +66 -0
- package/gs/math/gamma.gs.ts +158 -0
- package/gs/math/hypot.gs.test.ts +73 -0
- package/gs/math/hypot.gs.ts +23 -0
- package/gs/math/index.ts +44 -0
- package/gs/math/j0.gs.test.ts +74 -0
- package/gs/math/j0.gs.ts +257 -0
- package/gs/math/j1.gs.test.ts +81 -0
- package/gs/math/j1.gs.ts +231 -0
- package/gs/math/jn.gs.test.ts +133 -0
- package/gs/math/jn.gs.ts +447 -0
- package/gs/math/ldexp.gs.test.ts +128 -0
- package/gs/math/ldexp.gs.ts +28 -0
- package/gs/math/lgamma.gs.test.ts +102 -0
- package/gs/math/lgamma.gs.ts +251 -0
- package/gs/math/log.gs.test.ts +40 -0
- package/gs/math/log.gs.ts +21 -0
- package/gs/math/log10.gs.test.ts +80 -0
- package/gs/math/log10.gs.ts +25 -0
- package/gs/math/log1p.gs.test.ts +55 -0
- package/gs/math/log1p.gs.ts +24 -0
- package/gs/math/logb.gs.test.ts +87 -0
- package/gs/math/logb.gs.ts +54 -0
- package/gs/math/mod.gs.test.ts +64 -0
- package/gs/math/mod.gs.ts +36 -0
- package/gs/math/modf.gs.test.ts +80 -0
- package/gs/math/modf.gs.ts +32 -0
- package/gs/math/nextafter.gs.test.ts +107 -0
- package/gs/math/nextafter.gs.ts +71 -0
- package/gs/math/pow.gs.test.ts +103 -0
- package/gs/math/pow.gs.ts +55 -0
- package/gs/math/pow10.gs.test.ts +58 -0
- package/gs/math/pow10.gs.ts +19 -0
- package/gs/math/remainder.gs.test.ts +70 -0
- package/gs/math/remainder.gs.ts +33 -0
- package/gs/math/signbit.gs.test.ts +33 -0
- package/gs/math/signbit.gs.ts +8 -0
- package/gs/math/sin.gs.test.ts +83 -0
- package/gs/math/sin.gs.ts +38 -0
- package/gs/math/sincos.gs.test.ts +91 -0
- package/gs/math/sincos.gs.ts +15 -0
- package/gs/math/sinh.gs.test.ts +66 -0
- package/gs/math/sinh.gs.ts +34 -0
- package/gs/math/sqrt.gs.test.ts +49 -0
- package/gs/math/sqrt.gs.ts +20 -0
- package/gs/math/tan.gs.test.ts +50 -0
- package/gs/math/tan.gs.ts +23 -0
- package/gs/math/tanh.gs.test.ts +52 -0
- package/gs/math/tanh.gs.ts +23 -0
- package/gs/math/trig_reduce.gs.ts +66 -0
- package/gs/math/unsafe.gs.ts +52 -0
- package/gs/strconv/atob.gs.ts +45 -0
- package/gs/strconv/atof.gs.ts +60 -0
- package/gs/strconv/atoi.gs.ts +243 -0
- package/gs/strconv/doc.gs.ts +2 -0
- package/gs/strconv/ftoa.gs.ts +66 -0
- package/gs/strconv/index.ts +6 -0
- package/gs/strconv/itoa.gs.ts +41 -0
- package/gs/strconv/quote.gs.ts +245 -0
- package/gs/strings/index.ts +4 -0
- package/gs/strings/replace.ts +9 -237
- package/gs/strings/search.ts +0 -28
- package/gs/sync/atomic/doc.gs.ts +276 -0
- package/gs/sync/atomic/doc_64.gs.ts +168 -0
- package/gs/sync/atomic/index.ts +4 -0
- package/gs/sync/atomic/type.gs.ts +596 -0
- package/gs/sync/atomic/value.gs.ts +158 -0
- package/gs/unsafe/unsafe.ts +6 -0
- package/package.json +1 -1
- package/gs/maps/iter.gs.ts +0 -71
- package/gs/maps/maps.gs.ts +0 -87
- package/gs/stringslite/godoc.txt +0 -17
- package/gs/stringslite/index.ts +0 -1
- package/gs/stringslite/strings.ts +0 -82
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Pow10 } from './pow10.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Pow10', () => {
|
|
5
|
+
it('should return correct powers of 10 for small integers', () => {
|
|
6
|
+
expect(Pow10(0)).toBe(1)
|
|
7
|
+
expect(Pow10(1)).toBe(10)
|
|
8
|
+
expect(Pow10(2)).toBe(100)
|
|
9
|
+
expect(Pow10(3)).toBe(1000)
|
|
10
|
+
expect(Pow10(4)).toBe(10000)
|
|
11
|
+
expect(Pow10(5)).toBe(100000)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should return correct powers of 10 for negative integers', () => {
|
|
15
|
+
expect(Pow10(-1)).toBe(0.1)
|
|
16
|
+
expect(Pow10(-2)).toBe(0.01)
|
|
17
|
+
expect(Pow10(-3)).toBe(0.001)
|
|
18
|
+
expect(Pow10(-4)).toBeCloseTo(0.0001, 15)
|
|
19
|
+
expect(Pow10(-5)).toBeCloseTo(0.00001, 15)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should return correct powers of 10 for fractional exponents', () => {
|
|
23
|
+
expect(Pow10(0.5)).toBeCloseTo(Math.sqrt(10), 15)
|
|
24
|
+
expect(Pow10(1.5)).toBeCloseTo(10 * Math.sqrt(10), 14)
|
|
25
|
+
expect(Pow10(-0.5)).toBeCloseTo(1 / Math.sqrt(10), 15)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('should handle large positive exponents', () => {
|
|
29
|
+
expect(Pow10(100)).toBe(1e100)
|
|
30
|
+
expect(Pow10(200)).toBe(1e200)
|
|
31
|
+
expect(Pow10(300)).toBe(1e300)
|
|
32
|
+
expect(Pow10(308)).toBe(1e308)
|
|
33
|
+
expect(Pow10(309)).toBe(Number.POSITIVE_INFINITY)
|
|
34
|
+
expect(Pow10(400)).toBe(Number.POSITIVE_INFINITY)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should handle large negative exponents', () => {
|
|
38
|
+
expect(Pow10(-100)).toBe(1e-100)
|
|
39
|
+
expect(Pow10(-200)).toBe(1e-200)
|
|
40
|
+
expect(Pow10(-300)).toBe(1e-300)
|
|
41
|
+
expect(Pow10(-320)).toBe(1e-320)
|
|
42
|
+
expect(Pow10(-324)).toBe(0)
|
|
43
|
+
expect(Pow10(-400)).toBe(0)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should handle special values', () => {
|
|
47
|
+
expect(Pow10(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
|
|
48
|
+
expect(Pow10(Number.NEGATIVE_INFINITY)).toBe(0)
|
|
49
|
+
expect(Number.isNaN(Pow10(Number.NaN))).toBe(true)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should match Math.pow(10, n)', () => {
|
|
53
|
+
const testValues = [0, 1, 2, 3, -1, -2, -3, 0.5, 1.5, -0.5, 10, -10]
|
|
54
|
+
for (const n of testValues) {
|
|
55
|
+
expect(Pow10(n)).toBeCloseTo(Math.pow(10, n), 15)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { Inf } from "./bits.gs.js";
|
|
3
|
+
|
|
4
|
+
let pow10tab = $.arrayToSlice<number>([1e00, 1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29, 1e30, 1e31])
|
|
5
|
+
|
|
6
|
+
let pow10postab32 = $.arrayToSlice<number>([1e00, 1e32, 1e64, 1e96, 1e128, 1e160, 1e192, 1e224, 1e256, 1e288])
|
|
7
|
+
|
|
8
|
+
let pow10negtab32 = $.arrayToSlice<number>([1e-00, 1e-32, 1e-64, 1e-96, 1e-128, 1e-160, 1e-192, 1e-224, 1e-256, 1e-288, 1e-320])
|
|
9
|
+
|
|
10
|
+
// Pow10 returns 10**n, the base-10 exponential of n.
|
|
11
|
+
//
|
|
12
|
+
// Special cases are:
|
|
13
|
+
//
|
|
14
|
+
// Pow10(n) = 0 for n < -323
|
|
15
|
+
// Pow10(n) = +Inf for n > 308
|
|
16
|
+
export function Pow10(n: number): number {
|
|
17
|
+
return Math.pow(10, n)
|
|
18
|
+
}
|
|
19
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Remainder, remainder } from './remainder.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Remainder', () => {
|
|
5
|
+
it('should return correct IEEE 754 remainder for normal values', () => {
|
|
6
|
+
expect(Remainder(5, 3)).toBeCloseTo(-1, 15)
|
|
7
|
+
expect(Remainder(7, 3)).toBeCloseTo(1, 15)
|
|
8
|
+
expect(Remainder(8, 3)).toBeCloseTo(-1, 15)
|
|
9
|
+
expect(Remainder(9, 3)).toBeCloseTo(0, 15)
|
|
10
|
+
expect(Remainder(10, 3)).toBeCloseTo(1, 15)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('should handle negative values correctly', () => {
|
|
14
|
+
expect(Remainder(-5, 3)).toBeCloseTo(1, 15)
|
|
15
|
+
expect(Remainder(5, -3)).toBeCloseTo(-1, 15)
|
|
16
|
+
expect(Remainder(-5, -3)).toBeCloseTo(1, 15)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should handle fractional values', () => {
|
|
20
|
+
expect(Remainder(5.5, 2)).toBeCloseTo(-0.5, 15)
|
|
21
|
+
expect(Remainder(7.5, 2)).toBeCloseTo(-0.5, 15)
|
|
22
|
+
expect(Remainder(6.5, 2)).toBeCloseTo(0.5, 15)
|
|
23
|
+
expect(Remainder(8.5, 2)).toBeCloseTo(0.5, 15)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should return zero when x is a multiple of y', () => {
|
|
27
|
+
expect(Remainder(6, 3)).toBe(0)
|
|
28
|
+
expect(Remainder(12, 4)).toBe(0)
|
|
29
|
+
expect(Remainder(-8, 2)).toBe(0)
|
|
30
|
+
expect(Remainder(15, 5)).toBe(0)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should handle special cases with NaN', () => {
|
|
34
|
+
expect(Number.isNaN(Remainder(Number.NaN, 3))).toBe(true)
|
|
35
|
+
expect(Number.isNaN(Remainder(5, Number.NaN))).toBe(true)
|
|
36
|
+
expect(Number.isNaN(Remainder(Number.NaN, Number.NaN))).toBe(true)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should handle special cases with infinity', () => {
|
|
40
|
+
expect(Number.isNaN(Remainder(Number.POSITIVE_INFINITY, 3))).toBe(true)
|
|
41
|
+
expect(Number.isNaN(Remainder(Number.NEGATIVE_INFINITY, 3))).toBe(true)
|
|
42
|
+
expect(Remainder(5, Number.POSITIVE_INFINITY)).toBe(5)
|
|
43
|
+
expect(Remainder(5, Number.NEGATIVE_INFINITY)).toBe(5)
|
|
44
|
+
expect(Remainder(-7, Number.POSITIVE_INFINITY)).toBe(-7)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('should handle division by zero', () => {
|
|
48
|
+
expect(Number.isNaN(Remainder(5, 0))).toBe(true)
|
|
49
|
+
expect(Number.isNaN(Remainder(-5, 0))).toBe(true)
|
|
50
|
+
expect(Number.isNaN(Remainder(0, 0))).toBe(true)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should handle zero dividend', () => {
|
|
54
|
+
expect(Remainder(0, 3)).toBe(0)
|
|
55
|
+
expect(Remainder(0, -3)).toBe(0)
|
|
56
|
+
const result = Remainder(-0, 3)
|
|
57
|
+
expect(result === 0 || Object.is(result, -0)).toBe(true)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe('remainder', () => {
|
|
62
|
+
it('should work the same as Remainder', () => {
|
|
63
|
+
expect(remainder(5, 3)).toBe(Remainder(5, 3))
|
|
64
|
+
expect(remainder(7, 3)).toBe(Remainder(7, 3))
|
|
65
|
+
expect(remainder(-5, 3)).toBe(Remainder(-5, 3))
|
|
66
|
+
expect(remainder(5.5, 2)).toBe(Remainder(5.5, 2))
|
|
67
|
+
expect(Number.isNaN(remainder(Number.NaN, 3))).toBe(true)
|
|
68
|
+
expect(Number.isNaN(remainder(5, 0))).toBe(true)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { IsInf, IsNaN, NaN } from "./bits.gs.js";
|
|
3
|
+
import { Mod } from "./mod.gs.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// Remainder returns the IEEE 754 floating-point remainder of x/y.
|
|
7
|
+
//
|
|
8
|
+
// Special cases are:
|
|
9
|
+
//
|
|
10
|
+
// Remainder(±Inf, y) = NaN
|
|
11
|
+
// Remainder(NaN, y) = NaN
|
|
12
|
+
// Remainder(x, 0) = NaN
|
|
13
|
+
// Remainder(x, ±Inf) = x
|
|
14
|
+
// Remainder(x, NaN) = NaN
|
|
15
|
+
export function Remainder(x: number, y: number): number {
|
|
16
|
+
return remainder(x, y)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function remainder(x: number, y: number): number {
|
|
20
|
+
// Handle special cases
|
|
21
|
+
if (Number.isNaN(x) || Number.isNaN(y) || !Number.isFinite(x) || y === 0) {
|
|
22
|
+
return Number.NaN
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!Number.isFinite(y)) {
|
|
26
|
+
return x
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// IEEE 754 remainder: x - n*y where n is the integer nearest to x/y
|
|
30
|
+
const n = Math.round(x / y)
|
|
31
|
+
return x - n * y
|
|
32
|
+
}
|
|
33
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Signbit } from './signbit.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Signbit', () => {
|
|
5
|
+
it('should return false for positive numbers', () => {
|
|
6
|
+
expect(Signbit(1)).toBe(false)
|
|
7
|
+
expect(Signbit(5.5)).toBe(false)
|
|
8
|
+
expect(Signbit(Number.MAX_VALUE)).toBe(false)
|
|
9
|
+
expect(Signbit(Number.MIN_VALUE)).toBe(false)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('should return true for negative numbers', () => {
|
|
13
|
+
expect(Signbit(-1)).toBe(true)
|
|
14
|
+
expect(Signbit(-5.5)).toBe(true)
|
|
15
|
+
expect(Signbit(-Number.MAX_VALUE)).toBe(true)
|
|
16
|
+
expect(Signbit(-Number.MIN_VALUE)).toBe(true)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should handle zero correctly', () => {
|
|
20
|
+
expect(Signbit(0)).toBe(false)
|
|
21
|
+
expect(Signbit(-0)).toBe(true)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('should handle infinity correctly', () => {
|
|
25
|
+
expect(Signbit(Number.POSITIVE_INFINITY)).toBe(false)
|
|
26
|
+
expect(Signbit(Number.NEGATIVE_INFINITY)).toBe(true)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should handle NaN correctly', () => {
|
|
30
|
+
expect(Signbit(Number.NaN)).toBe(false)
|
|
31
|
+
expect(Signbit(-Number.NaN)).toBe(false) // NaN doesn't have a sign
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Sin, sin, Cos, cos } from './sin.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Sin', () => {
|
|
5
|
+
it('should return correct sine values', () => {
|
|
6
|
+
expect(Sin(0)).toBe(0)
|
|
7
|
+
expect(Sin(-0)).toBe(-0)
|
|
8
|
+
expect(Sin(Math.PI / 2)).toBeCloseTo(1, 15)
|
|
9
|
+
expect(Sin(-Math.PI / 2)).toBeCloseTo(-1, 15)
|
|
10
|
+
expect(Sin(Math.PI)).toBeCloseTo(0, 15)
|
|
11
|
+
expect(Sin(-Math.PI)).toBeCloseTo(0, 15)
|
|
12
|
+
expect(Sin(Math.PI / 6)).toBeCloseTo(0.5, 15)
|
|
13
|
+
expect(Sin(Math.PI / 4)).toBeCloseTo(Math.sqrt(2) / 2, 15)
|
|
14
|
+
expect(Sin(Math.PI / 3)).toBeCloseTo(Math.sqrt(3) / 2, 15)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('should handle special values', () => {
|
|
18
|
+
expect(Number.isNaN(Sin(Number.POSITIVE_INFINITY))).toBe(true)
|
|
19
|
+
expect(Number.isNaN(Sin(Number.NEGATIVE_INFINITY))).toBe(true)
|
|
20
|
+
expect(Number.isNaN(Sin(Number.NaN))).toBe(true)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('should handle large values', () => {
|
|
24
|
+
expect(Sin(2 * Math.PI)).toBeCloseTo(0, 14)
|
|
25
|
+
expect(Sin(4 * Math.PI)).toBeCloseTo(0, 14)
|
|
26
|
+
expect(Sin(100 * Math.PI)).toBeCloseTo(0, 10)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should be periodic', () => {
|
|
30
|
+
const x = 1.5
|
|
31
|
+
expect(Sin(x)).toBeCloseTo(Sin(x + 2 * Math.PI), 14)
|
|
32
|
+
expect(Sin(x)).toBeCloseTo(Sin(x + 4 * Math.PI), 14)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('sin', () => {
|
|
37
|
+
it('should work the same as Sin', () => {
|
|
38
|
+
expect(sin(0)).toBe(Sin(0))
|
|
39
|
+
expect(sin(Math.PI / 2)).toBe(Sin(Math.PI / 2))
|
|
40
|
+
expect(sin(-Math.PI / 2)).toBe(Sin(-Math.PI / 2))
|
|
41
|
+
expect(sin(Math.PI)).toBe(Sin(Math.PI))
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('Cos', () => {
|
|
46
|
+
it('should return correct cosine values', () => {
|
|
47
|
+
expect(Cos(0)).toBe(1)
|
|
48
|
+
expect(Cos(Math.PI / 2)).toBeCloseTo(0, 15)
|
|
49
|
+
expect(Cos(-Math.PI / 2)).toBeCloseTo(0, 15)
|
|
50
|
+
expect(Cos(Math.PI)).toBeCloseTo(-1, 15)
|
|
51
|
+
expect(Cos(-Math.PI)).toBeCloseTo(-1, 15)
|
|
52
|
+
expect(Cos(Math.PI / 3)).toBeCloseTo(0.5, 15)
|
|
53
|
+
expect(Cos(Math.PI / 4)).toBeCloseTo(Math.sqrt(2) / 2, 15)
|
|
54
|
+
expect(Cos(Math.PI / 6)).toBeCloseTo(Math.sqrt(3) / 2, 15)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should handle special values', () => {
|
|
58
|
+
expect(Number.isNaN(Cos(Number.POSITIVE_INFINITY))).toBe(true)
|
|
59
|
+
expect(Number.isNaN(Cos(Number.NEGATIVE_INFINITY))).toBe(true)
|
|
60
|
+
expect(Number.isNaN(Cos(Number.NaN))).toBe(true)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should handle large values', () => {
|
|
64
|
+
expect(Cos(2 * Math.PI)).toBeCloseTo(1, 14)
|
|
65
|
+
expect(Cos(4 * Math.PI)).toBeCloseTo(1, 14)
|
|
66
|
+
expect(Cos(100 * Math.PI)).toBeCloseTo(1, 10)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('should be periodic', () => {
|
|
70
|
+
const x = 1.5
|
|
71
|
+
expect(Cos(x)).toBeCloseTo(Cos(x + 2 * Math.PI), 14)
|
|
72
|
+
expect(Cos(x)).toBeCloseTo(Cos(x + 4 * Math.PI), 14)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('cos', () => {
|
|
77
|
+
it('should work the same as Cos', () => {
|
|
78
|
+
expect(cos(0)).toBe(Cos(0))
|
|
79
|
+
expect(cos(Math.PI / 2)).toBe(Cos(Math.PI / 2))
|
|
80
|
+
expect(cos(-Math.PI / 2)).toBe(Cos(-Math.PI / 2))
|
|
81
|
+
expect(cos(Math.PI)).toBe(Cos(Math.PI))
|
|
82
|
+
})
|
|
83
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { Abs } from "./abs.gs.js";
|
|
3
|
+
import { IsInf, IsNaN, NaN } from "./bits.gs.js";
|
|
4
|
+
import { trigReduce } from "./trig_reduce.gs.js";
|
|
5
|
+
|
|
6
|
+
let _sin = $.arrayToSlice<number>([1.58962301576546568060e-10, -2.50507477628578072866e-8, 2.75573136213857245213e-6, -1.98412698295895385996e-4, 8.33333333332211858878e-3, -1.66666666666666307295e-1])
|
|
7
|
+
|
|
8
|
+
let _cos = $.arrayToSlice<number>([-1.13585365213876817300e-11, 2.08757008419747316778e-9, -2.75573141792967388112e-7, 2.48015872888517045348e-5, -1.38888888888730564116e-3, 4.16666666666665929218e-2])
|
|
9
|
+
|
|
10
|
+
// Cos returns the cosine of the radian argument x.
|
|
11
|
+
//
|
|
12
|
+
// Special cases are:
|
|
13
|
+
//
|
|
14
|
+
// Cos(±Inf) = NaN
|
|
15
|
+
// Cos(NaN) = NaN
|
|
16
|
+
export function Cos(x: number): number {
|
|
17
|
+
return Math.cos(x)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function cos(x: number): number {
|
|
21
|
+
return Math.cos(x)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Sin returns the sine of the radian argument x.
|
|
25
|
+
//
|
|
26
|
+
// Special cases are:
|
|
27
|
+
//
|
|
28
|
+
// Sin(±0) = ±0
|
|
29
|
+
// Sin(±Inf) = NaN
|
|
30
|
+
// Sin(NaN) = NaN
|
|
31
|
+
export function Sin(x: number): number {
|
|
32
|
+
return Math.sin(x)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function sin(x: number): number {
|
|
36
|
+
return Math.sin(x)
|
|
37
|
+
}
|
|
38
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Sincos } from './sincos.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Sincos', () => {
|
|
5
|
+
it('should return correct sin and cos values for zero', () => {
|
|
6
|
+
const [sin, cos] = Sincos(0)
|
|
7
|
+
expect(sin).toBe(0)
|
|
8
|
+
expect(cos).toBe(1)
|
|
9
|
+
|
|
10
|
+
const [sinNeg, cosNeg] = Sincos(-0)
|
|
11
|
+
expect(sinNeg).toBe(-0)
|
|
12
|
+
expect(cosNeg).toBe(1)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should return correct sin and cos values for common angles', () => {
|
|
16
|
+
const [sin1, cos1] = Sincos(Math.PI / 2)
|
|
17
|
+
expect(sin1).toBeCloseTo(1, 15)
|
|
18
|
+
expect(cos1).toBeCloseTo(0, 15)
|
|
19
|
+
|
|
20
|
+
const [sin2, cos2] = Sincos(-Math.PI / 2)
|
|
21
|
+
expect(sin2).toBeCloseTo(-1, 15)
|
|
22
|
+
expect(cos2).toBeCloseTo(0, 15)
|
|
23
|
+
|
|
24
|
+
const [sin3, cos3] = Sincos(Math.PI)
|
|
25
|
+
expect(sin3).toBeCloseTo(0, 15)
|
|
26
|
+
expect(cos3).toBeCloseTo(-1, 15)
|
|
27
|
+
|
|
28
|
+
const [sin4, cos4] = Sincos(-Math.PI)
|
|
29
|
+
expect(sin4).toBeCloseTo(0, 15)
|
|
30
|
+
expect(cos4).toBeCloseTo(-1, 15)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should return correct sin and cos values for special angles', () => {
|
|
34
|
+
const [sin1, cos1] = Sincos(Math.PI / 6)
|
|
35
|
+
expect(sin1).toBeCloseTo(0.5, 15)
|
|
36
|
+
expect(cos1).toBeCloseTo(Math.sqrt(3) / 2, 15)
|
|
37
|
+
|
|
38
|
+
const [sin2, cos2] = Sincos(Math.PI / 4)
|
|
39
|
+
expect(sin2).toBeCloseTo(Math.sqrt(2) / 2, 15)
|
|
40
|
+
expect(cos2).toBeCloseTo(Math.sqrt(2) / 2, 15)
|
|
41
|
+
|
|
42
|
+
const [sin3, cos3] = Sincos(Math.PI / 3)
|
|
43
|
+
expect(sin3).toBeCloseTo(Math.sqrt(3) / 2, 15)
|
|
44
|
+
expect(cos3).toBeCloseTo(0.5, 15)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('should handle special values', () => {
|
|
48
|
+
const [sin1, cos1] = Sincos(Number.POSITIVE_INFINITY)
|
|
49
|
+
expect(Number.isNaN(sin1)).toBe(true)
|
|
50
|
+
expect(Number.isNaN(cos1)).toBe(true)
|
|
51
|
+
|
|
52
|
+
const [sin2, cos2] = Sincos(Number.NEGATIVE_INFINITY)
|
|
53
|
+
expect(Number.isNaN(sin2)).toBe(true)
|
|
54
|
+
expect(Number.isNaN(cos2)).toBe(true)
|
|
55
|
+
|
|
56
|
+
const [sin3, cos3] = Sincos(Number.NaN)
|
|
57
|
+
expect(Number.isNaN(sin3)).toBe(true)
|
|
58
|
+
expect(Number.isNaN(cos3)).toBe(true)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should satisfy the Pythagorean identity', () => {
|
|
62
|
+
const testValues = [0, Math.PI / 6, Math.PI / 4, Math.PI / 3, Math.PI / 2, Math.PI, 1.5, 2.7, -1.2]
|
|
63
|
+
|
|
64
|
+
for (const x of testValues) {
|
|
65
|
+
const [sin, cos] = Sincos(x)
|
|
66
|
+
expect(sin * sin + cos * cos).toBeCloseTo(1, 14)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should be periodic with period 2π', () => {
|
|
71
|
+
const x = 1.5
|
|
72
|
+
const [sin1, cos1] = Sincos(x)
|
|
73
|
+
const [sin2, cos2] = Sincos(x + 2 * Math.PI)
|
|
74
|
+
const [sin3, cos3] = Sincos(x + 4 * Math.PI)
|
|
75
|
+
|
|
76
|
+
expect(sin1).toBeCloseTo(sin2, 14)
|
|
77
|
+
expect(cos1).toBeCloseTo(cos2, 14)
|
|
78
|
+
expect(sin1).toBeCloseTo(sin3, 14)
|
|
79
|
+
expect(cos1).toBeCloseTo(cos3, 14)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('should match individual Math.sin and Math.cos calls', () => {
|
|
83
|
+
const testValues = [0, Math.PI / 6, Math.PI / 4, Math.PI / 3, Math.PI / 2, Math.PI, 1.5, -1.2]
|
|
84
|
+
|
|
85
|
+
for (const x of testValues) {
|
|
86
|
+
const [sin, cos] = Sincos(x)
|
|
87
|
+
expect(sin).toBeCloseTo(Math.sin(x), 15)
|
|
88
|
+
expect(cos).toBeCloseTo(Math.cos(x), 15)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { IsInf, IsNaN, NaN } from "./bits.gs.js";
|
|
3
|
+
import { trigReduce } from "./trig_reduce.gs.js";
|
|
4
|
+
|
|
5
|
+
// Sincos returns Sin(x), Cos(x).
|
|
6
|
+
//
|
|
7
|
+
// Special cases are:
|
|
8
|
+
//
|
|
9
|
+
// Sincos(±0) = ±0, 1
|
|
10
|
+
// Sincos(±Inf) = NaN, NaN
|
|
11
|
+
// Sincos(NaN) = NaN, NaN
|
|
12
|
+
export function Sincos(x: number): [number, number] {
|
|
13
|
+
return [Math.sin(x), Math.cos(x)]
|
|
14
|
+
}
|
|
15
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Sinh, sinh, Cosh, cosh } from './sinh.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Sinh', () => {
|
|
5
|
+
it('should return correct hyperbolic sine values', () => {
|
|
6
|
+
expect(Sinh(0)).toBe(0)
|
|
7
|
+
expect(Sinh(-0)).toBe(-0)
|
|
8
|
+
expect(Sinh(1)).toBeCloseTo(1.1752011936438014, 15)
|
|
9
|
+
expect(Sinh(-1)).toBeCloseTo(-1.1752011936438014, 15)
|
|
10
|
+
expect(Sinh(2)).toBeCloseTo(3.626860407847019, 15)
|
|
11
|
+
expect(Sinh(-2)).toBeCloseTo(-3.626860407847019, 15)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should handle special values', () => {
|
|
15
|
+
expect(Sinh(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
|
|
16
|
+
expect(Sinh(Number.NEGATIVE_INFINITY)).toBe(Number.NEGATIVE_INFINITY)
|
|
17
|
+
expect(Number.isNaN(Sinh(Number.NaN))).toBe(true)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should handle edge cases', () => {
|
|
21
|
+
expect(Sinh(Number.MAX_VALUE)).toBe(Number.POSITIVE_INFINITY)
|
|
22
|
+
expect(Sinh(-Number.MAX_VALUE)).toBe(Number.NEGATIVE_INFINITY)
|
|
23
|
+
expect(Sinh(Number.MIN_VALUE)).toBeCloseTo(Number.MIN_VALUE, 15)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('sinh', () => {
|
|
28
|
+
it('should work the same as Sinh', () => {
|
|
29
|
+
expect(sinh(0)).toBe(Sinh(0))
|
|
30
|
+
expect(sinh(1)).toBe(Sinh(1))
|
|
31
|
+
expect(sinh(-1)).toBe(Sinh(-1))
|
|
32
|
+
expect(sinh(Number.POSITIVE_INFINITY)).toBe(Sinh(Number.POSITIVE_INFINITY))
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('Cosh', () => {
|
|
37
|
+
it('should return correct hyperbolic cosine values', () => {
|
|
38
|
+
expect(Cosh(0)).toBe(1)
|
|
39
|
+
expect(Cosh(-0)).toBe(1)
|
|
40
|
+
expect(Cosh(1)).toBeCloseTo(1.5430806348152437, 15)
|
|
41
|
+
expect(Cosh(-1)).toBeCloseTo(1.5430806348152437, 15)
|
|
42
|
+
expect(Cosh(2)).toBeCloseTo(3.7621956910836314, 15)
|
|
43
|
+
expect(Cosh(-2)).toBeCloseTo(3.7621956910836314, 15)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should handle special values', () => {
|
|
47
|
+
expect(Cosh(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
|
|
48
|
+
expect(Cosh(Number.NEGATIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
|
|
49
|
+
expect(Number.isNaN(Cosh(Number.NaN))).toBe(true)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should handle edge cases', () => {
|
|
53
|
+
expect(Cosh(Number.MAX_VALUE)).toBe(Number.POSITIVE_INFINITY)
|
|
54
|
+
expect(Cosh(-Number.MAX_VALUE)).toBe(Number.POSITIVE_INFINITY)
|
|
55
|
+
expect(Cosh(Number.MIN_VALUE)).toBeCloseTo(1, 15)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('cosh', () => {
|
|
60
|
+
it('should work the same as Cosh', () => {
|
|
61
|
+
expect(cosh(0)).toBe(Cosh(0))
|
|
62
|
+
expect(cosh(1)).toBe(Cosh(1))
|
|
63
|
+
expect(cosh(-1)).toBe(Cosh(-1))
|
|
64
|
+
expect(cosh(Number.POSITIVE_INFINITY)).toBe(Cosh(Number.POSITIVE_INFINITY))
|
|
65
|
+
})
|
|
66
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { Abs } from "./abs.gs.js";
|
|
3
|
+
import { Exp } from "./exp.gs.js";
|
|
4
|
+
|
|
5
|
+
// Sinh returns the hyperbolic sine of x.
|
|
6
|
+
//
|
|
7
|
+
// Special cases are:
|
|
8
|
+
//
|
|
9
|
+
// Sinh(±0) = ±0
|
|
10
|
+
// Sinh(±Inf) = ±Inf
|
|
11
|
+
// Sinh(NaN) = NaN
|
|
12
|
+
export function Sinh(x: number): number {
|
|
13
|
+
return Math.sinh(x)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function sinh(x: number): number {
|
|
17
|
+
return Math.sinh(x)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Cosh returns the hyperbolic cosine of x.
|
|
21
|
+
//
|
|
22
|
+
// Special cases are:
|
|
23
|
+
//
|
|
24
|
+
// Cosh(±0) = 1
|
|
25
|
+
// Cosh(±Inf) = +Inf
|
|
26
|
+
// Cosh(NaN) = NaN
|
|
27
|
+
export function Cosh(x: number): number {
|
|
28
|
+
return Math.cosh(x)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function cosh(x: number): number {
|
|
32
|
+
return Math.cosh(x)
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Sqrt, sqrt } from './sqrt.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Sqrt', () => {
|
|
5
|
+
it('should return correct square root values', () => {
|
|
6
|
+
expect(Sqrt(0)).toBe(0)
|
|
7
|
+
expect(Sqrt(-0)).toBe(-0)
|
|
8
|
+
expect(Sqrt(1)).toBe(1)
|
|
9
|
+
expect(Sqrt(4)).toBe(2)
|
|
10
|
+
expect(Sqrt(9)).toBe(3)
|
|
11
|
+
expect(Sqrt(16)).toBe(4)
|
|
12
|
+
expect(Sqrt(25)).toBe(5)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should handle fractional values', () => {
|
|
16
|
+
expect(Sqrt(0.25)).toBe(0.5)
|
|
17
|
+
expect(Sqrt(0.01)).toBe(0.1)
|
|
18
|
+
expect(Sqrt(2)).toBeCloseTo(1.4142135623730951, 14)
|
|
19
|
+
expect(Sqrt(3)).toBeCloseTo(1.7320508075688772, 15)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should handle special values', () => {
|
|
23
|
+
expect(Sqrt(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
|
|
24
|
+
expect(Number.isNaN(Sqrt(-1))).toBe(true)
|
|
25
|
+
expect(Number.isNaN(Sqrt(-10))).toBe(true)
|
|
26
|
+
expect(Number.isNaN(Sqrt(Number.NaN))).toBe(true)
|
|
27
|
+
expect(Number.isNaN(Sqrt(Number.NEGATIVE_INFINITY))).toBe(true)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should handle edge cases', () => {
|
|
31
|
+
expect(Sqrt(Number.MAX_VALUE)).toBeCloseTo(1.3407807929942596e154, 140)
|
|
32
|
+
expect(Sqrt(Number.MIN_VALUE)).toBeCloseTo(1.4916681462400413e-154, 150)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should handle very small positive values', () => {
|
|
36
|
+
expect(Sqrt(1e-100)).toBeCloseTo(1e-50, 14)
|
|
37
|
+
expect(Sqrt(1e-200)).toBeCloseTo(1e-100, 14)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('sqrt', () => {
|
|
42
|
+
it('should work the same as Sqrt', () => {
|
|
43
|
+
expect(sqrt(0)).toBe(Sqrt(0))
|
|
44
|
+
expect(sqrt(1)).toBe(Sqrt(1))
|
|
45
|
+
expect(sqrt(4)).toBe(Sqrt(4))
|
|
46
|
+
expect(sqrt(9)).toBe(Sqrt(9))
|
|
47
|
+
expect(Number.isNaN(sqrt(-1))).toBe(Number.isNaN(Sqrt(-1)))
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as $ from "@goscript/builtin/builtin.js";
|
|
2
|
+
import { IsInf, IsNaN, NaN } from "./bits.gs.js";
|
|
3
|
+
import { Float64bits, Float64frombits } from "./unsafe.gs.js";
|
|
4
|
+
|
|
5
|
+
// Sqrt returns the square root of x.
|
|
6
|
+
//
|
|
7
|
+
// Special cases are:
|
|
8
|
+
//
|
|
9
|
+
// Sqrt(+Inf) = +Inf
|
|
10
|
+
// Sqrt(±0) = ±0
|
|
11
|
+
// Sqrt(x < 0) = NaN
|
|
12
|
+
// Sqrt(NaN) = NaN
|
|
13
|
+
export function Sqrt(x: number): number {
|
|
14
|
+
return Math.sqrt(x)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function sqrt(x: number): number {
|
|
18
|
+
return Math.sqrt(x)
|
|
19
|
+
}
|
|
20
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { Tan, tan } from './tan.gs.js'
|
|
3
|
+
|
|
4
|
+
describe('Tan', () => {
|
|
5
|
+
it('should return correct tangent values', () => {
|
|
6
|
+
expect(Tan(0)).toBe(0)
|
|
7
|
+
expect(Tan(-0)).toBe(-0)
|
|
8
|
+
expect(Tan(Math.PI / 4)).toBeCloseTo(1, 14)
|
|
9
|
+
expect(Tan(-Math.PI / 4)).toBeCloseTo(-1, 15)
|
|
10
|
+
expect(Tan(Math.PI)).toBeCloseTo(0, 14)
|
|
11
|
+
expect(Tan(-Math.PI)).toBeCloseTo(0, 14)
|
|
12
|
+
expect(Tan(Math.PI / 6)).toBeCloseTo(0.5773502691896257, 14)
|
|
13
|
+
expect(Tan(Math.PI / 3)).toBeCloseTo(1.7320508075688772, 14)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('should handle special values', () => {
|
|
17
|
+
expect(Number.isNaN(Tan(Number.POSITIVE_INFINITY))).toBe(true)
|
|
18
|
+
expect(Number.isNaN(Tan(Number.NEGATIVE_INFINITY))).toBe(true)
|
|
19
|
+
expect(Number.isNaN(Tan(Number.NaN))).toBe(true)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should approach infinity near asymptotes', () => {
|
|
23
|
+
const nearPiOver2 = Math.PI / 2 - 1e-10
|
|
24
|
+
expect(Math.abs(Tan(nearPiOver2))).toBeGreaterThan(1e9)
|
|
25
|
+
|
|
26
|
+
const near3PiOver2 = 3 * Math.PI / 2 - 1e-10
|
|
27
|
+
expect(Math.abs(Tan(near3PiOver2))).toBeGreaterThan(1e9)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should be periodic', () => {
|
|
31
|
+
const x = 1.5
|
|
32
|
+
expect(Tan(x)).toBeCloseTo(Tan(x + Math.PI), 13)
|
|
33
|
+
expect(Tan(x)).toBeCloseTo(Tan(x + 2 * Math.PI), 13)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('should handle edge cases', () => {
|
|
37
|
+
expect(Tan(Number.MIN_VALUE)).toBeCloseTo(Number.MIN_VALUE, 14)
|
|
38
|
+
expect(Tan(-Number.MIN_VALUE)).toBeCloseTo(-Number.MIN_VALUE, 14)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('tan', () => {
|
|
43
|
+
it('should work the same as Tan', () => {
|
|
44
|
+
expect(tan(0)).toBe(Tan(0))
|
|
45
|
+
expect(tan(Math.PI / 4)).toBe(Tan(Math.PI / 4))
|
|
46
|
+
expect(tan(-Math.PI / 4)).toBe(Tan(-Math.PI / 4))
|
|
47
|
+
expect(tan(Math.PI)).toBe(Tan(Math.PI))
|
|
48
|
+
expect(Number.isNaN(tan(Number.NaN))).toBe(Number.isNaN(Tan(Number.NaN)))
|
|
49
|
+
})
|
|
50
|
+
})
|