# 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 number
`12'h3f` — 12 bit unsigned hexadecimal number
`5'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 to `8'bxxxx_xxxx` (`x` padded)
`12'hfx` — equivalent to `12'b0000_1111_xxxx` (zero padded)
`8'hfffx` — equivalent to `8'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 `T` 109 giga `G` 106 mega `M` 103 kilo `K` or `k` 10-3 milli `m` 10-6 micro `u` 10-9 nano `n` 10-12 pico `p` 10-15 fempto `f` 10-18 atto `a` 10d exponent `e` d or `E` d

### 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.

 ``M_PI` π 3.14159 ``M_TWO_PI` 2π 6.28319 ``M_PI_2` π/2 1.5708 ``M_PI_4` π/4 0.785398 ``M_1_PI` 1/π 0.31831 ``M_2_PI` 2/π 0.63662 ``M_2_SQRTPI` 2/√π 1.12838 ``M_E` e 2.71828 ``M_LOG2E` log2 e 1.4427 ``M_LOG10E` log10 e 0.434294 ``M_LN2` loge 2 0.693147 ``M_LN10` loge 10 2.30259 ``M_SQRT2` √2 1.41421 ``M_SQRT1_2` 1/√2 0.707107

Physical constants use the `P_ prefix.

 ``P_Q` charge of an electron 1.602176462 × 10 -19 C ``P_C` speed of light 2.99792458 × 10 8 m/s ``P_K` Boltzmann’s constant 1.3806503 × 10 -23 J/K ``P_H` Planck’s constant 6.626076 × 10 -34 J-s ``P_EPS0` permittivity of a vacuum 8.854187817 × 10 -12 F/m ``P_U0` permeability of a vacuum 4π10 -7 H/m ``P_CELSIUS0` 0 Celsius 273.15 K