-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* ---------------------------------------------------------------------------------------------------*/ | ||
/* 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 fu64 license information. */ | ||
/* -------------------------------------------------------------------------------------------------- */ | ||
/* Intel® Decimal Floating-Point Math Library - Copyright (c) 2018, Intel Corp. */ | ||
/* -------------------------------------------------------------------------------------------------- */ | ||
|
||
use crate::constants::{MASK_ANY_INF, MASK_INF, MASK_STEERING_BITS, NAN_MASK64, QUIET_MASK64}; | ||
use crate::d128::{BID_UINT128, BID_UINT64}; | ||
|
||
/// The quantumdN functions compute the quantum of a finite argument. | ||
/// If x is infinite, the result is +Inf. If x is NaN, the result is NaN. | ||
pub (crate) fn bid128_quantum(x: &BID_UINT128) -> BID_UINT128 { | ||
let mut res: BID_UINT128 = BID_UINT128::default(); | ||
|
||
// If x is infinite, the result is +Inf. If x is NaN, the result is NaN | ||
if (x.w[1] & MASK_ANY_INF) == MASK_INF { | ||
res.w[1] = 0x7800000000000000u64; | ||
res.w[0] = 0x0000000000000000u64; | ||
return res; | ||
} else if (x.w[1] & NAN_MASK64) == NAN_MASK64 { | ||
res.w[1] = x.w[1] & QUIET_MASK64; | ||
return res; | ||
} | ||
|
||
// Extract exponent | ||
let int_exp = if (x.w[1] & MASK_STEERING_BITS) == MASK_STEERING_BITS { | ||
(((x.w[1] >> 47) & 0x3fff) as i32) - 6176 | ||
} else { | ||
(((x.w[1] >> 49) & 0x3fff) as i32) - 6176 | ||
}; | ||
|
||
// Form 10^new_exponent*1 | ||
res.w[1] = (((int_exp as i64) << 49 ) + 0x3040000000000000i64) as BID_UINT64; | ||
res.w[0] = 0x0000000000000001u64; | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* ---------------------------------------------------------------------------------------------------*/ | ||
/* 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. */ | ||
/* -------------------------------------------------------------------------------------------------- */ | ||
|
||
mod common; | ||
|
||
dec_test!(bid128_quantum_001, bid128_quantum, 0x304C0000000000000000000000003039u128, 0x304C0000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_002, bid128_quantum, 0xB04C0000000000000000000000003039u128, 0x304C0000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_003, bid128_quantum, 0x302C0000000000000000000000003039u128, 0x302C0000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_004, bid128_quantum, 0xB02C0000000000000000000000003039u128, 0x302C0000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_005, bid128_quantum, 0x30360000000000000000000000003039u128, 0x30360000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_006, bid128_quantum, 0xB0360000000000000000000000003039u128, 0x30360000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_007, bid128_quantum, 0x303E000000000000000000000001E23Au128, 0x303E0000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_008, bid128_quantum, 0x5FFE314DC6448D9338C15B0A00000000u128, 0x5FFE0000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_009, bid128_quantum, 0xDFFE314DC6448D9338C15B0A00000000u128, 0x5FFE0000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_010, bid128_quantum, 0x30400000000000000000000000000000u128, 0x30400000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_011, bid128_quantum, 0xB0400000000000000000000000000000u128, 0x30400000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_012, bid128_quantum, 0x00000000000000000000000000000001u128, 0x00000000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_013, bid128_quantum, 0x80000000000000000000000000000001u128, 0x00000000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_014, bid128_quantum, 0x00000000000000000000000000000000u128, 0x00000000000000000000000000000001u128); | ||
dec_test!(bid128_quantum_015, bid128_quantum, 0x78000000000000000000000000000000u128, 0x78000000000000000000000000000000u128); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters