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. Help! Need source code for _isnan and _finite

Help! Need source code for _isnan and _finite

Scheduled Pinned Locked Moved C / C++ / MFC
help
10 Posts 4 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
    Jesse Evans
    wrote on last edited by
    #1

    Folks, (using MSVC 6.0) Not sure if I got the function names right. I have an situation where I need to determine if a double value is corrupted. I should be able to check this by using _isnan and _finite (Is Not A Number and Is Finite). Both these functions are defined in LIBCMDT.lib but they collide with definitions in a third party library I need and I can't compile. So, I'm looking for source code for these two functions so avoid the collision problem. I've Googled them both but have not found a solution that seems ok (lot's of unix references). TIA!

    'til next we type... HAVE FUN!! -- Jesse

    S J T 3 Replies Last reply
    0
    • J Jesse Evans

      Folks, (using MSVC 6.0) Not sure if I got the function names right. I have an situation where I need to determine if a double value is corrupted. I should be able to check this by using _isnan and _finite (Is Not A Number and Is Finite). Both these functions are defined in LIBCMDT.lib but they collide with definitions in a third party library I need and I can't compile. So, I'm looking for source code for these two functions so avoid the collision problem. I've Googled them both but have not found a solution that seems ok (lot's of unix references). TIA!

      'til next we type... HAVE FUN!! -- Jesse

      S Offline
      S Offline
      Saurabh Garg
      wrote on last edited by
      #2

      I am pretty sure you can resolve conflict by not using you own functions. But I have those functions handy so I will give it anyway.

      typedef __int64 Int64;

      //! Check if a number is infinite.
      inline bool isInfinite(double A)
      {
      // Representation of infinity for double precision number.
      static const Int64 _kInfAsInt = 0x7FF0000000000000;

      // An infinity has an exponent of 1023 (shift left 52 positions) and
      // a zero mantissa. There are two infinities - positive and negative.
      if ((\*(Int64\*)&A & 0x7FFFFFFFFFFFFFFF) == \_kInfAsInt)
      {
      	return true;
      }
      else
      {
      	return false;
      }
      

      }

      //! Check if a number is Not-a-Number.
      inline bool isNan(double A)
      {
      // A NAN has an exponent of 1023 (shifted left 52 positions) and
      // a non-zero mantissa. There are two Nan's - positive and negative.
      Int64 _exp = *(Int64*)&A & 0x7FF0000000000000;
      Int64 _mantissa = *(Int64*)&A & 0xFFFFFFFFFFFFF;

      if(\_exp == 0x7FF0000000000000 && \_mantissa != 0)
      {
      	return true;
      }
      else
      {
      	return false;
      }
      

      }

      -Saurabh

      J 1 Reply Last reply
      0
      • J Jesse Evans

        Folks, (using MSVC 6.0) Not sure if I got the function names right. I have an situation where I need to determine if a double value is corrupted. I should be able to check this by using _isnan and _finite (Is Not A Number and Is Finite). Both these functions are defined in LIBCMDT.lib but they collide with definitions in a third party library I need and I can't compile. So, I'm looking for source code for these two functions so avoid the collision problem. I've Googled them both but have not found a solution that seems ok (lot's of unix references). TIA!

        'til next we type... HAVE FUN!! -- Jesse

        J Offline
        J Offline
        Jijo Raj
        wrote on last edited by
        #3

        Found another similar function - _fpclass(). For checking NaN, it returns status such as _FPCLASS_SNAN and _FPCLASS_QNAN. For infinity, _FPCLASS_PINF and _FPCLASS_NINF. Have a look at it. Might be useful. Regards, Jijo.

        _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

        J 1 Reply Last reply
        0
        • J Jesse Evans

          Folks, (using MSVC 6.0) Not sure if I got the function names right. I have an situation where I need to determine if a double value is corrupted. I should be able to check this by using _isnan and _finite (Is Not A Number and Is Finite). Both these functions are defined in LIBCMDT.lib but they collide with definitions in a third party library I need and I can't compile. So, I'm looking for source code for these two functions so avoid the collision problem. I've Googled them both but have not found a solution that seems ok (lot's of unix references). TIA!

          'til next we type... HAVE FUN!! -- Jesse

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

          why a third party lib would redefine them ? :confused:

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          J 1 Reply Last reply
          0
          • T toxcct

            why a third party lib would redefine them ? :confused:

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            J Offline
            J Offline
            Jesse Evans
            wrote on last edited by
            #5

            toxcct wrote:

            why a third party lib would redefine them ?

            Dunno, but here's the build output:

            --------------------Configuration: ConstATE_B - Win32 Debug--------------------
            Linking...
            LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __finite already defined in analysis.lib(isnan.obj)
            LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __isnan already defined in analysis.lib(isnan.obj)
            .\ConstATE_B.exe : fatal error LNK1169: one or more multiply defined symbols found
            Error executing link.exe.

            ConstATE_B.exe - 3 error(s), 0 warning(s)

            analysis.lib is the third-party library. If I opt to ignore either library I get a lot more errors!

            'til next we type... HAVE FUN!! -- Jesse

            T 1 Reply Last reply
            0
            • J Jesse Evans

              toxcct wrote:

              why a third party lib would redefine them ?

              Dunno, but here's the build output:

              --------------------Configuration: ConstATE_B - Win32 Debug--------------------
              Linking...
              LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __finite already defined in analysis.lib(isnan.obj)
              LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __isnan already defined in analysis.lib(isnan.obj)
              .\ConstATE_B.exe : fatal error LNK1169: one or more multiply defined symbols found
              Error executing link.exe.

              ConstATE_B.exe - 3 error(s), 0 warning(s)

              analysis.lib is the third-party library. If I opt to ignore either library I get a lot more errors!

              'til next we type... HAVE FUN!! -- Jesse

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

              just a guess (stupid guess probably) : do you have to source of that analysis lib ?

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              J 1 Reply Last reply
              0
              • S Saurabh Garg

                I am pretty sure you can resolve conflict by not using you own functions. But I have those functions handy so I will give it anyway.

                typedef __int64 Int64;

                //! Check if a number is infinite.
                inline bool isInfinite(double A)
                {
                // Representation of infinity for double precision number.
                static const Int64 _kInfAsInt = 0x7FF0000000000000;

                // An infinity has an exponent of 1023 (shift left 52 positions) and
                // a zero mantissa. There are two infinities - positive and negative.
                if ((\*(Int64\*)&A & 0x7FFFFFFFFFFFFFFF) == \_kInfAsInt)
                {
                	return true;
                }
                else
                {
                	return false;
                }
                

                }

                //! Check if a number is Not-a-Number.
                inline bool isNan(double A)
                {
                // A NAN has an exponent of 1023 (shifted left 52 positions) and
                // a non-zero mantissa. There are two Nan's - positive and negative.
                Int64 _exp = *(Int64*)&A & 0x7FF0000000000000;
                Int64 _mantissa = *(Int64*)&A & 0xFFFFFFFFFFFFF;

                if(\_exp == 0x7FF0000000000000 && \_mantissa != 0)
                {
                	return true;
                }
                else
                {
                	return false;
                }
                

                }

                -Saurabh

                J Offline
                J Offline
                Jesse Evans
                wrote on last edited by
                #7

                Saurabh.Garg wrote:

                I am pretty sure you can resolve conflict by not using you own functions.

                Not sure how. Here's the build output:

                --------------------Configuration: ConstATE_B - Win32 Debug--------------------
                Linking...
                LINK : LNK6004: .\ConstATE_B.exe not found or not built by the last incremental link; performing full link
                LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __finite already defined in analysis.lib(isnan.obj)
                LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __isnan already defined in analysis.lib(isnan.obj)
                .\ConstATE_B.exe : fatal error LNK1169: one or more multiply defined symbols found
                Error executing link.exe.
                Creating browse info file...

                ConstATE_B.exe - 3 error(s), 0 warning(s)

                Saurabh.Garg wrote:

                I have those functions handy so I will give it anyway.

                Thanks! That should help.

                'til next we type... HAVE FUN!! -- Jesse

                S 1 Reply Last reply
                0
                • J Jijo Raj

                  Found another similar function - _fpclass(). For checking NaN, it returns status such as _FPCLASS_SNAN and _FPCLASS_QNAN. For infinity, _FPCLASS_PINF and _FPCLASS_NINF. Have a look at it. Might be useful. Regards, Jijo.

                  _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

                  J Offline
                  J Offline
                  Jesse Evans
                  wrote on last edited by
                  #8

                  Jijo raj wrote:

                  Found another similar function - _fpclass().

                  Aha, a solution that does not depend upon custom functions. That should work fine, thanks!

                  'til next we type... HAVE FUN!! -- Jesse

                  1 Reply Last reply
                  0
                  • T toxcct

                    just a guess (stupid guess probably) : do you have to source of that analysis lib ?

                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    J Offline
                    J Offline
                    Jesse Evans
                    wrote on last edited by
                    #9

                    Nope. Only the library object file. Jijo raj suggested using _fpclass so I'm giving that a go.

                    'til next we type... HAVE FUN!! -- Jesse

                    1 Reply Last reply
                    0
                    • J Jesse Evans

                      Saurabh.Garg wrote:

                      I am pretty sure you can resolve conflict by not using you own functions.

                      Not sure how. Here's the build output:

                      --------------------Configuration: ConstATE_B - Win32 Debug--------------------
                      Linking...
                      LINK : LNK6004: .\ConstATE_B.exe not found or not built by the last incremental link; performing full link
                      LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __finite already defined in analysis.lib(isnan.obj)
                      LIBCMTD.lib(ieeemisc.obj) : error LNK2005: __isnan already defined in analysis.lib(isnan.obj)
                      .\ConstATE_B.exe : fatal error LNK1169: one or more multiply defined symbols found
                      Error executing link.exe.
                      Creating browse info file...

                      ConstATE_B.exe - 3 error(s), 0 warning(s)

                      Saurabh.Garg wrote:

                      I have those functions handy so I will give it anyway.

                      Thanks! That should help.

                      'til next we type... HAVE FUN!! -- Jesse

                      S Offline
                      S Offline
                      Saurabh Garg
                      wrote on last edited by
                      #10

                      Those error are almost always due to linking different "types" of CRT in different modules. For example your main executable might be using "Multi-threaded Debug DLL" CRT but one of your other statically linked library might be using "Multi-threaded Debug" or may be just single threaded ones. In this case I think analysis.lib is a static library and it is using a version of CRT different from the application you are linking it with. Make you all CRTs are of same type and those errors will go away. -Saurabh

                      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