Float operations in java

Source: Internet
Author: User

I. what are the points to note about floating-point operations? 1. in java, floating point operations do not handle exceptions. Therefore, no exceptions are thrown even if the divisor is 0. when the calculation result is an overflow (Infinity), the result is Infinity. When the underflow occurs, the result is 0. If the result is mathematical, It is undefined, the result is NaN (not a number); 3. the result of all NaN-related operations is always NaN; 4. because NaN is unordered, when comparing NaN with NaN, the result is always false. II. example: public class floattest {public static void main (String args []) {double num = 1.0E200; System. out. println (num * num); double num2 = 1.0E-323; System. out. println (num2/10.0); System. out. println (1.0/0.0); System. out. println (-1.0/0.0); double numNan = 0.0/0.0; System. out. println (numNan); System. out. println (numNan> 0) ;}} 3. test result:/* Infinity0.0Infinity-InfinityNaN false */

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.