Skip to content

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

@Jay2k1

Description

@Jay2k1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions