Debian Codegraph @

common/types/traits/math.go

raw symbols SCIP
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package traits
16
17 import "github.com/google/cel-go/common/types/ref"
18
19 // Adder interface to support '+' operator overloads.
20 type Adder interface {
21 // Add returns a combination of the current value and other value.
22 //
23 // If the other value is an unsupported type, an error is returned.
24 Add(other ref.Val) ref.Val
25 }
26
27 // Divider interface to support '/' operator overloads.
28 type Divider interface {
29 // Divide returns the result of dividing the current value by the input
30 // denominator.
31 //
32 // A denominator value of zero results in an error.
33 Divide(denominator ref.Val) ref.Val
34 }
35
36 // Modder interface to support '%' operator overloads.
37 type Modder interface {
38 // Modulo returns the result of taking the modulus of the current value
39 // by the denominator.
40 //
41 // A denominator value of zero results in an error.
42 Modulo(denominator ref.Val) ref.Val
43 }
44
45 // Multiplier interface to support '*' operator overloads.
46 type Multiplier interface {
47 // Multiply returns the result of multiplying the current and input value.
48 Multiply(other ref.Val) ref.Val
49 }
50
51 // Negater interface to support unary '-' and '!' operator overloads.
52 type Negater interface {
53 // Negate returns the complement of the current value.
54 Negate() ref.Val
55 }
56
57 // Subtractor interface to support binary '-' operator overloads.
58 type Subtractor interface {
59 // Subtract returns the result of subtracting the input from the current
60 // value.
61 Subtract(subtrahend ref.Val) ref.Val
62 }