Java floating point arithmetic

Original link: https://www.lifengdi.com/archives/course/java/3909

Compared with integer operations, floating-point number operations can only perform numerical calculations such as addition, subtraction, multiplication and division, and cannot perform bit operations and shift operations. In computers, although floating-point numbers have a large range of representation, floating-point numbers have a very important feature, that is, floating-point numbers often cannot be accurately represented. For example: The floating-point number 0.1 cannot be accurately represented in the computer, because the conversion of decimal 0.1 into binary is an infinitely recurring decimal. Obviously, no matter whether float or double is used, only an approximate value of 0.1 can be stored. However, the floating-point number 0.5 can be represented exactly. Because floating-point numbers are often inexactly represented, floating-point arithmetic can generate errors: // Floating-point arithmetic errors public class Main { pu […]

This article is reproduced from: https://www.lifengdi.com/archives/course/java/3909
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment