-
Notifications
You must be signed in to change notification settings - Fork 1
/
binary.ts
32 lines (31 loc) · 998 Bytes
/
binary.ts
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
/**
* Represents any kind of operator that has a left hand operand and a right hand operand.
*/
export enum BinaryOperator {
/** The operator for adding two values. */
ADD = "add",
/** The operator for subtracting one value from another. */
SUB = "sub",
/** The operator for multiplying two values. */
MUL = "mul",
/** The operator for dividing one value by another. */
DIV = "div",
/** The operator for raising a base to an exponent. */
POW = "pow",
/** The operator for evaluating dot (scalar) product of two vectors. */
DOT = "dot",
/** The operator for evaluating cross (vector) product of two vectors. */
CROSS = "cross",
/** The operator to scale a vector. */
SCALE = "scale"
}
/**
* Checks whether the passed string has been defined as a BinaryOperator.
*/
export function isBinaryOperator(s: string): s is BinaryOperator {
type iter = keyof typeof BinaryOperator;
for(const elt in BinaryOperator)
if(BinaryOperator[<iter>elt] === s)
return true;
return false;
}