How to cast i32 to f32 in mlir?

I have a mlir function to cast i32 to f32.

module {
  func.func @forward() -> f32{
    %0 = arith.constant 1 : i32
    %3 = arith.bitcast %0 : i32 to f32
    return %3 : f32
  }
}

But I get the value of %3 is 1.4013e-45. It should be 1. Is arith.bitcast only copy byte? How can I get a right value? Thank for your help.

The arith.sitofp function converts integers to floating point.

2 Likes

What you got is denormal epsilon–which is what you ask for:: 0x00000001 as f32 is 1.4013e-45

Yes! Thank you for your help.

I got it! Thank you for your help.