Skip to content

NaN and Infinity not allowed #148

@vallsv

Description

@vallsv

Hi,

While doing some tests, i found out that it is not possible to create quantities with NaN or Infinity.

I would like to know if it's an expected behavior.

import Qty from "js-quantities";

try {
  new Qty(Infinity, 'mm');
} catch (e) {
  console.log("Oupsi", e.message);
}

try {
  new Qty(NaN, 'mm');
} catch (e) {
  console.log("Oupsi...", e.message);
}

// Oupsi... Only number accepted as initialization value when units are explicitly provided

I am working on a system with python server. So i try to see if i can transpose everything on both sides.
For example, here is with Pint.

>>> import pint
>>> pint.Quantity(float('nan'), 'mm') / pint.Quantity(float('nan'), 's')
<Quantity(nan, 'millimeter / second')>

I was guessing javascript was already propagating NaN and Infinity properly inside js-quantities.
What do you think?

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