-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
[Feature request] More built-in math functions (MIN, MAX, ABS/SGN) #723
Comments
Since there is a user-defined alternative, why make them built-in? If they're found to be used really often and to be performance hits, then we'll consider making them built-in. (We should suggest in the docs to only define them if not already defined, for future-proofing)
While we're at this, how should function names be standardized? |
There will be a user-defined alternative eventually, assuming varargs, recursion, overloading, and the ternary operator are all implemented. Until then, you still have to do For standardized function names, so far it seems like rgbasm has gone with the typical or straightforward names for built-in functions ( |
All the built-in functions so far are for operations that would be difficult or impossible to do with the available integer operators; in particular the fixed-point math and trigonometry functions. There are a lot of useful small functions on integers, and it's probably simplest to leave those for user-defined (once that's possible). |
MIN(args...)
= the minimum one of args (must be at least one)MAX(args...)
= the maximum one of args (must be at least one)SGN(N)
= 1, 0, or -1, depending on the sign of N(this is equivalent toABS(N)
= the absolute value of NN * SGN(N)
)I frequently write conditionals like these:
In theory, user-defined functions will eventually allow these. However, built-in functions would not have to wait for that, and would reserve an obvious name for them. Even after user-defined functions are implemented,
MIN
andMAX
would be difficult to define like this without vararg, recursion, overloading, and ternary support.The text was updated successfully, but these errors were encountered: