1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* -------------------------------------------------------------------------------------------------- */
/* Port of the Intel Decimal Floating-Point Math Library decimal128 type to Rust. */
/* decmathlib-rs - Copyright (C) 2023-2024 Carlos Guzmán Álvarez */
/* -------------------------------------------------------------------------------------------------- */
/* Licensed under the MIT license. See LICENSE file in the project root for full license information. */
/* -------------------------------------------------------------------------------------------------- */
/* Intel® Decimal Floating-Point Math Library - Copyright (c) 2018, Intel Corp. */
/* -------------------------------------------------------------------------------------------------- */
use crate::bid_internal::{BID_HIGH_128W, BID_LOW_128W, BID_UINT128, BID_UINT64, SIGNMASK32, SIGNMASK64};
pub (crate) fn bid128_from_int32(x: i32) -> BID_UINT128 {
let mut res: BID_UINT128 = Default::default();
// if integer is negative, use the absolute value
if (x & (SIGNMASK32 as i32)) == (SIGNMASK32 as i32) {
res.w[BID_HIGH_128W] = 0xb040000000000000u64;
res.w[BID_LOW_128W] = !(x as u64) + 1; // 2's complement of x
} else {
res.w[BID_HIGH_128W] = 0x3040000000000000u64;
res.w[BID_LOW_128W] = x as u64;
}
res
}
pub (crate) fn bid128_from_uint32(x: u32) -> BID_UINT128 {
let mut res: BID_UINT128 = Default::default();
res.w[BID_HIGH_128W] = 0x3040000000000000u64;
res.w[BID_LOW_128W] = x as u64;
res
}
pub (crate) fn bid128_from_int64(x: i64) -> BID_UINT128 {
let mut res: BID_UINT128 = Default::default();
// if integer is negative, use the absolute value
if (x & (SIGNMASK64 as i64)) == (SIGNMASK64 as i64) {
res.w[BID_HIGH_128W] = 0xb040000000000000u64;
res.w[BID_LOW_128W] = (!x + 1) as BID_UINT64; // 2's complement of x
} else {
res.w[BID_HIGH_128W] = 0x3040000000000000u64;
res.w[BID_LOW_128W] = x as BID_UINT64;
}
res
}
pub (crate) fn bid128_from_uint64(x: u64) -> BID_UINT128 {
let mut res : BID_UINT128 = Default::default();
res.w[BID_HIGH_128W] = 0x3040000000000000u64;
res.w[BID_LOW_128W] = x;
res
}