Skip to content

Support operations with string+bignumber and string+fraction #789

@josdejong

Description

@josdejong

Adding a string to a number or boolean works:

math.add("2", 4)     // 6
math.add("2", true)  // 3

Whilst trying to add a string and a bignumber, fraction, or complex number fails:

math.add("2", math.bignumber(4))    // TypeError: Unexpected type of argument in function add (expected: number, actual: BigNumber, index: 1)
math.add("2", math.fraction(2, 4))  // TypeError: Unexpected type of argument in function add (expected: number, actual: Fraction, index: 1)
math.add("2", math.complex(2, 0))   // TypeError: Unexpected type of argument in function add (expected: number, actual: Complex, index: 1)

Reason is that there are a few conversion definitions missing: string to bignumber, string to fraction, string to complex, and maybe a few more. See code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions