Skip to content

How should decimal interact with measure? #185

Open
@jessealama

Description

@jessealama

The measure proposal allows JS programmers to represent numbers with a dimension (unit). It adds new capabilities to JS by exposing CLDR unit data.

As currently envisioned, a measure object contains

  1. an underlying number value (e.g. a JS Number)
  2. a unit
  3. a precision

Example: new Measure(1.3, "gram", 2) is intended to be a datum that corresponds to 1.3 grams, with a precision of 1/102 (i.e., the true mathematical value is in the interval [1.29, 1.31]).

(Invocations of the measure API should be understood as suggestions to stimulate discussion; as of writing, measure has only recently reached stage 1 and its experimental API is very much subject to change.)

As it stands, measure is a nice companion to decimal. Fixing the unit (and especially if the unit is undefined or explicitly dimensionless), and allowing the other two parameters to vary, we have a space of measure instances that fairly closely tracks what IEEE 754 Decimal is intended to capture, namely a decimal number (understood as a mathematical value) plus a quantum.

IEEE 754 defines rules of arithmetic and other mathematical operations, and specifies, in particular, the quanta of the results of mathematical operations from the quanta of the operations arguments. As it stands, measure does not really support arithmetic on the underlying numeric values; measure's notion of arithmetic is focused on units (e.g. convering "meter" and 2 to "meter squared").

Given the conceptual overlap between measure and what we have called non-normalized, or full Decimal128, some questions arise:

  • Should the measure proposal be included, at least in part, in the decimal proposal?
  • Does measure give us all, or enough, of what we want out of full Decimal128?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions