/
math_atan.go
56 lines (48 loc) · 1.57 KB
/
math_atan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Code generated by __generator__/interpreter.go at once
package builtin
import (
"math"
"github.com/ysugimoto/falco/interpreter/context"
"github.com/ysugimoto/falco/interpreter/function/errors"
"github.com/ysugimoto/falco/interpreter/function/shared"
"github.com/ysugimoto/falco/interpreter/value"
)
const Math_atan_Name = "math.atan"
var Math_atan_ArgumentTypes = []value.Type{value.FloatType}
func Math_atan_Validate(args []value.Value) error {
if len(args) != 1 {
return errors.ArgumentNotEnough(Math_atan_Name, 1, args)
}
for i := range args {
if args[i].Type() != Math_atan_ArgumentTypes[i] {
return errors.TypeMismatch(Math_atan_Name, i+1, Math_atan_ArgumentTypes[i], args[i].Type())
}
}
return nil
}
// Fastly built-in function implementation of math.atan
// Arguments may be:
// - FLOAT
// Reference: https://developer.fastly.com/reference/vcl/functions/math-trig/math-atan/
func Math_atan(ctx *context.Context, args ...value.Value) (value.Value, error) {
// Argument validations
if err := Math_atan_Validate(args); err != nil {
return value.Null, err
}
x := value.Unwrap[*value.Float](args[0])
switch {
case x.IsNAN:
return &value.Float{IsNAN: true}, nil
case x.IsNegativeInf:
return &value.Float{Value: -math.Pi / 2}, nil
case x.IsPositiveInf:
return &value.Float{Value: math.Pi / 2}, nil
case x.Value == 0:
return &value.Float{Value: x.Value}, nil
case shared.IsSubnormalFloat64(x.Value):
ctx.FastlyError = &value.String{Value: "ERANGE"}
return &value.Float{Value: x.Value}, nil
default:
return &value.Float{Value: math.Atan(x.Value)}, nil
}
}