Numbers

Integers

Keywords: integer
default value: x
default size: dependant on the host machine, but at least 32 bits

Integers are similar to registers but can store signed (i.e. negative as well as positive numbers) whereas registers can only store positive numbers.

Real numbers

Keywords: real
default value: x
default size: again host machine dependant, but at least 64 bits

Real numbers can be in decimal or scientific format as shown in the example below. When written with a decimal point, there must be at least one number on either side of the point. A real number is converted to an integer by rounding to the nearest integer.

        // 1.3    a real number in decimal format
        // 1.3e27 a real number in scientific format

        real pedantic_pi;
        integer relaxed_pi;

        initial begin
           pedantic_pi = 3.141596259;
           relaxed_pi = pedantic_pi; // relaxed_pi is set to 3
        end

A warning about using registers vs. integers for signed values
An arithmetic operation is treated differently depending on the data type of the operand. A register operand is treated as an unsigned value and an integer value is treated as a signed value. Therefore if a negative value, such as -4'd12, is assigned to a register, it will stored as a positive integer which is its 2's complement value. So when used as an operand the 2's complement value will be used causing unintentional behaviour. If stored in an integer, the behaviour would be as expected, using signed arithmetic.


previous next contents