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

     1  package math
     2  
     3  import (
     4  	"context"
     5  	"math"
     6  
     7  	"github.com/MontFerret/ferret/pkg/runtime/core"
     8  	"github.com/MontFerret/ferret/pkg/runtime/values"
     9  	"github.com/MontFerret/ferret/pkg/runtime/values/types"
    10  )
    11  
    12  // ATAN2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.
    13  // @param {Int | Float} number1 - Input number.
    14  // @param {Int | Float} number2 - Input number.
    15  // @return {Float} - The arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.
    16  func Atan2(_ context.Context, args ...core.Value) (core.Value, error) {
    17  	err := core.ValidateArgs(args, 2, 2)
    18  
    19  	if err != nil {
    20  		return values.None, err
    21  	}
    22  
    23  	err = core.ValidateType(args[0], types.Int, types.Float)
    24  
    25  	if err != nil {
    26  		return values.None, err
    27  	}
    28  
    29  	err = core.ValidateType(args[1], types.Int, types.Float)
    30  
    31  	if err != nil {
    32  		return values.None, err
    33  	}
    34  
    35  	arg1 := toFloat(args[0])
    36  	arg2 := toFloat(args[1])
    37  
    38  	return values.NewFloat(math.Atan2(arg1, arg2)), nil
    39  }