Пользователь
I'm not super familiar with Java, but in other languages I would add 0 to the input value, since -0 + 0 = +0. public static double abs(double value) { return (value + 0) < 0 ? -value : value; }
public static double abs(double value) { return (value + 0) < 0 ? -value : value; }
As an aside, re-interpreting a double as its integer representation is not free on all platforms.
I'm not super familiar with Java, but in other languages I would add 0 to the input value, since -0 + 0 = +0.
public static double abs(double value) { return (value + 0) < 0 ? -value : value; }
As an aside, re-interpreting a double as its integer representation is not free on all platforms.