# Values¶

WebAssembly programs operate on primitive numeric values. Moreover, in the definition of programs, immutable sequences of values occur to represent more complex data, such as text strings or other vectors.

## Bytes¶

The simplest form of value are raw uninterpreted bytes. In the abstract syntax they are represented as hexadecimal literals.

$\begin{split}\begin{array}{llll} \def\mathdef2186#1{{}}\mathdef2186{byte} & \href{../syntax/values.html#syntax-byte}{\mathit{byte}} &::=& \def\mathdef2243#1{\mathtt{0x#1}}\mathdef2243{00} ~|~ \dots ~|~ \def\mathdef2244#1{\mathtt{0x#1}}\mathdef2244{FF} \\ \end{array}\end{split}$

### Conventions¶

• The meta variable $$b$$ ranges over bytes.
• Bytes are sometimes interpreted as natural numbers $$n < 256$$.

## Integers¶

Different classes of integers with different value ranges are distinguished by their bit width $$N$$ and by whether they are unsigned or signed.

$\begin{split}\begin{array}{llll} \def\mathdef2186#1{{}}\mathdef2186{unsigned integer} & \href{../syntax/values.html#syntax-int}{\def\mathdef2187#1{{\mathit{u}#1}}\mathdef2187{N}} &::=& 0 ~|~ 1 ~|~ \dots ~|~ 2^N{-}1 \\ \def\mathdef2186#1{{}}\mathdef2186{signed integer} & \href{../syntax/values.html#syntax-int}{\def\mathdef2194#1{{\mathit{s}#1}}\mathdef2194{N}} &::=& -2^{N-1} ~|~ \dots ~|~ {-}1 ~|~ 0 ~|~ 1 ~|~ \dots ~|~ 2^{N-1}{-}1 \\ \def\mathdef2186#1{{}}\mathdef2186{uninterpreted integer} & \href{../syntax/values.html#syntax-int}{\def\mathdef2199#1{{\mathit{i}#1}}\mathdef2199{N}} &::=& \href{../syntax/values.html#syntax-int}{\def\mathdef2187#1{{\mathit{u}#1}}\mathdef2187{N}} \\ \end{array}\end{split}$

The latter class defines uninterpreted integers, whose signedness interpretation can vary depending on context. In the abstract syntax, they are represented as unsigned values. However, some operations convert them to signed based on a two’s complement interpretation.

Note

The main integer types occurring in this specification are $$\href{../syntax/values.html#syntax-int}{\def\mathdef2192#1{{\mathit{u}#1}}\mathdef2192{\mathit{32}}}$$, $$\href{../syntax/values.html#syntax-int}{\def\mathdef2193#1{{\mathit{u}#1}}\mathdef2193{\mathit{64}}}$$, $$\href{../syntax/values.html#syntax-int}{\def\mathdef2197#1{{\mathit{s}#1}}\mathdef2197{\mathit{32}}}$$, $$\href{../syntax/values.html#syntax-int}{\def\mathdef2198#1{{\mathit{s}#1}}\mathdef2198{\mathit{64}}}$$, $$\href{../syntax/values.html#syntax-int}{\def\mathdef2200#1{{\mathit{i}#1}}\mathdef2200{\mathit{8}}}$$, $$\href{../syntax/values.html#syntax-int}{\def\mathdef2201#1{{\mathit{i}#1}}\mathdef2201{\mathit{16}}}$$, $$\href{../syntax/values.html#syntax-int}{\def\mathdef2202#1{{\mathit{i}#1}}\mathdef2202{\mathit{32}}}$$, $$\href{../syntax/values.html#syntax-int}{\def\mathdef2203#1{{\mathit{i}#1}}\mathdef2203{\mathit{64}}}$$. However, other sizes occur as auxiliary constructions, e.g., in the definition of floating-point numbers.

### Conventions¶

• The meta variables $$m, n, i$$ range over integers.
• Numbers may be denoted by simple arithmetics, as in the grammar above. In order to distinguish arithmetics like $$2^N$$ from sequences like $$(1)^N$$, the latter is distinguished with parentheses.

## Floating-Point¶

Floating-point data represents 32 or 64 bit values that correspond to the respective binary formats of the IEEE 754-2008 standard (Section 3.3).

Every value has a sign and a magnitude. Magnitudes can either be expressed as normal numbers of the form $$m_0.m_1m_2\dots m_M \cdot2^e$$, where $$e$$ is the exponent and $$m$$ is the significand whose most signifcant bit $$m_0$$ is $$1$$, or as a subnormal number where the exponent is fixed to the smallest possible value and $$m_0$$ is $$0$$; among the subnormals are positive and negative zero values. Since the significands are binary values, normals are represented in the form $$(1 + m\cdot 2^{-M}) \cdot 2^e$$, where $$M$$ is the bit width of $$m$$; similarly for subnormals.

Possible magnitudes also include the special values $$\infty$$ (infinity) and $$\href{../syntax/values.html#syntax-float}{\mathsf{nan}}$$ (NaN, not a number). NaN values have a payload that describes the mantissa bits in the underlying binary representation. No distinction is made between signalling and quiet NaNs.

$\begin{split}\begin{array}{llcll} \def\mathdef2186#1{{}}\mathdef2186{floating-point value} & \href{../syntax/values.html#syntax-float}{\def\mathdef2204#1{{\mathit{f}#1}}\mathdef2204{N}} &::=& {+} \href{../syntax/values.html#syntax-float}{\def\mathdef2205#1{{\mathit{f}#1}}\mathdef2205{\mathit{Nmag}}} ~|~ {-} \href{../syntax/values.html#syntax-float}{\def\mathdef2205#1{{\mathit{f}#1}}\mathdef2205{\mathit{Nmag}}} \\ \def\mathdef2186#1{{}}\mathdef2186{floating-point magnitude} & \href{../syntax/values.html#syntax-float}{\def\mathdef2205#1{{\mathit{f}#1}}\mathdef2205{\mathit{Nmag}}} &::=& (1 + \href{../syntax/values.html#syntax-int}{\def\mathdef2188#1{{\mathit{u}#1}}\mathdef2188{M}}\cdot 2^{-M}) \cdot 2^e & (\mathrel{\mbox{if}} -2^{E-1}+2 \leq e \leq 2^{E-1}-1) \\ &&|& (0 + \href{../syntax/values.html#syntax-int}{\def\mathdef2188#1{{\mathit{u}#1}}\mathdef2188{M}}\cdot 2^{-M}) \cdot 2^e & (\mathrel{\mbox{if}} e = -2^{E-1}+2) \\ &&|& \infty \\ &&|& \href{../syntax/values.html#syntax-float}{\mathsf{nan}}(n) & (\mathrel{\mbox{if}} 1 \leq n < 2^M) \\ \end{array}\end{split}$

where $$M = \href{../syntax/values.html#aux-significand}{\mathrm{signif}}(N)$$ and $$E = \href{../syntax/values.html#aux-exponent}{\mathrm{expon}}(N)$$ with

$\begin{split}\begin{array}{lclllllcl} \href{../syntax/values.html#aux-significand}{\mathrm{signif}}(32) &=& 23 &&&& \href{../syntax/values.html#aux-exponent}{\mathrm{expon}}(32) &=& 8 \\ \href{../syntax/values.html#aux-significand}{\mathrm{signif}}(64) &=& 52 &&&& \href{../syntax/values.html#aux-exponent}{\mathrm{expon}}(64) &=& 11 \\ \end{array}\end{split}$

A canonical NaN is a floating-point value $$\pm\href{../syntax/values.html#syntax-float}{\mathsf{nan}}(\href{../syntax/values.html#aux-canon}{\mathrm{canon}}_N)$$ where $$\href{../syntax/values.html#aux-canon}{\mathrm{canon}}_N$$ is a payload whose most significant bit is $$1$$ while all others are $$0$$:

$\href{../syntax/values.html#aux-canon}{\mathrm{canon}}_N = 2^{\href{../syntax/values.html#aux-significand}{\mathrm{signif}}(N)-1}$

An arithmetic NaN is a floating-point value $$\pm\href{../syntax/values.html#syntax-float}{\mathsf{nan}}(n)$$ with $$n \geq \href{../syntax/values.html#aux-canon}{\mathrm{canon}}_N$$, such that the most significant bit is $$1$$ while all others are arbitrary.

Note

In the abstract syntax, subnormals are distinguished by the leading 0 of the significand. The exponent of subnormals has the same value as the smallest possible exponent of a normal number. Only in the binary representation the exponent of a subnormal is encoded differently than the exponent of any normal number.

### Conventions¶

• The meta variable $$z$$ ranges over floating-point values where clear from context.

## Names¶

Names are sequences of scalar code points as defined by Unicode (Section 2.4).

$\begin{split}\begin{array}{llclll} \def\mathdef2186#1{{}}\mathdef2186{name} & \href{../syntax/values.html#syntax-name}{\mathit{name}} &::=& \href{../syntax/values.html#syntax-name}{\mathit{codepoint}}^\ast \qquad\qquad (\mathrel{\mbox{if}} |\href{../binary/values.html#binary-utf8}{\mathrm{utf8}}(\href{../syntax/values.html#syntax-name}{\mathit{codepoint}}^\ast)| < 2^{32}) \\ \def\mathdef2186#1{{}}\mathdef2186{code point} & \href{../syntax/values.html#syntax-name}{\mathit{codepoint}} &::=& \def\mathdef2245#1{\mathrm{U{+}#1}}\mathdef2245{00} ~|~ \dots ~|~ \def\mathdef2246#1{\mathrm{U{+}#1}}\mathdef2246{D7FF} ~|~ \def\mathdef2247#1{\mathrm{U{+}#1}}\mathdef2247{E000} ~|~ \dots ~|~ \def\mathdef2248#1{\mathrm{U{+}#1}}\mathdef2248{10FFFF} \\ \end{array}\end{split}$

Due to the limitations of the binary format, the length of a name is bounded by the length of its UTF-8 encoding.

### Convention¶

• Code points are sometimes used interchangeably with natural numbers $$n < 1114112$$.