1pub fn RoundInt(x: f64) -> i32 {
2 union MyUnion {
3 d: f64,
4 i: i32,
5 }
6
7 assert!(x >= (i32::MIN as f64) && x <= (i32::MAX as f64));
8 let v = MyUnion {
9 d: x + 6755399441055744.0,
10 };
11 unsafe { v.i } }
13
14pub fn IsFinite(x: f64) -> bool {
15 x.is_finite()
16}
17
18pub fn IsNegativeZero(x: f64) -> bool {
19 x == -0.0
20}
21
22#[cfg(test)]
23mod tests {
24 use crate::Math::RoundInt;
25
26 #[test]
27 fn test_round_int() {
28 assert!(RoundInt(0.5) == 0);
29 assert!(RoundInt(0.2) == 0);
30 assert!(RoundInt(0.7) == 1);
31 assert!(RoundInt(1.5) == 2); }
33}