Closed fangxiaoran closed 1 year ago
According to Wikipedia, a float number is represented as shown below.
Thus, multiplying a float number by $2^{(52-e+1023)}$ is enough to keep all significands when converting it to an integer. It's reasonable to use sys.float_info.mant_dig
. Note that flt_exponent = math.frexp(scalar)[1]
equals to $e-1023+1$, cls.FLOAT_MANTISSA_BITS - flt_exponent
$=53-(e-1023+1)=52-e+1023$.
However, a precision loss may occur in math.floor(lsb_exponent / cls.LOG2_BASE)
, since 16 is chosen as the BASE
, not 2. That might be another issue.
It seems
sys.float_info.mant_dig
is not a proper limitation for maximum exponent.https://github.com/intel/pailliercryptolib_python/blob/9000f1f5048b66397ab5e61e05ed2ff666158eba/src/ipcl_python/bindings/fixedpoint.py#L29