Skip to content

Lacking precision necessary for required comparisons #132

@kyrofa

Description

@kyrofa

This test passes

it("should compare properly", function() {
  var galQty = Qty("1 gal");
  var qtQty = Qty("4 qt");
  expect(galQty.eq(qtQty)).toBeTrue();
});

However, for more complex units it fails:

it("should compare properly", function() {
  var galQty = Qty("1 gal/acre");
  var qtQty = Qty("4 qt/acre");
  expect(galQty.eq(qtQty)).toBeTrue();
});

This is due to a lack of precision. If you take a look at baseScalar in the latter test, you'll see that they're VERY close down to twenty decimal places or so, but then differ. These types of problems are generally solved by using a library like big.js, but that does mean taking on a dependency. How do you feel about that? A less-great option would be to check how close the values are in compareTo and claim that they're equal if they're "close enough" (this is how I'm working around this issue locally for now). Is there another more preferred way to solve this problem? Happy to do the legwork, just need to know what will be approved.

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