-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCondExprIsPrime.java
More file actions
35 lines (32 loc) · 1.18 KB
/
CondExprIsPrime.java
File metadata and controls
35 lines (32 loc) · 1.18 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
package io.github.syst3ms.skriptparser.expressions;
import io.github.syst3ms.skriptparser.Parser;
import io.github.syst3ms.skriptparser.lang.properties.ConditionalType;
import io.github.syst3ms.skriptparser.lang.properties.PropertyConditional;
import io.github.syst3ms.skriptparser.util.math.BigDecimalMath;
import io.github.syst3ms.skriptparser.util.math.NumberMath;
/**
* Check if a given number is a prime number.
* This means that for a number {@code n},
* there does not exist a number {@code a} such that
* {@code a < n} and {@code n % a = 0}, except for {@code a = 1}.
*
* @name Is Prime
* @type CONDITION
* @pattern %numbers% (is|are)[ not|n't] [a] prime [number[s]]
* @since ALPHA
* @author Mwexim
*/
public class CondExprIsPrime extends PropertyConditional<Number> {
static {
Parser.getMainRegistration().newPropertyConditional(CondExprIsPrime.class, "numbers", ConditionalType.BE, "[a] prime [number[s]]")
.setPropertyName("prime")
.register();
}
@Override
public boolean check(Number owner) {
var bd = BigDecimalMath.getBigDecimal(owner);
return bd.signum() != -1
&& BigDecimalMath.isIntValue(bd)
&& NumberMath.isPrime(BigDecimalMath.getBigInteger(bd));
}
}