Reputation: 58
I've been looking at some source codes to better understand the core of this game we use, and to program more reliable and faster plugins. Then I found this curious piece of code...
public void setMaxH(double amount) {
super.setMaxH(amount);
this.h = Math.min(this.h, this.h);
...
}
I can not fathom any reason for this last line to exist in the code, using Math.min, assigning the results to the very same variable used in both parameters to min... does it do anything at all?
Upvotes: 1
Views: 97
Reputation: 920
public static double min(double a, double b)
: "Returns the smaller of two double values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero."
Then, probably an error in the code refactoring. Examine well the function and try to understand if the intention of the programmer could be:
this.h = Math.min(this.h, amount);
would be the only sensible thing.
Upvotes: 5