corhuan
2023-02-04 17:49:59 +08:00
```rust
/// x <= y
fn is_less_eq(x: i64, y: f64) -> bool {
const H: f64 = 9223372036854775808f64;
if !y.is_finite() {
return false;
} else if y >= H {
return true;
} else if y < -H {
return false;
} else {
let y = y.floor() as i64;
x <= y
}
}
fn main() {
println!("{}", is_less_eq(9007199254740993, 9007199254740992.0));
println!("{}", is_less_eq(1, 1.125f64));
println!("{}", is_less_eq(1, 0.125f64));
println!("{}", is_less_eq(1, f64::MIN_POSITIVE));
println!("{}", is_less_eq(-1, -0.125f64));
println!("{}", is_less_eq(-1, -1.125f64));
println!("{}", is_less_eq(-1, -1f64));
println!("{}", is_less_eq(i64::MIN, i64::MIN as f64));
println!("{}", is_less_eq(i64::MIN, -9223372036854777856f64));
}
```