deep-time 0.1.0-beta.26

High-precision, no-std, no-alloc date-time library, leap-seconds, time scales, relativistic time, and a powerful date & duration parser
Documentation
use crate::Real;

/// Const-compatible version of `Real::trunc` (rounds toward zero)
pub const fn trunc(x: Real) -> Real {
    let bits = x.to_bits();
    let sign = bits & (1u64 << 63);
    let exp = ((bits >> 52) & 0x7ff) as i32 - 1023;

    if exp < 0 {
        // |x| < 1.0 → result is signed zero
        return Real::from_bits(sign);
    }

    if exp >= 52 {
        return x;
    }

    // Clear all fractional bits
    let mask = !0u64 << (52 - exp);
    let truncated = (bits & mask) | sign; // preserve sign
    Real::from_bits(truncated)
}
// tests in super::round