Results 1 to 3 of 3
  1. #1
    Adde1986 is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default Code counting error

    delete this thread please!
    Last edited by Adde1986; 03-18-2009 at 02:21 AM. Reason: got the answer

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    The value of x is incrementing by 0.1.

    x is a double and the Java language insists that the values and the operations on them follow the IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Standard 754-1985.

    What's most significant in the code you posted is that double values only have a finite amount of precision (so they can be used by a computer with a finite amount of memory and time at its disposal). Because of that, the result of incrementing x by y will not, in general, be the same whether we interpret x and y as (finite precision) Java doubles or (infinite precision) mathematical values.

    If the result you observe is not what you want, then incrementing 0 by 0.1 is not appropriate. What you want, in that case, is something else. Which you should describe.

  3. #3
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Rep Power

Similar Threads

  1. Error Code???
    By andmartha in forum New To Java
    Replies: 11
    Last Post: 10-04-2008, 03:16 AM
  2. Help with code (static error)
    By oceansdepth in forum New To Java
    Replies: 1
    Last Post: 03-28-2008, 05:32 AM
  3. Pls help with a code error.
    By saytri in forum New To Java
    Replies: 8
    Last Post: 12-24-2007, 09:10 PM
  4. error in code
    By dirtycash in forum New To Java
    Replies: 2
    Last Post: 12-07-2007, 12:40 AM
  5. error stack when I try to execute my code
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 09:32 PM

Posting Permissions

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