-
Notifications
You must be signed in to change notification settings - Fork 89
Description
In smlib, Math_Min() returns the biggest of two given numbers and Math_Max() returns the smallest of two given numbers:
smlib/scripting/include/smlib/math.inc
Lines 53 to 85 in aad2c8e
| /** | |
| * 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.
- PHP: max — Find highest value
- JS: The Math.max() function returns the largest of the zero or more numbers given as input parameters
- C++: fmax: Returns the larger of two floating point arguments
- Python: max - Return the largest item in an iterable or the largest of two or more arguments.
- Go: Max returns the larger of x or y.
- Perl: max - Returns the entry in the list with the highest numerical value.