lambgrp425
lambgrp425

Reputation: 706

$display floating-point number in console

I'm trying to display an IEEE 754 single precision floating-point number during simulation. I'm using $display() and attempting to print the number in both ModelSim and in my console (using Icarus Verilog on a Mac). My best attempt so far is this:

wire [31:0] out;
wire signed [200:0] conv = -1**(out[31]) * (1'b1 + (out[22:0] * 2'b10**($signed(8'b11101001)))) * 2'b10**(out[30:23] + $signed(8'b10000001));

$display("The number is %f", conv);

The width of converted is just arbitrarily large. For 11000001100111010000100000110000, the above will print out -16.000000. I've determined that the sign and the exponent parts work, but the mantissa, which is being multiplied by 2^-23, is just going to 0. The real answer should be -19.628998.

Any ideas what I'm missing? Is this even possible in Verilog?

Upvotes: 2

Views: 11226

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180917

If I understand you correctly, what you want is $bitstoreal, something like;

wire [31:0] out;

$display("The number is %f", $bitstoreal(out));

Upvotes: 4

Related Questions