Skip to content
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

⚠️ Math_Min() and Math_Max() are doing the opposite of what you would expect #70

Open
Jay2k1 opened this issue Jun 28, 2022 · 2 comments

Comments

@Jay2k1
Copy link

Jay2k1 commented Jun 28, 2022

In smlib, Math_Min() returns the biggest of two given numbers and Math_Max() returns the smallest of two given numbers:

/**
* Sets the given value to min
* if the value is smaller than the given.
*
* @param value Value
* @param min Min Value used as lower border
* @return Correct value not lower than min
*/
stock any:Math_Min(any:value, any:min)
{
if (value < min) {
value = min;
}
return value;
}
/**
* Sets the given value to max
* if the value is greater than the given.
*
* @param value Value
* @param max Max Value used as upper border
* @return Correct value not upper than max
*/
stock any:Math_Max(any:value, any:max)
{
if (value > max) {
value = max;
}
return value;
}

In doing so, they are doing the exact opposite of what anyone who has ever used max and min functions in other languages will expect them to do.

In other programming/scripting languages, the max function returns the maximum value (i.e. the biggest) of a given set and min returns the minimum (the smallest) number of a given set.
I bet that everyone who scripts some SourcePawn and uses the functions provided here will be very confused about the results, then start debugging their code and at some point read the source code of the functions - and then be even more confused about why they are "inverted" and pull their hair out.

@peace-maker
Copy link
Member

Yes, it's too late to change that behavior now though. :( We could deprecate it and add some Math_Min2 stock which is gross.

@Jay2k1
Copy link
Author

Jay2k1 commented Jun 29, 2022

I agree to both of that, although I think deprecating them and finding a new naming scheme is preferable to leaving it as it is. Either way, maybe this issue will pop up on google for people who are looking for a min/max function in SP/SM and help reduce confusion...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants