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

     1  package math
     2  
     3  import (
     4  	"context"
     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  // RADIANS returns the angle converted from degrees to radians.
    12  // @param {Int | Float} number - The input number.
    13  // @return {Float} - The angle in radians.
    14  func Radians(_ context.Context, args ...core.Value) (core.Value, error) {
    15  	err := core.ValidateArgs(args, 1, 1)
    16  
    17  	if err != nil {
    18  		return values.None, err
    19  	}
    20  
    21  	err = core.ValidateType(args[0], types.Int, types.Float)
    22  
    23  	if err != nil {
    24  		return values.None, err
    25  	}
    26  
    27  	r := toFloat(args[0])
    28  
    29  	return values.NewFloat(r * DegToRad), nil
    30  }