Skip to content

Unit.equals throws an exception when using Fractions, whilst math.equal works as expected  #2918

@josdejong

Description

@josdejong

From #2915

I parameterize the mathjs like this :

const config: math.ConfigOptions = {
  number: "Fraction",
};
const math: MathJsStatic = create(all, config);

I create units like this :

math.createUnit('rotation', {definition: '360 deg', aliases: ['tour','tr']})

I try to do this :

const a = math.unit(360, "deg");
const b = math.unit(1, "rotation");
expect(b.equals(a));

And i have this error :

TypeError: Cannot implicitly convert a number to a Fraction when there will be a loss of precision (value: 6.283185307179586). Use function fraction(x) to convert to Fraction.

Any idee ??!
tks.

Apparently the method Unit.equals internally tries to convert the Fraction into a number. For some reason the function math.equal(a, b) does work as expected whereas b.equals(a) throws this error.

It sounds like this is a solvable bug. Anyone able to look into this? Help would be welcome.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions