Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VC++ stream floating point precision error

VC++ stream floating point precision error

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
8 Posts 4 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Val Samko
    wrote on last edited by
    #1

    =========== #include int main() { double z = 20.0; std::cout<

    J T 2 Replies Last reply
    0
    • V Val Samko

      =========== #include int main() { double z = 20.0; std::cout<

      J Offline
      J Offline
      Joseph Dempsey
      wrote on last edited by
      #2

      a double is only a 64bit value. You can't get a 128 bit number out of that. You're going to have to find some other way of getting your precision. Joseph Dempsey joseph_r_dempsey@yahoo.com "Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning." --anonymous

      V 1 Reply Last reply
      0
      • J Joseph Dempsey

        a double is only a 64bit value. You can't get a 128 bit number out of that. You're going to have to find some other way of getting your precision. Joseph Dempsey joseph_r_dempsey@yahoo.com "Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning." --anonymous

        V Offline
        V Offline
        Val Samko
        wrote on last edited by
        #3

        double on Win32 is of course 64bit. long double on SGI and on Sun is 128bit. The question is - why does VC++ produce such a weird output? I am not trying to get 128bit number out of Win32 double, I'm just trying to output it with 50 digits after the decimal point. And when I try to do that, I get completely wrong result. Borland C++ and g++ produce correct results on Win32.

        D 1 Reply Last reply
        0
        • V Val Samko

          double on Win32 is of course 64bit. long double on SGI and on Sun is 128bit. The question is - why does VC++ produce such a weird output? I am not trying to get 128bit number out of Win32 double, I'm just trying to output it with 50 digits after the decimal point. And when I try to do that, I get completely wrong result. Borland C++ and g++ produce correct results on Win32.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Just a guess but I think it may be outputting the least number of digits required for significance.

          V 1 Reply Last reply
          0
          • D David Crow

            Just a guess but I think it may be outputting the least number of digits required for significance.

            V Offline
            V Offline
            Val Samko
            wrote on last edited by
            #5

            The problem is quite different, 20 and 2000000000000000 are just very different numbers, it is not the same nubmer with a different number of digits after the decimal point .. there is no decimal point :)

            D 1 Reply Last reply
            0
            • V Val Samko

              The problem is quite different, 20 and 2000000000000000 are just very different numbers, it is not the same nubmer with a different number of digits after the decimal point .. there is no decimal point :)

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Perhaps you'd want this instead:

              void main( void )
              {
              double z = 20.0123;

              for (int x = 1; x < 40; x++)
                  cout << setprecision(x) << z << endl;
              

              }

              1 Reply Last reply
              0
              • V Val Samko

                =========== #include int main() { double z = 20.0; std::cout<

                T Offline
                T Offline
                Tim Smith
                wrote on last edited by
                #7

                It is a bug in Microsoft's STL when the precision is greater than _MAX_SIG_DIG and the formatted number doesn't contain any decimal point. Send the bug off to Microsoft and/or Dinkumware http://www.dinkumware.com/[^]. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                V 1 Reply Last reply
                0
                • T Tim Smith

                  It is a bug in Microsoft's STL when the precision is greater than _MAX_SIG_DIG and the formatted number doesn't contain any decimal point. Send the bug off to Microsoft and/or Dinkumware http://www.dinkumware.com/[^]. Tim Smith I'm going to patent thought. I have yet to see any prior art.

                  V Offline
                  V Offline
                  Val Samko
                  wrote on last edited by
                  #8

                  I thought it is a bug, weird one. Thanks for the explanation.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups