decimus 0.0.6

Decimal Floating-Point Math Library for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::BidUint128;
use crate::bid_internal::*;

/// Converts signed 32-bit integer into 128-bit decimal floting-point value.
pub fn bid128_from_int32(x: i32) -> BidUint128 {
  let mut res = BidUint128::default();
  // If integer is negative, use the absolute value.
  let u = x as u32;
  if (u & SIGNMASK32) == SIGNMASK32 {
    res.w[1] = 0xb040000000000000;
    res.w[0] = (!u + 1) as u64; // 2's complement of x
  } else {
    res.w[1] = 0x3040000000000000;
    res.w[0] = u as u64;
  }
  res
}