# Unum (number format)

Unums (universal numbers) are a family of formats and arithmetic, similar to floating point, proposed by John L. Gustafson. They are designed as an alternative to the ubiquitous IEEE 754 floating-point standard and the latest version (known as posits) can be used as a drop-in replacement for programs which do not depend on specific features of IEEE 754.

## Type I Unum

The first version of unums, now officially known as Type I unum, was introduced in his book The End of Error as a superset of the IEEE-754 floating-point format. The two defining features of the Type I unum format are:

• a variable-width storage format for both the significand and exponent, and
• a u-bit, which determines whether the unum corresponds to an exact number (u = 0), or an interval between consecutive exact unums (u = 1). In this way, the unums cover the entire extended real number line [−∞,+∞].

For performing computation with the format, Gustafson proposes using interval arithmetic with a pair of unums, what he calls a ubound, providing the guarantee that the resulting interval contains the exact solution.

William M. Kahan and John L. Gustafson discussed unums at the Arith23 conference.

## Type II Unum

Type II Unums were introduced in late 2016 as a total redesign of Unums that broke IEEE-754 compatibility.

## Type III Unum (Posit & Valid)

In February 2017, Gustafson officially introduced Type III unums which consist of posits for fixed floating-point-like values and valids for interval arithmetic.

### Posit

Posits are a hardware-friendly version of unum where difficulties faced in the original type I unum due to its variable size are resolved. Similar size posits when compared to floats offer a bigger dynamic range and more fraction bits for accuracy. In an independent study, Lindstrom, Lloyd and Hittinger from Lawrence Livermore National Laboratory confirmed that posits out-perform floats in accuracy.[dubious ] Posits have particularly superior accuracy in the range near one, where most computations occur. This makes it very attractive to the current trend in deep learning to minimise the number of bits used. It potentially helps any applications to achieve a speedup by enabling the use of fewer bits (since it has more fraction bits for accuracy) thus reducing network and memory bandwidth, and power requirements, and bring us one step closer to exascale.

Posits have variable-sized index and mantissa bitfields, with the split being specified by a "regime" indicator. Gustafson claims that they offer better precision than standard floating-point numbers while taking up fewer bits.

Posits have a different format than IEEE 754 floats. They consist of four parts: sign, regime, exponent, and fraction (also known as significand/mantissa). For a n-bit posit, regime can be of length 2 to (n − 1). The format of the regime is such that it is a repetition of a same-sign bit and terminated by a different-sign bit.

Example 1:

Example 1 Example 2
000000000000001 1110

Example 1 shows a regime with 14 same-sign bits (bit 0), terminated by a different-sign bit (bit 1). As there are 14 same-sign bits, the runlength of the regime is 14.

Example 2 shows a regime with 3 same-sign bits (bit 1), terminated by a different-sign bit (bit 0). As there are 3 same-sign bits, the runlength of the regime is 3.

Sign, exponent and fraction bits are very similar to IEEE 754; however, posits may omit either or both of the exponent and fraction bits, leaving a posit that consists of only sign and regime bits. Example 3 shows the longest possible regime runlength for a 16-bit posit, where the regime terminating bit, exponent bit and fraction bits are beyond the length of the size of the posit. Example 4 illustrates the shortest possible runlength of 1 for a 16-bit posit with one exponent bit (bit value = 1) and 12 fraction bits (bit value = 100000000001).

Example 3: Regime runlength = 15 Example 4: Regime runlength = 1
0111111111111111 0101100000000001

The recommended posit sizes and corresponding exponent bits and quire sizes:

Posit size (bits) Number of exponent bits Quire size (bits)
8 0 32
16 1 128
32 2 512
64 3 2048

Note: 32-bit posit is expected to be sufficient to solve almost all classes of applications[citation needed].

#### Quire

Quire is one of the most useful features of posits. It is a special data type that will give posits "near-infinity" number of bits to accumulate dot products. It is based on the work of Ulrich W. Kulisch and Willard L. Miranker.

### Valid

Gustafson has not yet published a complete specification of valids, but they are described as a Type III Unum mode that bounds results in a given range.

## Implementations

There are several software and hardware implementations of posits from the community. The first ever complete parameterized posit arithmetic hardware generator was proposed in 2018.

Unum implementations have been explored in Julia. and MATLAB. A C++ version with support for any posit sizes combined with any number of exponent bits is also provided. A fast implementation in C, SoftPosit, provided by the NGA research team based on Berkeley SoftFloat is the latest addition to the available software implementations.

### SoftPosit

SoftPosit is a software implementation of posits that is based on Berkeley SoftFloat. This allows software comparison between posits and floats. It currently supports

• Subtract
• Multiply
• Divide
• Fused-dot-product (with quire)
• Square root
• Convert posit to signed and unsigned integer
• Convert signed and unsigned integer to posit
• Convert posit to another posit size
• Less than, equal, less than equal comparison
• Round to nearest integer

Helper functions

• convert double to posit
• convert posit to double
• cast unsigned integer to posit

for 16-bit posits with one exponent bit and 8-bit posit with zero exponent bit. Support for 32-bit posits and flexible type (2-32 bits with two exponent bits) is pending correctness verification. Currently it supports x86_64 systems. It has been tested on GNU gcc (SUSE Linux) 4.8.5 Apple LLVM version 9.1.0 (clang-902.0.39.2).

Examples:

```#include "softposit.h"

int main (int argc, char *argv[]){

posit8_t pA, pB, pZ;
pA = castP8(0xF2);
pB = castP8(0x23);

//To check answer by converting it to double
double dZ = convertP8ToDouble(pZ);
printf("dZ: %.15f\n", dZ);

//To print result in binary (warning: non-portable code)
uint8_t uiZ = castUI8(pZ);
printBinary((uint64_t*)&uiZ, 8);

return 0;
}
```

Fused dot product with quire16_t

```//Convert double to posit
posit16_t pA = convertDoubleToP16(1.02783203125 );
posit16_t pB = convertDoubleToP16(0.987060546875);
posit16_t pC = convertDoubleToP16(0.4998779296875);
posit16_t pD = convertDoubleToP16(0.8797607421875);

quire16_t qZ;

//Set quire to 0
qZ = q16_clr(qZ);

//accumulate products without roundings

//Convert back to posit
posit16_t pZ = q16_to_p16(qZ);

double dZ = convertP16ToDouble(pZ);
```

## Critique

William M. Kahan, the principal architect of IEEE 754-1985 criticizes type I unums on the following grounds (some are addressed in type II and type III standards):

• The description of unums sidesteps using calculus for solving physics problems.
• Unums can be expensive in terms of time and power consumption.
• Each computation in unum space is likely to change the bit length of the structure. This requires either unpacking them into a fixed-size space, or data allocation, deallocation, and garbage collection during unum operations, similar to the issues for dealing with variable-length records in mass storage.
• Unums provide only two kinds of numerical exception, quiet and signaling NaN (Not-a-Number).
• Unum computation may deliver overly loose bounds from the selection of an algebraically correct but numerically unstable algorithm.
• The costs and benefits of unum over short precision floating point for problems requiring low precision are not obvious.
• Solving differential equations and evaluating integrals with unums guarantee correct answers but may not be as fast as methods that usually work.