How to get float value in IR

IR is as follows:

store float 1.000000e+00, float* %f, align 4, !dbg !860
%0 = load float, float* %f, align 4, !dbg !861

So if I know the name %f, how can I get 1.000000e+00 in both load and store instruction?

I know that constant_int->getSExtValue() can get int value. But I didn’t find similar function provided by ConstantFP.

Well, I read countless blogs. And I finally find the hints in here. APFloat::converToDouble() is an appropriate function.

Here is my code:

if (auto *op = dyn_cast<StoreInst>(&I))
{
  // get left: value
  Value *arg1 = op->getOperand(0); // %4 = xxx
  Value *arg2 = op->getOperand(1);

  Value *val = op->getValueOperand();
  if (auto constant_int = dyn_cast<ConstantInt>(val))
  {
    int number = constant_int->getSExtValue();
    errs() << "ConstantInt " << number << ".\n";
  }
  else if (auto constant_fp = dyn_cast<ConstantFP>(val))
  {
    APFloat apfloat_number = constant_fp->getValueAPF();
    // float number = constant_fp->getValueAPF();
    double number = apfloat_number.convertToDouble();
    errs() << "APFloat float" << number << ".\n";
  }
}