Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathCeil.java
More file actions
Latest commit
34 lines (29 loc) · 931 Bytes
/
Copy pathCeil.java
File metadata and controls
34 lines (29 loc) · 931 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
packagecom.thealgorithms.maths;
/**
* Utility class to compute the ceiling of a given number.
*/
publicfinalclassCeil {
privateCeil() {
}
/**
* Returns the smallest double value that is greater than or equal to the input.
* Equivalent to mathematical ⌈x⌉ (ceiling function).
*
* @param number the number to ceil
* @return the smallest double greater than or equal to {@code number}
*/
publicstaticdoubleceil(doublenumber) {
if (Double.isNaN(number) || Double.isInfinite(number) || number == 0.0 || number < Integer.MIN_VALUE || number > Integer.MAX_VALUE) {
returnnumber;
}
if (number < 0.0 && number > -1.0) {
return -0.0;
}
longintPart = (long) number;
if (number > 0 && number != intPart) {
returnintPart + 1.0;
} else {
returnintPart;
}
}
}