From ecc3d9181eaa0e5933ad60d5369fdac9ec0c2a48 Mon Sep 17 00:00:00 2001 From: Wannes <90846062+vereecw@users.noreply.github.com> Date: Mon, 30 Jan 2023 09:12:28 +0100 Subject: [PATCH] Added more math consts (#404) --- docs/stdlib-math.md | 22 ++++++++++++++++++++++ stdlib/math.go | 36 +++++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/docs/stdlib-math.md b/docs/stdlib-math.md index d68eb77..ce8d2cd 100644 --- a/docs/stdlib-math.md +++ b/docs/stdlib-math.md @@ -18,6 +18,28 @@ math := import("math") - `ln10` - `ln10E` +Mathematical constants. + +- `maxFloat32` +- `smallestNonzeroFloat32` +- `maxFloat64` +- `smallestNonzeroFloat64` + +Floating-point limit values. Max is the largest finite value representable by the type. SmallestNonzero is the smallest positive, non-zero value representable by the type. + +- `maxInt` +- `minInt` +- `maxInt8` +- `minInt8` +- `maxInt16` +- `minInt16` +- `maxInt32` +- `minInt32` +- `maxInt64` +- `minInt64` + +Integer limit values. + ## Functions - `abs(x float) => float`: returns the absolute value of x. diff --git a/stdlib/math.go b/stdlib/math.go index 633ea09..1bd9ba6 100644 --- a/stdlib/math.go +++ b/stdlib/math.go @@ -7,17 +7,31 @@ import ( ) var mathModule = map[string]tengo.Object{ - "e": &tengo.Float{Value: math.E}, - "pi": &tengo.Float{Value: math.Pi}, - "phi": &tengo.Float{Value: math.Phi}, - "sqrt2": &tengo.Float{Value: math.Sqrt2}, - "sqrtE": &tengo.Float{Value: math.SqrtE}, - "sqrtPi": &tengo.Float{Value: math.SqrtPi}, - "sqrtPhi": &tengo.Float{Value: math.SqrtPhi}, - "ln2": &tengo.Float{Value: math.Ln2}, - "log2E": &tengo.Float{Value: math.Log2E}, - "ln10": &tengo.Float{Value: math.Ln10}, - "log10E": &tengo.Float{Value: math.Log10E}, + "e": &tengo.Float{Value: math.E}, + "pi": &tengo.Float{Value: math.Pi}, + "phi": &tengo.Float{Value: math.Phi}, + "sqrt2": &tengo.Float{Value: math.Sqrt2}, + "sqrtE": &tengo.Float{Value: math.SqrtE}, + "sqrtPi": &tengo.Float{Value: math.SqrtPi}, + "sqrtPhi": &tengo.Float{Value: math.SqrtPhi}, + "ln2": &tengo.Float{Value: math.Ln2}, + "log2E": &tengo.Float{Value: math.Log2E}, + "ln10": &tengo.Float{Value: math.Ln10}, + "log10E": &tengo.Float{Value: math.Log10E}, + "maxFloat32": &tengo.Float{Value: math.MaxFloat32}, + "smallestNonzeroFloat32": &tengo.Float{Value: math.SmallestNonzeroFloat32}, + "maxFloat64": &tengo.Float{Value: math.MaxFloat64}, + "smallestNonzeroFloat64": &tengo.Float{Value: math.SmallestNonzeroFloat64}, + "maxInt": &tengo.Int{Value: math.MaxInt}, + "minInt": &tengo.Int{Value: math.MinInt}, + "maxInt8": &tengo.Int{Value: math.MaxInt8}, + "minInt8": &tengo.Int{Value: math.MinInt8}, + "maxInt16": &tengo.Int{Value: math.MaxInt16}, + "minInt16": &tengo.Int{Value: math.MinInt16}, + "maxInt32": &tengo.Int{Value: math.MaxInt32}, + "minInt32": &tengo.Int{Value: math.MinInt32}, + "maxInt64": &tengo.Int{Value: math.MaxInt64}, + "minInt64": &tengo.Int{Value: math.MinInt64}, "abs": &tengo.UserFunction{ Name: "abs", Value: FuncAFRF(math.Abs),