# Thread: Floating point operations in Java

1. Member Join Date
Feb 2017
Posts
1
Rep Power
0

## Floating point operations in Java

Hello!

Do you know any info (article, web pages, books and ...) about floating point operations on Java?

I want understand : how Java adding two double values (on machine level or binary level with rounding) ?

What happening on deep level (step by step)?

Example:

Java Code:
```public class GalToLitTable {

public static void main(String[] args) {

System.out.println(3.7854 + 3.7854);
System.out.println(7.5708 + 3.7854);

}

}```
After run:

7.5708
11.356200000000001

But it must have:

7.5708
11.3562

I want to understand (step by step) how java summing two floating point value (double type).

1. How java convert this values into binary?

2. What type and perfomance of this binary (sign, mantis, exponent, 80 or 64 bit length)?

3. How java rounding this binary?

4. How java summing two binary value?

5. How java rounding this binary sum?

6. How java convert binary sum to decimal sum and rounding binary\decimal value during this converting?

For exampe Q 1-3 I answer:

7.5708 = 0 10000000001 11100100100001111111110010111001001000111010001010 10 (Inexact, 1+11+52 bit = 64 bit)

3.7854 = 0 10000000000 11100100100001111111110010111001001000111010001010 10 (Inexact, 1+11+52 bit = 64 bit)

I'm right? This values 7.5708 and 3.7854 not exact convert to binary, how java rounding this binary (last bit) or java cuts this binary (without rounding)? Convert to binary are carried out in the FPU 80-bit (extended) representation? I correctly convert decimal to binary? Java has Round-Half-Even (Banker's Rounding), when convert decimal to binary?  Reply With Quote

2. ## Re: Floating point operations in Java  Reply With Quote

3. Moderator   Join Date
Apr 2009
Posts
13,541
Rep Power
28

## Re: Floating point operations in Java

Was there a problem with the answers you got over at Code Ranch?
https://coderanch.com/t/676362/java/...int-operations  Reply With Quote

4. ## Re: Floating point operations in Java

Goddammit.  Reply With Quote

5. ## Re: Floating point operations in Java Originally Posted by SurfMan Goddammit.
No cursing allowed here! Bring in the soft cushions and the comfy chair; this old lady needs a harsh punisment!

kind regards,

The Spanish Inquisition (typing on a bloody tablet *grmbl*)  Reply With Quote

6. Senior Member Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
15

## Re: Floating point operations in Java

And this isn't advanced Java. To some, it "might" be considered advanced computer science, but not Java.

Regards,
Jim  Reply With Quote

7. ## Re: Floating point operations in Java Originally Posted by jim829 And this isn't advanced Java. To some, it "might" be considered advanced computer science, but not Java.
You're rightl; I moved it to the New to Java section.

kind regards,

Jos  Reply With Quote

binary, floating point, floating point arithmetic, ieee, java 