Numbers
4-Value Logic Values
A scalar logic net can be one of four possible values:
Value |
Description |
0 |
Zero, low, or false. |
1 |
One, high, or true. |
x |
Unknown or uninitialized. |
z |
Undriven (floating). |
Integers
Simple integers are numbers constructed from digits and possibly underscores. Underscores are ignored in numbers, so 42_839 is equivalent to 42839.
- Examples:
124
+124
-124
42_839
Simple integers are signed unsized numbers. A simple integer specification may not contain an x or z.
Except in Verilog-A, integer numbers can be explicitly expressed in decimal, hexadecimal, octal, or binary notation. To do so, use s’bn; where s is an optional decimal number that indicates the size of the constant in bits; b is the base format and n is the number in the specified base. The base format is a one or two character code that signifies the following types of numbers:
b
unsigned binary
o
unsigned octal
d
unsigned decimal
h
unsigned hexadecimal
sb
signed binary
so
signed octal
sd
signed decimal
sh
signed hexadecimal
In hexadecimal numbers the letters a
through f
represent the digits 10
through 15. Letters in integer constants can be either lower or upper case.
- Examples:
63
— unsized unsigned decimal number'd63
— unsized unsigned decimal number'h3f
— unsized unsigned hexadecimal number'o77
— unsized unsigned octal number'b11_1111
— unsized unsigned binary number12'h3f
— 12 bit unsigned hexadecimal number5'sd0
— 5 bit signed decimal number
The letters x
and z
can be given to denote unknown and high impedance
digits in all numbers that use a base format, and _
is ignored. Sized
constants for which the size is larger than the given number are padded on the
left with zeros unless the first digit of the given number is an x
or z
,
which are padded with the x
or z
. The number is truncated on the left if
the size is smaller than the given number.
- Examples:
64'o0
— a 64 bit octal 0 (zero padded)8'hx
— equivalent to8'bxxxx_xxxx
(x
padded)12'hfx
— equivalent to12'b0000_1111_xxxx
(zero padded)8'hfffx
— equivalent to8'b1111_xxxx
(truncated)
Real Numbers
Real numbers must either include a decimal point or a scale factor. If a decimal point is present, there must be digits on both sides. So .12, 9., 4.eE3, and .2e-7 are not valid numbers. Underscores are ignored in real numbers. Scale factors are given in the table below. These scale factors are available in Verilog-A and Verilog-AMS, but not in Verilog.
- Examples:
3.14
0.1
1.2E12
1.30e-2
236.123_763e-12
1.3u
5.46K
Multiplier |
Name |
Symbol |
1012 |
tera |
|
109 |
giga |
|
106 |
mega |
|
103 |
kilo |
|
10-3 |
milli |
|
10-6 |
micro |
|
10-9 |
nano |
|
10-12 |
pico |
|
10-15 |
fempto |
|
10-18 |
atto |
|
10d |
exponent |
|
constants.vams
Predefined numbers in the form of compiler directives are included in the file constants.vams and listed in the table below (only available in Verilog-A and Verilog-AMS). The would be included with:
`include "constants.vams"
Mathematical constants are denoted with a `M_ prefix.
|
π |
3.14159265358979323846 |
|
2π |
6.28318530717958647693 |
|
π/2 |
1.57079632679489661923 |
|
π/4 |
0.78539816339744830962 |
|
1/π |
0.31830988618379067154 |
|
2/π |
0.63661977236758134308 |
|
2/√π |
1.12837916709551257390 |
|
e |
2.7182818284590452354 |
|
log2 e |
1.4426950408889634074 |
|
log10 e |
0.43429448190325182765 |
|
loge 2 |
0.69314718055994530942 |
|
loge 10 |
2.30258509299404568402 |
|
√2 |
1.41421356237309504880 |
|
1/√2 |
0.70710678118654752440 |
Physical constants use the `P_ prefix.
|
charge of an electron |
1.602176462 × 10 -19 C |
|
speed of light |
2.99792458 × 10 8 m/s |
|
Boltzmann’s constant |
1.3806503 × 10 -23 J/K |
|
Planck’s constant |
6.626076 × 10 -34 J-s |
|
permittivity of a vacuum |
8.854187817 × 10 -12 F/m |
|
permeability of a vacuum |
4π10 -7 H/m |
|
0 Celsius |
273.15 K |