Math. Abs Method

Source: Internet
Author: User

 
Public static intABS(Int)
Return IntThe absolute value of the value. If the parameter is not negative, this parameter is returned. If the parameter is a negative number, the opposite number of this parameter is returned.

Note: If the parameter is equalInteger. min_value(That is, the minimum negative value that can be expressed)IntValue), the result is the same as the value and is negative.

 
Public static longABS(Long)
Return LongThe absolute value of the value. If the parameter is not negative, this parameter is returned. If the parameter is a negative number, the opposite number of this parameter is returned.

Note: If the parameter is equalLong. min_value(That is, the minimum negative value that can be expressed)LongValue), the result is the same as the value and is negative.

 
Public static floatABS(Float)
Return FloatThe absolute value of the value. If the parameter is not negative, this parameter is returned. If the parameter is a negative number, the opposite number of this parameter is returned. In special cases:

  • If the parameter is positive zero or negative zero, the result is positive zero.
  • If the parameter is infinite, the result is positive infinity.
  • If the parameter is Nan, the result is Nan.

In other words, the result is equal to the value of the following expression:

Float. intbitstofloat (0x7fffffff & float. floattointbits ())

 
Public static doubleABS(Double)
Return DoubleThe absolute value of the value. If the parameter is not negative, this parameter is returned. If the parameter is a negative number, the opposite number of this parameter is returned. In special cases:

  • If the parameter is positive zero or negative zero, the result is positive zero.
  • If the parameter is infinite, the result is positive infinity.
  • If the parameter is Nan, the result is Nan.

In other words, the result is equal to the value of the following expression:

Double. longbitstodouble (double. doubletolongbits (a) <1) >>> 1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.