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. How to know whether a double value is valid or not??

How to know whether a double value is valid or not??

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 5 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.
  • A Offline
    A Offline
    ashxly
    wrote on last edited by
    #1

    Recently I find that my application always crashs with invalid double floating value, so I want to determine whether a double floating value is valid or not then I can do some extra work to avoid crashes. Can anybody tell me is there any function or method to known whether a floating value is valid or invalid?? Thanks a lot

    M R T D 4 Replies Last reply
    0
    • A ashxly

      Recently I find that my application always crashs with invalid double floating value, so I want to determine whether a double floating value is valid or not then I can do some extra work to avoid crashes. Can anybody tell me is there any function or method to known whether a floating value is valid or invalid?? Thanks a lot

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      How come invalid ? :confused:


      Maximilien Lincourt Your Head A Splode - Strong Bad

      A 1 Reply Last reply
      0
      • M Maximilien

        How come invalid ? :confused:


        Maximilien Lincourt Your Head A Splode - Strong Bad

        A Offline
        A Offline
        ashxly
        wrote on last edited by
        #3

        the result looks like 1.#NF, and no divided by zero exception occurs.

        R 1 Reply Last reply
        0
        • A ashxly

          Recently I find that my application always crashs with invalid double floating value, so I want to determine whether a double floating value is valid or not then I can do some extra work to avoid crashes. Can anybody tell me is there any function or method to known whether a floating value is valid or invalid?? Thanks a lot

          R Offline
          R Offline
          RChin
          wrote on last edited by
          #4

          Can you give us an example of an invalid floating point value? Or more importantly where in your code this is causing the crash.


          I Dream of Absolute Zero

          1 Reply Last reply
          0
          • A ashxly

            the result looks like 1.#NF, and no divided by zero exception occurs.

            R Offline
            R Offline
            RChin
            wrote on last edited by
            #5

            ashxly wrote: the result looks like 1.#NF, and no divided by zero exception occurs OK. This makes sense. The error occurs because infinity cannot be truely represented by any numerical value, including floats. You will certainly get a numerical overflow if you try to divide by zero[^]. So I think the cause is not that you have an 'invalid' float value (unlikely), but that you are performing an invalid mathematical action (like dividing by zero).


            I Dream of Absolute Zero

            1 Reply Last reply
            0
            • A ashxly

              Recently I find that my application always crashs with invalid double floating value, so I want to determine whether a double floating value is valid or not then I can do some extra work to avoid crashes. Can anybody tell me is there any function or method to known whether a floating value is valid or invalid?? Thanks a lot

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              have a look at <float.h>. it provides many functions to manage the infinites, undefined values, and so...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              1 Reply Last reply
              0
              • A ashxly

                Recently I find that my application always crashs with invalid double floating value, so I want to determine whether a double floating value is valid or not then I can do some extra work to avoid crashes. Can anybody tell me is there any function or method to known whether a floating value is valid or invalid?? Thanks a lot

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

                Have you looked at _isnan()?


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                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