1
ecnelises 2023-02-04 00:21:45 +08:00
试试在 Rust 或者 JS 里看看 905325263262362321.0 < 905325263262362322.0 的结果
|
3
takato OP 905325263262362321.0 < 905325263262362322.0
false 905325263262362321.0 > 905325263262362322.0 false 905325263262362321.0 == 905325263262362322.0 true |
4
liuxu 2023-02-04 16:44:41 +08:00
|
5
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)); } ``` |
6
corhuan 2023-02-04 17:54:45 +08:00
|