MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / ceil

Method ceil

src/main/java/com/thealgorithms/maths/Ceil.java:18–33  ·  view source on GitHub ↗

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 number

(double number)

Source from the content-addressed store, hash-verified

16 * @return the smallest double greater than or equal to {@code number}
17 */
18 public static double ceil(double number) {
19 if (Double.isNaN(number) || Double.isInfinite(number) || number == 0.0 || number < Integer.MIN_VALUE || number > Integer.MAX_VALUE) {
20 return number;
21 }
22
23 if (number < 0.0 && number > -1.0) {
24 return -0.0;
25 }
26
27 long intPart = (long) number;
28 if (number > 0 && number != intPart) {
29 return intPart + 1.0;
30 } else {
31 return intPart;
32 }
33 }
34}

Callers 10

testCeilMethod · 0.95
testEdgeCasesMethod · 0.95
simpleMathMethod · 0.45
edgeCaseProviderMethod · 0.45
getEgyptianFractionMethod · 0.45
sortMethod · 0.45
wiggleSortMethod · 0.45
SegmentTreeMethod · 0.45
columnarTranspositionMethod · 0.45

Calls

no outgoing calls

Tested by 4

testCeilMethod · 0.76
testEdgeCasesMethod · 0.76
simpleMathMethod · 0.36
edgeCaseProviderMethod · 0.36