-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyword.java
More file actions
70 lines (65 loc) · 1.37 KB
/
Copy pathKeyword.java
File metadata and controls
70 lines (65 loc) · 1.37 KB
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
62
63
64
65
66
67
68
69
70
/**
* @name Sterling Blevins
*
* @file Keyword.java
* @description The keyword enumeration for the keywords and built in math functions
*
* @date 5/3/17
*/
public enum Keyword{
QUOTE("quote"),
IF("if"),
DEFINE("define"),
SET("set!"),
DEFUN("defun"), // "lambda"
EXP("exp"),
COS("cos"),
SIN("sin"),
TAN("tan"),
SQRT("sqrt");
private String word;
private Keyword(String word) {
this.word = word;
}
public String toString() {
return this.word;
}
/**
* Evaluation for two component math functions
* @param x
* @param y
* @return
*/
public double eval(double x, double y) {
double temp = 0;
switch (this) {
case EXP:
temp = Math.pow(x, y);
break;
}
return temp;
}
/**
* Evaluation for one component math functions
* @param a
* @return
*/
public double eval(double a) {
double temp = 0;
switch (this) {
case COS:
temp = Math.cos(a);
break;
case SIN:
temp = Math.sin(a);
break;
case TAN:
temp = Math.tan(a);
break;
case SQRT:
temp = Math.sqrt(a);
break;
}
return temp;
}
}