-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
math_exp2.go
49 lines (41 loc) · 1.32 KB
/
math_exp2.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
// 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/value"
)
const Math_exp2_Name = "math.exp2"
var Math_exp2_ArgumentTypes = []value.Type{value.FloatType}
func Math_exp2_Validate(args []value.Value) error {
if len(args) != 1 {
return errors.ArgumentNotEnough(Math_exp2_Name, 1, args)
}
for i := range args {
if args[i].Type() != Math_exp2_ArgumentTypes[i] {
return errors.TypeMismatch(Math_exp2_Name, i+1, Math_exp2_ArgumentTypes[i], args[i].Type())
}
}
return nil
}
// Fastly built-in function implementation of math.exp2
// Arguments may be:
// - FLOAT
// Reference: https://developer.fastly.com/reference/vcl/functions/math-logexp/math-exp2/
func Math_exp2(ctx *context.Context, args ...value.Value) (value.Value, error) {
// Argument validations
if err := Math_exp2_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{IsNegativeInf: true}, nil
case x.IsPositiveInf:
return &value.Float{IsPositiveInf: true}, nil
}
return &value.Float{Value: math.Exp2(x.Value)}, nil
}