Skip to content

More performant constructor #245

@LajosCseppento

Description

@LajosCseppento

Thank you for sharing this library!

In my current project I need to convert Decimal128 (BSON/MongoDB) values to Decimal.js on big data sets (server side). The simple Decimal(decimal128.toString()) solution is a bottleneck and I noticed I could do around 2-4x faster if I did not involve strings in the process.

I extracted the significand and the exponent from the Decimal128 (it is quite fast) and I would like to construct a Decimal.js object from these. Currently I do this to construct the object:

  const decimal = Decimal(0);
  decimal.d = digits;
  decimal.e = exponent;
  decimal.s = isNegative ? -1 : 1;
  return decimal;

I was wondering would it be possible to have an "advanced" constructor which can either take a significand digits/significand in 32-bit chunks + exponent (and then convert it to the internal format) or to expose the internal format?

By the way, do you happen to have some docs/spec on the internal format? (A bit more detailed than the public docs.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions