forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloor.java
More file actions
32 lines (30 loc) · 1020 Bytes
/
Floor.java
File metadata and controls
32 lines (30 loc) · 1020 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
package Maths;
public class Floor {
public static void main(String[] args) {
assert floor(10) == Math.floor(10);
assert floor(-10) == Math.floor(-10);
assert floor(10.0) == Math.floor(10.0);
assert floor(-10.0) == Math.floor(-10.0);
assert floor(10.1) == Math.floor(10.1);
assert floor(-10.1) == Math.floor(-10.1);
assert floor(0) == Math.floor(0);
assert floor(-0) == Math.floor(-0);
assert floor(0.0) == Math.floor(0.0);
assert floor(-0.0) == Math.floor(-0.0);
}
/**
* Returns the largest (closest to positive infinity)
*
* @param number the number
* @return the largest (closest to positive infinity) of given {@code number}
*/
public static double floor(double number) {
if (number - (int) number == 0) {
return number;
} else if (number - (int) number > 0) {
return (int) number;
} else {
return (int) number - 1;
}
}
}