Formatting complex numbers #2844
Replies: 1 comment 5 replies
-
Thanks for bringing this up. The code is indeed rounding re or im to the largest order of magnitude: mathjs/src/type/complex/Complex.js Lines 59 to 69 in 76c8c62 This was done because with complex calculations, you almost always have round-off errors involved, and it is really hard to read complex numbers when you have to check against re or im being "about zero", values that would be formatted like It makes sense to me to not apply that rounding to zero when using notation |
Beta Was this translation helpful? Give feedback.
-
See https://stackblitz.com/edit/js-xt7ffy?devToolsHeight=33&file=index.js
It seems like formatting complex numbers in exponential mode is based on the magnitude, sqrt(re^2+im^2). This gives both real and imaginary parts if they are of similar magnitudes, otherwise one part would be hidden, such that
'1.23456789+.0023456789i'
gives1.2e+0
.But the major motivation to use
exponential
format is to reveal significant figures. Such a behaviour does not meet this purpose.Wondering if there are any recommendations? Or if formatting each part independently can be submitted as a feature request?
Beta Was this translation helpful? Give feedback.
All reactions