Real Datatype

Real datatype

A datatype in verilog that can store floating-point values, such as decimal numbers with both integer and fractional factors, is referred to as a “real datatype”. Real datatype can store values, just like registers (reg) and integers (integer datatype). This implies that you can assign a floating-point value to a real datatype in verilog in a manner similar to how you would do it for registers and integer variables.

      Click here to follow our WhatsApp Channel

Real datatype, however, can only be changed within procedural blocks, more precisely within blocks like “always” and “initial.” This is a significant restriction. Code parts known as procedural blocks define the processes and behaviors that should occur under certain conditions or at particular periods throughout the execution of the code. This means that only within these specified procedural blocks are real datatype that involve in operations, calculations, and assignments permitted.

‘0’ is the default value given to a real datatype. As a result, if you declare a real datatype without explicitly giving it a value, it will be initialised with zero by default.

In conclusion, real datatypes can be given values similar to registers and integer datatypes and are used to store floating-point values, such as decimal numbers. However, you can only change their values in procedural blocks like “always” and “initial,” where they are used. The default value of real datatype is ‘0’ if they are not given a value.

Read more: Real datatype code examples

module Real_tb;

  // Declare a real variable
  real voltage;

  initial begin
    // Assign a real value to the variable
    voltage = 3.14;

    // Display the real value
    $display("Voltage: %0f", voltage);

    // Perform some arithmetic operations
    voltage = voltage * 2.0;
    $display("Doubled Voltage: %0f", voltage);

    voltage = voltage + 1.5;
    $display("Voltage + 1.5: %0f", voltage);

    // Wait for a while
    #10;

    // Display final value
    $display("Final Voltage: %0f", voltage);

  end

endmodule

Output:

Voltage: 3.140000
Doubled Voltage: 6.280000
Voltage + 1.5: 7.780000
Final Voltage: 7.780000


V C S S i m u l a t i o n R e p o r t

Scroll to Top