-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCosecant.java
More file actions
35 lines (25 loc) · 886 Bytes
/
Cosecant.java
File metadata and controls
35 lines (25 loc) · 886 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 Cosecant extends AbstractFunction {
private final Sine sine;
public Cosecant() {
super();
this.sine = new Sine();
}
public Cosecant(Sine sine) {
super();
this.sine = sine;
}
@Override
public BigDecimal calculate(BigDecimal x, BigDecimal precision) throws ArithmeticException {
isValid(x, precision);
BigDecimal sin = sine.calculate(x, precision.setScale(precision.scale() + 12, HALF_EVEN));
if (sin.abs().compareTo(precision) < 0) {
throw new ArithmeticException(format("У косеканса нет значения при x = %s", x));
}
return BigDecimal.ONE.divide(sin, precision.scale(), HALF_EVEN);
}
}