mathjs
mathjs copied to clipboard
add exactConstantFunctions to simplify, to tell mathjs to not convert constant functions into decimals
I had a case which ended up with a constant log in it, which I wanted to stay as an exact value and not a decimal. I've added an option, exactConstantFunctions, so when passed as true it'll not evaluate functions. So while by default simplify("3 + sin(4)") will give you back 2.2431975046920716, with { exactConstantFunctions: true } passed you'll get back 3 + sin(4). It'll still add, multiply, apply exponents to raw constants, just not call most functions (especially not desirable for me for the trig/log functions to be called).
I like that idea, thanks!
Some thoughts:
- I found the name
exactConstantFunctionsconfusing at first. Maybe just name itexactFunctions, similar toexactFractions? - Can you describe the new option in the comments in function
simplify(alongside the description ofexactFractions)? That will end up in the documentation on the website here. - Not for this PR, but I can imagine that in the future we could expand on it, like only replacing
sinwhen it's result is a nice, round value, likesin(0),sin(pi),sqrt(16).