#[inline]
pub fn zlong_from_double(d: f64) -> i64 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
if !(-9_223_372_036_854_775_808.0..9_223_372_036_854_775_808.0).contains(&d) {
return i64::MIN;
}
}
d as i64
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn in_range_values_truncate_toward_zero() {
assert_eq!(zlong_from_double(3.9), 3);
assert_eq!(zlong_from_double(-3.9), -3);
assert_eq!(zlong_from_double(-9_223_372_036_854_775_808.0), i64::MIN);
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[test]
fn x86_answers_integer_indefinite_for_unrepresentable() {
for d in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, 9.3e18, -9.3e18] {
assert_eq!(zlong_from_double(d), i64::MIN, "{d}");
}
}
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
#[test]
fn saturating_hosts_clamp_and_zero_nan() {
assert_eq!(zlong_from_double(f64::INFINITY), i64::MAX);
assert_eq!(zlong_from_double(f64::NEG_INFINITY), i64::MIN);
assert_eq!(zlong_from_double(f64::NAN), 0);
}
}