-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCosine.java
More file actions
36 lines (25 loc) · 838 Bytes
/
Cosine.java
File metadata and controls
36 lines (25 loc) · 838 Bytes
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
package ru.itmo.qa.lab2.trig;
import ch.obermuhlner.math.big.BigDecimalMath;
import ru.itmo.qa.lab2.function.AbstractFunction;
import java.math.BigDecimal;
import java.math.MathContext;
import static java.math.RoundingMode.HALF_EVEN;
public class Cosine extends AbstractFunction {
private final Sine sine;
public Cosine() {
super();
this.sine = new Sine();
}
public Cosine(Sine sine) {
super();
this.sine = sine;
}
@Override
public BigDecimal calculate(BigDecimal x, BigDecimal precision) throws ArithmeticException {
isValid(x, precision);
MathContext mc = new MathContext(precision.scale() + 2, HALF_EVEN);
BigDecimal piHalf = BigDecimalMath.pi(mc)
.divide(BigDecimal.valueOf(2), mc.getPrecision(), HALF_EVEN);
return sine.calculate(piHalf.subtract(x), precision);
}
}