abhas Active member
| Subject: SOME THINGS YOU SHOULD KNOW ABOUT FLOATING-POINT ARITHMETIC Sun Jul 20, 2008 8:05 pm | |
| public class Fp1 { public static void main(String[] args) { double val1 = 0.1; double val2 = 0.3; double d = val1 + val1 + val1; if (d != val2) { System.out.println("d != val2"); } System.out.println( "d - val2 = " + (d - val2)); } } Everyone knows that: 0.1 + 0.1 + 0.1 == 0.3 at least in mathematical terms. But when you run the Fp1 program, you discover that this equality no longer holds. The program output looks like this: d != val2 d - val2 = 5.551115123125783E-17 This result seems to indicate that 0.1 + 0.1 + 0.1 differs from 0.3 by about 5.55e-17. What is wrong here? The problem is that IEEE 754 floating-point arithmetic, as found in the Java language, doesn't use decimals to represent numbers. Instead it uses binary fractions and exponents. |
|
kanika rajput Active member
| Subject: Re: SOME THINGS YOU SHOULD KNOW ABOUT FLOATING-POINT ARITHMETIC Thu Jan 29, 2009 11:41 am | |
| can plzzz expain me bollean data type plzz!!!1 |
|