DEC64 Numbers

Overview

DEC64 is a numeric representation for targets that want decimal arithmetic. Each build selects a value representation that suits its target — see Target Profiles — and DEC64 is the decimal option.

DEC64 represents numbers as coefficient * 10^exponent in a 64-bit word, so values that are exact in decimal stay exact: under DEC64, 0.1 + 0.2 is 0.3. It was designed by Douglas Crockford as a general-purpose number type suitable for both business and scientific computation.

Values leaving a runtime are encoded as nota, which carries numbers as a decimal coefficient and exponent. Two runtimes that selected different numeric representations therefore exchange numbers through a common decimal form.

Format

A DEC64 number is a 64-bit value:

[coefficient: 56 bits][exponent: 8 bits]
  • Coefficient — a 56-bit signed integer (two’s complement)
  • Exponent — an 8-bit signed integer (range: -127 to 127)

The value of a DEC64 number is: coefficient * 10^exponent

Examples

ValueCoefficientExponentHex
0000000000000000000
1100000000000000100
3.14159314159-5000000004CB2FFFB
-1-10FFFFFFFFFFFFFF00
1000000160000000000000106

Special Values

Null

The exponent 0x80 (-128) indicates null, and null is the format’s one special value. Operations whose result is undefined — division by zero among them — return null.

coefficient: any, exponent: 0x80  →  null

Arithmetic Properties

  • Exact decimals: All decimal fractions with up to 17 significant digits are represented exactly
  • No rounding: 0.1 + 0.2 == 0.3 is true
  • Integer range: Exact integers up to 2^55 (about 3.6 * 10^16)
  • Normalized on demand: The runtime normalizes coefficients to remove trailing zeros when needed for comparison

Comparison with IEEE 754

PropertyDEC64IEEE 754 double
Decimal fractionsExactApproximate
Significant digits~17~15-16
Special valuesnull onlyNaN, ±Infinity, -0
Rounding errorsNone (decimal)Common
Financial arithmeticCorrectRequires libraries
Scientific range±10^127±10^308

DEC64 trades a smaller exponent range for exact decimal arithmetic. Most applications never need exponents beyond ±127.