github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/math/lib.go (about)

     1  package math
     2  
     3  import (
     4  	"math"
     5  
     6  	"github.com/MontFerret/ferret/pkg/runtime/core"
     7  	"github.com/MontFerret/ferret/pkg/runtime/values"
     8  	"github.com/MontFerret/ferret/pkg/runtime/values/types"
     9  )
    10  
    11  const (
    12  	RadToDeg  = 180 / math.Pi
    13  	DegToRad  = math.Pi / 180
    14  	RadToGrad = 200 / math.Pi
    15  	GradToDeg = math.Pi / 200
    16  )
    17  
    18  func RegisterLib(ns core.Namespace) error {
    19  	return ns.RegisterFunctions(
    20  		core.NewFunctionsFromMap(map[string]core.Function{
    21  			"ABS":                 Abs,
    22  			"ACOS":                Acos,
    23  			"ASIN":                Asin,
    24  			"ATAN":                Atan,
    25  			"ATAN2":               Atan2,
    26  			"AVERAGE":             Average,
    27  			"CEIL":                Ceil,
    28  			"COS":                 Cos,
    29  			"DEGREES":             Degrees,
    30  			"EXP":                 Exp,
    31  			"EXP2":                Exp2,
    32  			"FLOOR":               Floor,
    33  			"LOG":                 Log,
    34  			"LOG2":                Log2,
    35  			"LOG10":               Log10,
    36  			"MAX":                 Max,
    37  			"MEDIAN":              Median,
    38  			"MIN":                 Min,
    39  			"PERCENTILE":          Percentile,
    40  			"PI":                  Pi,
    41  			"POW":                 Pow,
    42  			"RADIANS":             Radians,
    43  			"RAND":                Rand,
    44  			"RANGE":               Range,
    45  			"ROUND":               Round,
    46  			"SIN":                 Sin,
    47  			"SQRT":                Sqrt,
    48  			"STDDEV_POPULATION":   StandardDeviationPopulation,
    49  			"STDDEV_SAMPLE":       StandardDeviationSample,
    50  			"SUM":                 Sum,
    51  			"TAN":                 Tan,
    52  			"VARIANCE_POPULATION": PopulationVariance,
    53  			"VARIANCE_SAMPLE":     SampleVariance,
    54  		}))
    55  }
    56  
    57  func toFloat(arg core.Value) float64 {
    58  	if arg.Type() == types.Int {
    59  		return float64(arg.(values.Int))
    60  	}
    61  
    62  	return float64(arg.(values.Float))
    63  }