ConstantNode - intended values. #2823
-
Hi Jos, Another quick question about the existing node types and the philosophy / intention behind them; I figured it made more sense to ask here, so that the information is recorded for others, as well.^1 In the docs, it says the type of
However, 1) in the same file, the constructor is declared as:
(where, if I'm not mistaken,
it returns:
i.e. The work I'm currently doing would be greatly simplified by having a single node type for numbers (i.e. for both negative and non-negative values); is there any reason you'd recommend against such a simplification? Specifically, I wondered if, as with Operator and Function nodes, there was a reason for returning negative constants as unary minus nodes as opposed to constant nodes? Thanks in advance for your time and help. Hope this finds you well! All the best, Jacob 1: If it would be helpful to record your answer to my previous query about Operator vs. Function nodes here in the discussions, please let me know and I'll add it 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Beta Was this translation helpful? Give feedback.
the typescript typing of the ConstantNode constructor may well be too restrictive, and if mathjs is indeed creating ConstantNode objects with, say, string values, then I don't see any reason you shouldn't submit a PR widening the typescript type and adding tests for the wider type.
The question of the proper parse for the string
-2
is more subtle: is that the unary minus operator applied to the constant two or the constant "negative two"? I gather mathjs currently prefers the former. That's one of those changes that it's hard to know the ramifications of: maybe someone else is depending on all-
symbols being captured as operator nodes... so my recommendation would be to just run a cu…