fix to_i64 for modulus u64

This commit is contained in:
Janmajaya Mall
2024-05-20 13:22:32 +05:30
parent 28216110b2
commit b8fdf4552e
2 changed files with 4 additions and 4 deletions

View File

@@ -56,14 +56,14 @@ impl Modulus for u64 {
// 0.0?
let v = v.round();
if v < 0.0 {
self - v.to_u64().unwrap()
self - v.abs().to_u64().unwrap()
} else {
v.to_u64().unwrap()
}
}
fn map_element_from_i64(&self, v: i64) -> Self::Element {
if v < 0 {
self - v.to_u64().unwrap()
self - v.abs().to_u64().unwrap()
} else {
v.to_u64().unwrap()
}
@@ -171,7 +171,7 @@ impl<T> ModularOpsU64<T> {
debug_assert!(a < self.q);
debug_assert!(b < self.q);
if a > b {
if a >= b {
a - b
} else {
(self.q + a) - b

View File

@@ -1927,7 +1927,7 @@ mod tests {
let mut bool_evaluator = BoolEvaluator::<
Vec<Vec<u64>>,
NttBackendU64,
WordSizeModulus<CiphertextModulus<u64>>,
ModularOpsU64<CiphertextModulus<u64>>,
ModularOpsU64<CiphertextModulus<u64>>,
>::new(SP_BOOL_PARAMS);