floating point - double arithmetic and equality in Java -
There is an inequality here (at least for me). This routine is true:
double X = 11.0; Double y = 10.0; But this routine prints false prints:
double x = 1.1; Double y = 1.0; If (x-y == 0.1) {// print true} and {// print false} Anyone cares to explain what's going on here? I am looking for something with integer arithmetic for int s for float s. Apart from this, is there any other property (other than 10 ) in this property?
1.0 does not have accurate binary representation of 0.1.
Perhaps you are asking that 0.1 is not stored in the form of a Mantissa and an exponent of 10? But it's not how it works. This is not an exponent more than the decimal number but it is a binary number. So "Bar 10" is not a natural thing.
Sorry, maybe the last part is unclear. It is better to think of exponents as a shift of bits, any shift of bits transforms an infinite sequence such as 0.1 (decimal) into a finite.
Comments
Post a Comment