5.2.3. The `real` Data Type
Overview
The `real` data type represents floating-point numbers in Verilog, following IEEE 754 double-precision format. It's primarily used for modeling analog behavior and mathematical calculations requiring fractional precision.
Syntax and Declaration
Verilog
real variable_name;
real variable_name1, variable_name2;
Characteristics
​
-
Format: IEEE 754 double-precision (64-bit)
​
-
Range: Approximately ±1.7 × 10^308​
​​
-
Precision: ~15-17 decimal digits
​
-
Default value: 0.0
Examples
Verilog
module real_examples;
real voltage, current, power;
real frequency = 100.5e6; // 100.5 MHz
real temperature = -40.25; // -40.25°C
initial begin
voltage = 3.3;
current = 0.025;
power = voltage * current; // 0.0825
$display("Power consumption: %f watts", power);
$display("Frequency: %e Hz", frequency);
end
endmodule
Limitations
​
-
Cannot be synthesized to hardware
​​
-
Mainly used for simulation and modeling
​​
-
No bit-wise operations allowed
​
-
Cannot be used in sensitivity lists
Real Applications
Verilog
// Analog modeling
real voltage_supply = 5.0;
real current_load = 0.5;
real power_dissipation = voltage_supply * current_load;
// Timing calculations
real period = 10.0; // ns
real frequency = 1.0 / (period * 1e-9);
Initialization
Verilog
// Always initialize variables
real temperature = 25.0;
Real Number Precision
Verilog
// Be aware of floating-point precision limits
real precise_value = 0.1 + 0.2; // May not equal exactly 0.3
