josdejong/mathjs

Functions do not recon with `config.number` when converting a string into a numeric type

オープン

#3,206 opened on 2024/05/29

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (1,314 件のフォーク)batch import
bughelp wanted

Repository metrics

Stars
 (15,065 個のスター)
PR merge metrics
 (PR metrics pending)

説明

It's a bit of an edge case, but for example:

math.config({number: 'BigNumber'})
math.add('2', '3')
// results in a number with value 5, but should be a BigNumber with value 5

The reason is that functions like add do not have a signature like add(string, string). Therefore, automatic conversion kicks in. The automatic conversion finds a conversion from string -> number that fits the bill and uses that, without reconing with the configured config.number. I'm not sure how a proper solution to fix this would look like, since the type conversions are static 🤔.

コントリビューターガイド