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