Results 1 to 3 of 3

Thread: setprecision Help please...

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    1

    setprecision Help please...

    I have
    Code:
    double m=0.5;
    cout<<setprecision(20);
    Then the output is 0.5 but
    Code:
    double m=0.6;
    cout<<setprecision(20);
    the output is 0.59999999999999999998
    What happens and how can I fix this error ?

    Thanks in advance,

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    There is nothing you can do about it. This is a issue with IEEE floating point.

    IEEE floating point format is not accurate. Anyway double type have precision up to 15 decimal digits.

    There is c maths library which allows any numbers up to any arbitrary digits you require. The downside of it is it is slow.

  3. #3
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Here's one library, The GNU MP Home Page

    I'm sure there are more which you can google.

Posting Permissions

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



Click Here to Expand Forum to Full Width