Real to floating point

Hello,
Is there an easy way to convert a real data type(e.g. -60.345) to its IEEE 32 bit floating point representation(IEEE754)? (and vice versa).
Thanks

In reply to shaygueta:
Assuming you are aware of the following

SV real = C double (64-bit IEEE-754)
SV shortreal = C float (32-bit IEEE-754)

You can have a look at the LRM section 20.5 Conversion functions to check the casting result in the snippet

System functions are provided to convert values to and from real number values, and to convert values to signed or unsigned values.
[63:0] $realtobits ( real_val )
real $bitstoreal ( bit_val )
[31:0] $shortrealtobits ( shortreal_val )
shortreal $bitstoshortreal ( bit_val )
These conversion system functions may be used in constant expressions, as specified in 11.2.1.


module test();
    
  shortreal  float32;  
  real       float64;  
  real       x;
  
  initial begin
    
    float64 = 7.1000001;
    float32 = shortreal'(float64);
    x = real'(float32);  
    $display("float64_bits = %64b", $realtobits(float64));
    $display("float32_bits = %32b", $shortrealtobits(float32));
    $display("x_bin = %64b", $realtobits(x));
    
  end
  
endmodule
# KERNEL: float64_bits = 0100000000011100011001100110011001101101000111000110001100001101
# KERNEL: float32_bits = 01000000111000110011001100110011
# KERNEL: x_bin        = 0100000000011100011001100110011001101101000111000110001100001101

Keep in mind that changing from 64-bit to 32-bit you are most likely losing precision.
you can double check with many online converters from binary to IEEE-754 (32, and 64 bit) formats like this one Base Convert: IEEE 754 Floating Point

HTH,
-R