What Java method takes an int and returns +1 or -1?

后端 未结 6 1161
無奈伤痛
無奈伤痛 2021-02-18 17:03

What Java method takes an int and returns +1 or -1? The criteria for this is whether or not the int is positive or negative. I looked through the docum

6条回答
  •  伪装坚强ぢ
    2021-02-18 17:48

    Math.signum(double i)

    Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero. Special Cases:

    • If the argument is NaN, then the result is NaN.
    • If the argument is positive zero or negative zero, then the result is the same as the argument.

    Parameters:

    • d - the floating-point value whose signum is to be returned

    Returns: The signum function of the argument

    Since: 1.5

提交回复
热议问题