You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need a function that converts ABDKMathQuad number into mantissa and exponent where quad = mantissa * 2**exponent. The mantissa lies in the open interval(-1, 1), while the twos exponent is a signed integer. It isn't as straightforward as I thought. The function I have constructed is shown below. But it is obvious that it isn't correct. Can anyone help me with this?
I expect the output to be equivalent to what numpy.frexp would return for a float.
function frexp(
bytes16 quad
) public pure returns (uint256 mantissa, int256 exponent) {
uint256 exponent1 = (uint128(quad) >> 112) & 0x7FFF;
mantissa = uint128(quad) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
mantissa = mantissa * 2 ** 63;
exponent = -int256(exponent1);
if (exponent == 0) {
//it's a subnormal number
exponent += 63;
} else {
//substract one from the whole number
quad = quad.sub(ABDKMathQuad.fromUInt(1));
//mantissat = mantissa of the original number 2**63
//exponent = exponent of the substracted number - 16383 - 63
exponent += 16383 + 63;
}
}
The text was updated successfully, but these errors were encountered:
I need a function that converts ABDKMathQuad number into mantissa and exponent where
quad = mantissa * 2**exponent
. The mantissa lies in the open interval(-1, 1), while the twos exponent is a signed integer. It isn't as straightforward as I thought. The function I have constructed is shown below. But it is obvious that it isn't correct. Can anyone help me with this?I expect the output to be equivalent to what numpy.frexp would return for a float.
The text was updated successfully, but these errors were encountered: