-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecant.java
More file actions
35 lines (25 loc) · 900 Bytes
/
Secant.java
File metadata and controls
35 lines (25 loc) · 900 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
package ru.itmo.qa.lab2.trig;
import ru.itmo.qa.lab2.function.AbstractFunction;
import java.math.BigDecimal;
import static java.lang.String.format;
import static java.math.RoundingMode.HALF_EVEN;
public class Secant extends AbstractFunction {
private final Cosine cosine;
public Secant() {
super();
this.cosine = new Cosine();
}
public Secant(final Cosine cosine) {
super();
this.cosine = cosine;
}
@Override
public BigDecimal calculate(BigDecimal x, BigDecimal precision) throws ArithmeticException {
isValid(x, precision);
BigDecimal cos = cosine.calculate(x, precision.setScale(precision.scale() + 12, HALF_EVEN));
if (cos.abs().compareTo(precision) < 0) {
throw new ArithmeticException(format("У секанса нет значения при x = %s", x));
}
return BigDecimal.ONE.divide(cos, precision.scale(), HALF_EVEN);
}
}