-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.java
More file actions
86 lines (74 loc) · 2.05 KB
/
Log.java
File metadata and controls
86 lines (74 loc) · 2.05 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @author Rakith (Jay) Jayewardene
* Creates a class called Log which extends Function
*/
public class Log extends Function {
/* Stores the operand */
private Function operand;
/* Stores the input value */
private double inputValue;
/**
* A constructor that takes operand as input
* @param operand
*/
public Log(Function operand) {
this.operand = operand;
}
/**
* A method that gets the operand
* @return operand
*/
public Function getOperand() {
return operand;
}
/**
* A method that sets the operand
* @param operand
*/
public void setOperand(Function operand) {
this.operand = operand;
}
/**
* A method that takes no input and produces the log of the inputValue
* @return the log value of the input as a double
*/
@Override
public double value(double inputValue) {
return Math.log(getOperand().value(this.inputValue));
}
/**
* A method that takes no input and produces the log of the value
* @return the log value of the input as a double
*/
@Override
public double value() {
return Math.log(getOperand().value(inputValue));
}
/**
* A method that takes no input and takes the derivative of the log function
* @return the derivative of the log function in type Function
*/
@Override
public Function derivative() {
return new BinaryOp(new Number(1), getOperand(), BinaryOp.Op.DIV);
}
/**
* A method that takes no input and converts the log function to a String
* @return the String representation of the log function
*/
@Override
public String toString() {
return "Log[" + getOperand().toString() + "]";
}
/**
* A method that compares an Object function to the log function
* @return true if the Object and log function are equal or false if they are not
*/
@Override
public boolean equals(Object function) {
if(function instanceof Log) {
return true;
}
return false;
}
}