Skip to content

Latest commit

 

History

History
68 lines (56 loc) · 6.61 KB

RELATED.md

File metadata and controls

68 lines (56 loc) · 6.61 KB

History and related work

The need for accurately representing decimal quantities is not new or unique to our current circumstances. That's why there are a number of popular JS ecosystem libraries for decimal, why many other programming languages, databases and standards have built-in data types for this purpose, and why TC39 has been considering adding Decimal for at least 12 years.

Related JS ecosystem libraries

JavaScript programmers are using decimal data types today with various ecosystem libraries. The most popular three on npm are each by MikeMcl:

These packages have some interesting differences, but there are also many similarities:

  • APIs are based on JavaScript objects and method calls
  • Rounding modes and precision limits are settings in the constructor
  • Inherently rounding operations like sqrt, exponentiation, division are supported

The initial proposal in this document suggests some differences, described above.

We plan to investigate the experiences and feedback developers have had with these and other existing JavaScript libraries so that we can learn from them in the design of BigDecimal. The discussion continues in #22.

Related features in other systems

Due to the overwhelming evidence listed above that decimal is an important data type in programming, many different programming languages, databases and standards include decimal, rationals, or similar features. Below is a partial listing, with a summary of the semantics in each.

  • Standards
    • IEEE 754-2008 and later: 32-bit, 64-bit and 128-bit decimal; see explanation (recommends against using 32-bit decimal)
    • (plus many of the below are standardized)
  • Programming languages
    • Fixed-size decimals:
      • C: 32, 64 and 128-bit IEE 754 decimal types, with a global settings object. Still a proposal, but has a GCC implementation.
      • C++: Early proposal work in progress, to be based on IEEE 64 and 128-bit decimal. Still a proposal, but has a GCC implementation.
      • C#/.NET: Custom 128-bit decimal semantics with slightly different sizes for the mantissa vs exponent compared to IEEE.
      • Swift/Obj-C: Yet another custom semantics for fixed-bit-size floating point decimal.
    • Global settings for setting decimal precision
      • Python: Decimal with global settings to set precision.
    • Rationals
      • Perl6: Literals like 1.5 are Rat instances!
      • Common Lisp: Ratios live alongside floats; no decimal data type
      • Scheme: Analogous to Common Lisp, with different names for types (Racket is similar)
      • Ruby: Rational class alongside BigDecimal.
    • Arbitrary-precision decimals (this proposal)
      • Ruby: Arbitrary-precision Decimal, alongside Rational.
      • PHP: A set of functions to bind to bc for mathematical calculations. An alternative community-driven Decimal library is also available.
      • Java: Arbitrary-precision decimal based on objects and methods. Requires rounding modes and precision parameters for operations like division
  • Databases
  • Libraries
    • Intel C inteldfp: IEEE decimal
    • Bloomberg C++ bdldfp: IEEE decimal
    • IBM C decnumber: Configurable context with precision, rounding mode
    • Rust crates [1] [2]
  • Hardware (all implementing IEEE decimal)

History of discussion of decimal in TC39

Decimal has been under discussion in TC39 for a very long time, with proposals and feedback from many people including Sam Ruby, Mike Cowlishaw, Brendan Eich, Waldemar Horwat, Maciej Stachowiak, Dave Herman and Mark Miller.

  • A new decimal type was long planned for ES4, see Proposed ECMAScript 4th Edition – Language Overview
  • In the following ES3.1/ES5 effort, discussions about a decimal type continued on es-discuss, e.g., [1] [2]
  • Decimal was discussed at length in the development of ES6. It was eventually rolled into the broader typed objects/value types effort, which didn't make it into ES6, but is being incrementally developed now (see the below section about relationship to other TC39 proposals).