Help! Need source code for _isnan and _finite
-
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
-
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
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
-
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
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.
-
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
why a third party lib would redefine them ? :confused:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
why a third party lib would redefine them ? :confused:
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
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
-
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
just a guess (stupid guess probably) : do you have to source of that analysis lib ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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
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
-
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.
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
-
just a guess (stupid guess probably) : do you have to source of that analysis lib ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
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
-
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
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