-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variadic functions for math
and tinyexpr rewrite.
#8644
Comments
Sure, sounds cool. How's the performance?
I think the only ones where that really makes sense are minimum and maximum, I don't think e.g. "log2" makes sense as a variadic function. There are possibilities here for optional arguments, e.g.
I'm not sure what you mean here. Things like division by zero? E.g. the function itself makes no sense to apply? |
Running the math benchmark shows a small speedup on my machine: 1.02 ± 0.01 times faster. Otherwise I haven't noticed any significant difference, nor would I expect to see one. I also ran the benchmark with few other expressions (using other operators and including function calls) with very similar results. With enough arguments (1000 +) the variadic functions e.g.
Do you think these are better to have separately, or changing the current
I was mostly thinking if the function requires at least some number of arguments, or has other limitations on the number of arguments. I agree the optional arguments might not be a good choice, but that would be an example of variadic function with extra arity requirements. |
Seems to me min and max without arguments could be like, the numeric minimum and maximum we can work with. Parens are optional anyhow - it'd feel like using a constant like pi? |
I do not see anyone querying for these, ever. If you do If this was something we wanted to have a way to display, I wouldn't even make it a constant in math. I'd make it an option - |
Yeah good point the mode of a disappeared argument resulting in something like INT_MAX by surprise might be a good enough reason to scuttle that. |
The one case I can imagine, is when you get the The limit isn't too obvious either |
This looks great! Variadic min/max and direct evaluation is very welcome. I especially like how the direct evaluation cleans up the memory management. I look forwards to merging this after 3.4.0 release. Please remove the |
That's understandable, removed it!
Cool, I wasn't aware of this. Added it (and some required |
Hi,
I've played around with the tinyexpr included in fish. I rewrote it here using more of c++ (than the very c-like code), and added variadic function support.
Changes:
minimum
andmaximum
)std::unordered_map
, so that alphabetical order is no longer required and the lookup is simplerWould this be of interest to you? If you'd like, I could open a pull request.
The current implementation of variadic functions doesn't support reporting errors from the functions, which might be good to have at some point. Also a question: Should some existing functions be made variadic, or should some variadic functions be added?
The text was updated successfully, but these errors were encountered: