Floating Point Representation (Question)

Discussion in 'Java' started by Stefan Ram, Dec 26, 2012.

  1. Stefan Ram

    Stefan Ram Guest

    AFAIK 0.1 in hex is 0x1.(9)ap-4, where »(9)« means an
    infinite sequence of »9«. However, Java only stores a
    finite number of 9s:

    printf( "%a%n", 0.1 )
    0x1.999999999999ap-4

    . So, since something /positive/ is missing, Javas
    representation of 0.1 should be /smaller/ than 0.1, but

    println( new java.math.BigDecimal( 0.1 ))
    0.1000000000000000055511151231257827021181583404541015625

    shows me a value that is /greater/ than 0.1?

    Removing more 9s makes the value even larger!

    println( new java.math.BigDecimal( 0x1.999999999999ap-4 ));
    0.1000000000000000055511151231257827021181583404541015625

    println( new java.math.BigDecimal( 0x1.9ap-4 ))
    0.10009765625
    Stefan Ram, Dec 26, 2012
    #1
    1. Advertising

  2. Stefan Ram

    Stefan Ram Guest

    Patricia Shanahan <> writes:
    >The "a" in "0x1.999999999999ap-4" is the last digit of the hex fraction.


    For some reason, I did not understand this, but thought »ap«
    was a unit marking the start of the exponent (already
    wondering »Why /two/ letters?«). Now that you have told me
    this, I understand it all - thank you!
    Stefan Ram, Dec 26, 2012
    #2
    1. Advertising

  3. Stefan Ram

    Eric Sosman Guest

    On 12/26/2012 11:22 AM, Stefan Ram wrote:
    > AFAIK 0.1 in hex is 0x1.(9)ap-4, where »(9)« means an
    > infinite sequence of »9«.


    What's the "a" for? ;-)

    > However, Java only stores a
    > finite number of 9s:
    >
    > printf( "%a%n", 0.1 )
    > 0x1.999999999999ap-4


    "One, point, twelve nines, A, exponent." See the "A?"

    --
    Eric Sosman
    d
    Eric Sosman, Dec 26, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    407
    Patricia Shanahan
    Jun 23, 2006
  2. Replies:
    10
    Views:
    2,818
    Torsten Bronger
    Dec 15, 2005
  3. Dilip
    Replies:
    8
    Views:
    457
    Ernie Wright
    Dec 28, 2006
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,298
    Saraswati lakki
    Jan 6, 2012
  5. Alex DeCaria
    Replies:
    15
    Views:
    200
    Josh Cheek
    Apr 14, 2010
Loading...

Share This Page