Software:DEC64

From HandWiki
DEC64
Dec64.png
Developer(s)Douglas Crockford
Initial release2014
Repositoryhttps://github.com/douglascrockford/DEC64/
Written inAssembler, C
PlatformPC
Typedata format
LicensePublic domain
Websitehttp://dec64.com/

DEC64 is a decimal floating point format proposed by Douglas Crockford for storing integer and decimal numbers in a computer. Its aim is to sidestep the rounding errors common to the widespread IEEE 754 format. Crockford released in 2014 a reference implementation as public domain software on GitHub.[1]

Example

In Javascript (which implements IEEE 754), the expression 0.1 + 0.2 will have a result which is not exactly 0.3:

console.log(0.1 + 0.2)
/* 0.30000000000000004 */

console.log(0.1 + 0.2 == 0.3)
/* false */

DEC64 attempts to solve such cases while maintaining desirable properties of IEEE 754.

Representation

DEC64 represents numbers as 64 bit values composed of two parts:

  • the least-significant 8 bits contain the exponent;
  • the remaining 56 bits contain the coefficient.

Both parts are two's complements, such that the exponent will be between -127 and 127, and the coefficient will be between -36028797018963968 and 36028797018963967.

The value of a number is given by:

value = coefficient * 10exponent

There are 255 possible representations of zero. They are all considered to be equal.

There is a special value called NaN ("not a number") that has a coefficient of 0 and an exponent of -128. The result of division by zero is nan. nan is also the result of operations that produce results that are too large to be represented. nan is equal to itself.

When an arithmetic operation has an input with an exponent of -128, the result will be nan.

Integers can have an exponent of 0 as long as the coefficient is less than 36 quadrillion. One interesting property of DEC64 is that an integer number can be easily converted to DEC64 simply by shifting it left 8 bits.

Reception

The proposal saw no widespread response or implementation up to now. Some argue, the benefits are too small to be worthwhile over wide-spread used floating-point formats.[2]

See also

External links

References

  1. DEC64 reference implementation on github.com
  2. A silly review of dec64 by Jens Nockert on aventine.se (March 09, 2014)