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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why it happen?A error happen in VC6.0

Why it happen?A error happen in VC6.0

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    When I use VC6.0,I find that: float value=33.4; DWORD temp=33; value=value-(float)temp; or value=value-temp; Then value will be 0.4 in theory. But in face it is 0.400002 in vc 6.0. Why is it? is it a bug of VC6.0 or CPU?

    W S 2 Replies Last reply
    0
    • L Lost User

      When I use VC6.0,I find that: float value=33.4; DWORD temp=33; value=value-(float)temp; or value=value-temp; Then value will be 0.4 in theory. But in face it is 0.400002 in vc 6.0. Why is it? is it a bug of VC6.0 or CPU?

      W Offline
      W Offline
      WaitYY1980
      wrote on last edited by
      #2

      Because,in fact,the float or double is not always preciously number when it store in the memory.:laugh::laugh:

      1 Reply Last reply
      0
      • L Lost User

        When I use VC6.0,I find that: float value=33.4; DWORD temp=33; value=value-(float)temp; or value=value-temp; Then value will be 0.4 in theory. But in face it is 0.400002 in vc 6.0. Why is it? is it a bug of VC6.0 or CPU?

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        That's life with floating point arithmetic. Just like 1/3 can't be represented in decimal without an infinite number of decimal places not all numbers can be represented exactly in base 2 with a fixed number of binary places. If you use doubles to get more precision the answer comes to 0.39999999999999858 which is closer to the ideal. On a sererate issue, lose the float cast: it's not needed and is bad form.

        Steve

        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