josdejong/mathjs

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

开放

#3,206 创建于 2024年5月29日

 (0 条评论) (0 个反应) (0 位负责人)JavaScript (1,314 个派生)batch import
bughelp wanted

仓库指标

星标
 (15,065 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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 🤔.

贡献者指南