mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-09 14:47:56 -05:00
chore: add (previously) failing test case for u128 decomposition
- the code fix was already correct, but we add another edge case because we have specialized decomposition code for u128 that we need to update and we need a previously failing case, this serves as reference for the fix of the specialized implementation
This commit is contained in:
committed by
IceTDrinker
parent
52a22ea82a
commit
dfcceefa83
@@ -242,6 +242,27 @@ fn test_decomposition_edge_case_sign_handling() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decomposition_edge_case_sign_handling_u128() {
|
||||
let decomposer = SignedDecomposer::new(DecompositionBaseLog(40), DecompositionLevelCount(3));
|
||||
// This value triggers a negative state at the start of the decomposition, invalid code using
|
||||
// logic shift will wrongly compute an intermediate value by not keeping the sign of the
|
||||
// state on the last level if base_log * (level_count + 1) > Scalar::BITS, the logic shift will
|
||||
// shift in 0s instead of the 1s to keep the sign information
|
||||
let val: u128 = 170141183460604905165246226680529368983;
|
||||
|
||||
let rounded = decomposer.closest_representable(val);
|
||||
let recomp = decomposer.recompose(decomposer.decompose(val)).unwrap();
|
||||
let decomp = decomposer.decompose(val);
|
||||
assert_eq!(rounded, recomp);
|
||||
|
||||
let expected = [-421613125320i128, 482008863255, -549755813888];
|
||||
|
||||
for (term, expect) in decomp.zip(expected) {
|
||||
assert_eq!(term.value() as i128, expect, "Problem with term {term:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_recompose_exhaustive() {
|
||||
let base_log = DecompositionBaseLog(10);
|
||||
|
||||
Reference in New Issue
Block a user