When to return a "simpler" type than a function was invoked with? #3398
Replies: 2 comments
-
|
As a first attempt at principles, I think the discussions in #3374 support the following:
|
Beta Was this translation helpful? Give feedback.
-
|
On point 4, I definitely think that some type simplifications should be made: However, at the other end of the spectrum in which every operation does simplification checks, I worry about performance (the computational cost of all of the checks on every intermediate result) and ability to chain operations (knowing what version of an operation to execute on the result of previous computation). The latter issue is particularly acute in prototypes like For example, for any Complex type for So what's clear to me from these prototypes is that at least there needs to be a way to obtain implementations of basic operations that will not do type simplification, even when a global |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The discussion in #3374 outlining how mathjs will uniformize when mathjs returns different types with config.predictable = false and how it will behave in out-of-domain cases with config.predictable = true has explicitly opened the door to functions returning a "simpler" type when it happens to be exact, e.g.
floorof a BigNumber could be a bigint, if that's useful. It turns out that a couple of functions that typically return a complex number already return a plain number when the imaginary part of the result happens to be zero, and certainly those examples should be regularized and that principle, assuming it's deemed valuable, should be extended to other functions. This discussion is dedicated to determining other cases, if any, when such "type simplification" could and should occur.Beta Was this translation helpful? Give feedback.
All reactions