Index: include/llvm/ADT/APFloat.h =================================================================== --- include/llvm/ADT/APFloat.h +++ include/llvm/ADT/APFloat.h @@ -276,6 +276,10 @@ /// \param isIEEE - If 128 bit number, select between PPC and IEEE static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE = false); + /// Returns the size of the floating point number (in bits) in the given + /// semantics. + static unsigned getSizeInBits(const fltSemantics &Sem); + /// @} /// Used to insert APFloat objects, or objects that contain APFloat objects, Index: lib/Support/APFloat.cpp =================================================================== --- lib/Support/APFloat.cpp +++ lib/Support/APFloat.cpp @@ -3368,6 +3368,21 @@ } } +unsigned APFloat::getSizeInBits(const fltSemantics &Sem) +{ + // sign bit + mantissa + unsigned size = 1 + Sem.precision; + + // Add size of the exponent + ExponentType ex = Sem.maxExponent; + while (ex) { + ex >>= 1; + size++; + } + + return size; +} + /// Make this number the largest magnitude normal number in the given /// semantics. void APFloat::makeLargest(bool Negative) {