numeric limits of llvm Types?

Hi all,

can I access the numeric limits of the llvm types,
e.g. HalfTy, FloatTy, DoubleTy, etc.
in a fashion like the std numeric_limits tool?


In c++API, I want to initialize values and need to know the correct range
for the llvm types....


The APFloat class may have what you need, especially if you're looking
to create llvm::Constants.

-- Sanjoy

i know the APFloat class, indeed, I initialize as follows:

    if(pType->isFloatTy() || pType->isHalfTy() || pType->isDoubleTy() ||
pType->isX86_FP80Ty() || pType->isFP128Ty() || pType->isPPC_FP128Ty() )
        //--- get rando value in range
        //tbd: replace by type specific range!
        double d=randZeroOne()*(std::numeric_limits<double>::max() -

        ConstantFP* constF_1 = ConstantFP::get(rM.getContext(), APFloat(d));


I want an 'llvm replacement' for td::numeric_limits<double>::max()

I have seen that FLTSemantics defines

  const fltSemantics APFloat::IEEEhalf = { 15, -14, 11 };
  const fltSemantics APFloat::IEEEsingle = { 127, -126, 24 };
  const fltSemantics APFloat::IEEEdouble = { 1023, -1022, 53 };
  const fltSemantics APFloat::IEEEquad = { 16383, -16382, 113 };
  const fltSemantics APFloat::x87DoubleExtended = { 16383, -16382, 64 };
  const fltSemantics APFloat::Bogus = { 0, 0, 0 };

but I'm not sure if I should use these.

I think there should be something like e.g.
FloatType::numeric_limit_min ...


Sanjoy Das wrote:

Having a llvm float type
Type* pType

i can do
const fltSemantics &fltS=pType->getFltSemantics();

In the debugger, I see taht fltS has maxExponent, minExponent, precision.

However, if I try to access these, I get an error like
'Illegal use of incomplete type....'

Guess this is just a lack of c++ skills....


Alexander Poddey wrote: