Sha256: bc1ed053dd63d45ac9c35302f18de9f00d94027f28af4ab749c9248439de832a

Contents?: true

Size: 1.21 KB

Versions: 31

Compression:

Stored size: 1.21 KB

Contents

// Adapted from https://github.com/Alexhuszagh/rust-lexical.

//! Bit-shift helpers.

use super::float::ExtendedFloat;
use core::mem;

// Shift extended-precision float right `shift` bytes.
#[inline]
pub(crate) fn shr(fp: &mut ExtendedFloat, shift: i32) {
    let bits: u64 = mem::size_of::<u64>() as u64 * 8;
    debug_assert!((shift as u64) < bits, "shr() overflow in shift right.");

    fp.mant >>= shift;
    fp.exp += shift;
}

// Shift extended-precision float right `shift` bytes.
//
// Accepts when the shift is the same as the type size, and
// sets the value to 0.
#[inline]
pub(crate) fn overflowing_shr(fp: &mut ExtendedFloat, shift: i32) {
    let bits: u64 = mem::size_of::<u64>() as u64 * 8;
    debug_assert!(
        (shift as u64) <= bits,
        "overflowing_shr() overflow in shift right."
    );

    fp.mant = if shift as u64 == bits {
        0
    } else {
        fp.mant >> shift
    };
    fp.exp += shift;
}

// Shift extended-precision float left `shift` bytes.
#[inline]
pub(crate) fn shl(fp: &mut ExtendedFloat, shift: i32) {
    let bits: u64 = mem::size_of::<u64>() as u64 * 8;
    debug_assert!((shift as u64) < bits, "shl() overflow in shift left.");

    fp.mant <<= shift;
    fp.exp -= shift;
}

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/serde_json-1.0.137/src/lexical/shift.rs
wasmtime-28.0.0 ./ext/cargo-vendor/serde_json-1.0.135/src/lexical/shift.rs
wasmtime-27.0.0 ./ext/cargo-vendor/serde_json-1.0.133/src/lexical/shift.rs
wasmtime-26.0.0 ./ext/cargo-vendor/serde_json-1.0.132/src/lexical/shift.rs
wasmtime-25.0.2 ./ext/cargo-vendor/serde_json-1.0.125/src/lexical/shift.rs
wasmtime-25.0.1 ./ext/cargo-vendor/serde_json-1.0.125/src/lexical/shift.rs
wasmtime-25.0.0 ./ext/cargo-vendor/serde_json-1.0.125/src/lexical/shift.rs
wasmtime-24.0.0 ./ext/cargo-vendor/serde_json-1.0.125/src/lexical/shift.rs
wasmtime-23.0.2 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-22.0.0 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-21.0.1 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-20.0.2 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-20.0.0 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-18.0.3 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-17.0.1 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-17.0.0 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-16.0.0 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-15.0.1 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-15.0.0 ./ext/cargo-vendor/serde_json-1.0.111/src/lexical/shift.rs
wasmtime-14.0.4 ./ext/cargo-vendor/serde_json-1.0.107/src/lexical/shift.rs