# 訊息

## English

``````module main;
real x, y, x2, y2, xyadd, xysub, xymul, xydiv;
reg [63:0] x1, y1;

initial
begin
x=3.14159;
y=-2.3e4;
x1 = \$realtobits(x);
x2 = \$bitstoreal(x1);
y1 = \$realtobits(y);
y2 = \$bitstoreal(y1);
xysub = x-y;
xymul = x*y;
xydiv = x/y;
\$display("x=%f x1=%b x2=%f", x, x1, x2);
\$display("y=%f y1=%b y2=%f", y, y1, y2);
\$display("x-y=%f xysub=%f", x-y, xysub);
\$display("x*y=%f xymul=%f", x*y, xymul);
\$display("x/y=%f xydiv=%f", x/y, xydiv);
end

endmodule```
```

# 執行結果

``````D:\oc>iverilog float.v -o float

D:\oc>vvp float
x=3.141590 x1=0100000000001001001000011111100111110000000110111000011001101110 x
2=3.141590
y=-23000.000000 y1=1100000011010110011101100000000000000000000000000000000000000
000 y2=-23000.000000
x-y=23003.141590 xysub=23003.141590
x*y=-72256.570000 xymul=-72256.570000
x/y=-0.000137 xydiv=-0.000137```
```

# 參考文獻

1. http://en.wikipedia.org/wiki/Double-precision_floating-point_format
2. Simplified Floating Point for DSP ECE 5760, Cornell University
3. 2010年6月25日星期五, float point @ verilog
4. Chapter 3: Verilog Syntax Details
``````.2 Behavioral Data Types: integer, real, and time

The types in integer and real are convenient data types to use for counting in behavioral code blocks. These data types act like their counter parts in other programming languages. If you eventually plan to synthesize your behavioral code then you would probably want to avoid using these data types because they often synthesize large circuits.

The data type time can hold a special simulator value called simulation time which is extracted from the system function \$time. The time information can be used to help you debug your simulations.

..... //code fragment from inside a module

integer i, y;
real a;
real b = 3.5;
real c = 4;
time simulationTime;
initial
begin
y = 4;
i = 5 + y;
c = c + 3.5;
a = 5.3e4;
simulationTime = \$time;
\$display("integer y = %d, i = %f \n", y, i);
\$display("reals   c = %f, a = %e, b= %g \n", c, a, b);
\$display("time    simulationTime = %t \n", simulationTime);```
```