Overflow detection
name
symbol
type
/// Adds two [FheUint] and returns a boolean indicating overflow.
///
/// * The operation is modular, i.e on overflow the result wraps around.
/// * On overflow the [FheBool] is true, otherwise false
use tfhe::prelude::*;
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint16};
let (client_key, server_key) = generate_keys(ConfigBuilder::default());
set_server_key(server_key);
let a = FheUint16::encrypt(u16::MAX, &client_key);
let b = FheUint16::encrypt(1u16, &client_key);
let (result, overflowed) = (&a).overflowing_add(&b);
let result: u16 = result.decrypt(&client_key);
assert_eq!(result, u16::MAX.wrapping_add(1u16));
assert_eq!(
overflowed.decrypt(&client_key),
u16::MAX.overflowing_add(1u16).1
);
assert!(overflowed.decrypt(&client_key));Operation\Size
FheUint8
FheUint16
FheUint32
FheUint64
FheUint128
FheUint256
Operation\Size
FheInt8
FheInt16
FheInt32
FheInt64
FheInt128
FheInt256
Last updated
Was this helpful?