Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By JosAH

Thread: Floating point operations in Java

  1. #1
    sasvak is offline Member
    Join Date
    Feb 2017
    Posts
    1
    Rep Power
    0

    Post 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?

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: Floating point operations in Java

    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default 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
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: Floating point operations in Java

    Goddammit.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Floating point operations in Java

    Quote Originally Posted by SurfMan View Post
    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*)
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default 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
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Floating point operations in Java

    Quote Originally Posted by jim829 View Post
    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
    DarrylBurke likes this.
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Floating point inaccuracy
    By Aga in forum Advanced Java
    Replies: 6
    Last Post: 02-04-2011, 05:07 AM
  2. if it is floating point number
    By Stephen Douglas in forum New To Java
    Replies: 26
    Last Post: 07-06-2010, 09:17 AM
  3. Replies: 1
    Last Post: 07-14-2009, 07:04 PM
  4. java floating point comparison
    By sardare in forum Advanced Java
    Replies: 6
    Last Post: 03-03-2009, 04:11 PM
  5. number of floating point
    By mohammad8065 in forum Advanced Java
    Replies: 5
    Last Post: 12-28-2008, 09:41 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •