josdejong/mathjs

math.rationalize silently ignores imaginary numbers

Open

#2,375 建立於 2022年1月6日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)JavaScript (1,298 fork)batch import
bughelp wanted

倉庫指標

Star
 (13,832 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Currently, math.rationalize seems to ignore imaginary numbers:

// math.js version 9.5.1

// complex coefficient a = (2 + complex(3, 4))
let a = new math.OperatorNode("+", "add", [new math.ConstantNode(2), new math.ConstantNode(math.complex(3, 4))]);
console.log(a.evaluate()); // {re: 5, im: 4}

// polynomial a * x
let poly = new math.OperatorNode("*", "multiply", [a, new math.SymbolNode("x")]);

let coefficients = math.rationalize(poly, true).coefficients;
console.log(coefficients); // [0, 5]

I would expect coefficients to be [0, 5+4i] or for rationalize to throw an error.

貢獻者指南