package coremath

import "github.com/purpleidea/mgmt/lang/core/math"

Index

Constants

const (
	// ModuleName is the prefix given to all the functions in this module.
	ModuleName = "math"
)

Functions

func FortyTwo

func FortyTwo(sig *types.Type, input []types.Value) (types.Value, error)

FortyTwo returns 42 as either an int or a float. This is not especially useful, but was built for a fun test case of a simple poly function with two different return types, but no input args.

func Minus1

func Minus1(ctx context.Context, input []types.Value) (types.Value, error)

Minus1 takes an int and subtracts one from it.

func Mod

func Mod(ctx context.Context, input []types.Value) (types.Value, error)

Mod returns mod(x, y), the remainder of x/y. The two values must be either both of KindInt or both of KindFloat, and it will return the same kind. If you pass in a divisor of zero, this will error, eg: mod(x, 0) = NaN. TODO: consider returning zero instead of erroring?

func Pow

func Pow(ctx context.Context, input []types.Value) (types.Value, error)

Pow returns x ^ y, the base-x exponential of y.

func Sqrt

func Sqrt(ctx context.Context, input []types.Value) (types.Value, error)

Sqrt returns sqrt(x), the square root of x.

Source Files

fortytwo.go math.go minus1.go mod.go pow.go sqrt.go

Version
v0.0.0-20250322185616-c50a578426f1 (latest)
Published
Mar 22, 2025
Platform
linux/amd64
Imports
7 packages
Last checked
4 days ago

Tools for package owners.