-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
math_asin.go
61 lines (53 loc) · 1.78 KB
/
math_asin.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
57
58
59
60
61
// 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_asin_Name = "math.asin"
var Math_asin_ArgumentTypes = []value.Type{value.FloatType}
func Math_asin_Validate(args []value.Value) error {
if len(args) != 1 {
return errors.ArgumentNotEnough(Math_asin_Name, 1, args)
}
for i := range args {
if args[i].Type() != Math_asin_ArgumentTypes[i] {
return errors.TypeMismatch(Math_asin_Name, i+1, Math_asin_ArgumentTypes[i], args[i].Type())
}
}
return nil
}
// Fastly built-in function implementation of math.asin
// Arguments may be:
// - FLOAT
// Reference: https://developer.fastly.com/reference/vcl/functions/math-trig/math-asin/
func Math_asin(ctx *context.Context, args ...value.Value) (value.Value, error) {
// Argument validations
if err := Math_asin_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:
ctx.FastlyError = &value.String{Value: "EDOM"}
return &value.Float{IsNAN: true}, nil
case x.IsPositiveInf:
ctx.FastlyError = &value.String{Value: "EDOM"}
return &value.Float{IsNAN: true}, 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
case x.Value < -1.0 || x.Value > 1.0:
ctx.FastlyError = &value.String{Value: "EDOM"}
return &value.Float{IsNAN: true}, nil
default:
return &value.Float{Value: math.Asin(x.Value)}, nil
}
}