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. casting problems

casting problems

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
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

    Hi, I have an awefull problem with casting floats to doubles, for example: float f = 0.2f; double d = (double)f; results in d == 0.20000000232323442 or other garbage after the precision of float. I'll be glad to any ideas other than fitting the result to float precision since float precision might be change between platforms. (theoreticly speaking). thanks, BishGada. :confused:

    _ M 2 Replies Last reply
    0
    • L Lost User

      Hi, I have an awefull problem with casting floats to doubles, for example: float f = 0.2f; double d = (double)f; results in d == 0.20000000232323442 or other garbage after the precision of float. I'll be glad to any ideas other than fitting the result to float precision since float precision might be change between platforms. (theoreticly speaking). thanks, BishGada. :confused:

      _ Offline
      _ Offline
      _Magnus_
      wrote on last edited by
      #2

      I think there is some compiler switch for that....but not sure. /Magnus


      - A dog who attends a flea circus most likely will steal the whole show

      1 Reply Last reply
      0
      • L Lost User

        Hi, I have an awefull problem with casting floats to doubles, for example: float f = 0.2f; double d = (double)f; results in d == 0.20000000232323442 or other garbage after the precision of float. I'll be glad to any ideas other than fitting the result to float precision since float precision might be change between platforms. (theoreticly speaking). thanks, BishGada. :confused:

        M Offline
        M Offline
        Mel Stober
        wrote on last edited by
        #3

        That problem has existed on every Intell computer that I know of for the last 30 years. Its not really Intell's fault, but rather the nature of the beast. Many numbers cannot be represented exactly by floating-point math due to the way they are calculated. It has something to do with powers of 2, but I don't recall the exact calculation. Here's an article, if you can wade through it. http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html

        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