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. Question about double #INF and #NAN

Question about double #INF and #NAN

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 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.
  • J Offline
    J Offline
    Jeff Archer
    wrote on last edited by
    #1

    Does anyone understand the bit-wise representations of #INF and #NAN for the type double?   Or could you point me to some real information on the internet? Also, what is the difference between Quiet NAN and Signaling NAN? I have been trying to find it with google all morning and I have found a lot of claiming to know but no actual knowledge. I know that for type float the bits are: 0x7FFFFFFF; // #NAN 0x7F800000; // #INF I believe that for type double the bits would: 0x7FFFFFFFFFFFFFFF; // #NAN 0x7FF0000000000000; // #INF However, this is just changing the exponent from 8 to 10 bits and assuming that if would be the same.   I would feel much better if I could find some supporting documentation.

    CPalliniC 1 Reply Last reply
    0
    • J Jeff Archer

      Does anyone understand the bit-wise representations of #INF and #NAN for the type double?   Or could you point me to some real information on the internet? Also, what is the difference between Quiet NAN and Signaling NAN? I have been trying to find it with google all morning and I have found a lot of claiming to know but no actual knowledge. I know that for type float the bits are: 0x7FFFFFFF; // #NAN 0x7F800000; // #INF I believe that for type double the bits would: 0x7FFFFFFFFFFFFFFF; // #NAN 0x7FF0000000000000; // #INF However, this is just changing the exponent from 8 to 10 bits and assuming that if would be the same.   I would feel much better if I could find some supporting documentation.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Isn't this [^] useful? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      J 1 Reply Last reply
      0
      • CPalliniC CPallini

        Isn't this [^] useful? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        J Offline
        J Offline
        Jeff Archer
        wrote on last edited by
        #3

        Yes, and thanks.   But I'm still kind of looking for a nice table like they have for the 32 floats.   Don't want to make the table myself because I'm not the expert.   Just want to be able to refer to the expert.

        L CPalliniC 2 Replies Last reply
        0
        • J Jeff Archer

          Yes, and thanks.   But I'm still kind of looking for a nice table like they have for the 32 floats.   Don't want to make the table myself because I'm not the expert.   Just want to be able to refer to the expert.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If you scroll up the page the nice table is there on the screen. [edit]sorry I note those are not doubles, but I'm sure a bit of simple extrapolation will do it[/edit]

          J 1 Reply Last reply
          0
          • J Jeff Archer

            Yes, and thanks.   But I'm still kind of looking for a nice table like they have for the 32 floats.   Don't want to make the table myself because I'm not the expert.   Just want to be able to refer to the expert.

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            If you're looking for NAN it may be either 0xFFFM or 0x7FFM i.e. sign bit may be either 0 or 1 and 52 bit-wide mantissa M != 0 is implementation-dependent (may carry additional info). Of course this is going on my arrogant assumptions... :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            In testa che avete, signor di Ceprano?

            J 1 Reply Last reply
            0
            • CPalliniC CPallini

              If you're looking for NAN it may be either 0xFFFM or 0x7FFM i.e. sign bit may be either 0 or 1 and 52 bit-wide mantissa M != 0 is implementation-dependent (may carry additional info). Of course this is going on my arrogant assumptions... :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              J Offline
              J Offline
              Jeff Archer
              wrote on last edited by
              #6

              The values in my original question are correct. (I believe) Just looking for supporting documentation. Thanks again for the time and thought you have put into this.

              CPalliniC 1 Reply Last reply
              0
              • L Lost User

                If you scroll up the page the nice table is there on the screen. [edit]sorry I note those are not doubles, but I'm sure a bit of simple extrapolation will do it[/edit]

                J Offline
                J Offline
                Jeff Archer
                wrote on last edited by
                #7

                Thanks. I was hoping to find such a table for double.   Really, just a supporting documentation.   I believe the values in my original question were correct.

                1 Reply Last reply
                0
                • J Jeff Archer

                  The values in my original question are correct. (I believe) Just looking for supporting documentation. Thanks again for the time and thought you have put into this.

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Well, while your values represent correctly NAN values, they (according to that Wikipedia page) don't cover all the possibilities. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  J 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    Well, while your values represent correctly NAN values, they (according to that Wikipedia page) don't cover all the possibilities. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    J Offline
                    J Offline
                    Jeff Archer
                    wrote on last edited by
                    #9

                    Sorry, I guess I didn't present that very well. NAN is an exponent of 0x7FF with a non-zero mantissa. INF is an exponent of 0x7FF with a zero mantissa. Here are the actual fuctions I am using... bool IsInf (double d) {       const INT64 iInf = 0x7FF0000000000000;       if ((*(INT64*)&d & 0x7FFFFFFFFFFFFFFF) == iInf)             return true;       return false; } bool IsNan (double d) {       INT64 exp = *(INT64*)&d & 0x7FF0000000000000;       INT64 mantissa = *(INT64*)&d & 0x000FFFFFFFFFFFFF;       if (exp == 0x7FF0000000000000 && mantissa != 0)             return true;       return false; }

                    modified on Friday, November 27, 2009 3:04 PM

                    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