Re: [問題] 請問是否有浮點數轉二進制的函式(C)
==> superlulier.bbs@ptt.cc (Avril Lavigne) 提到:
> 想請問是否有函式可以浮點數轉成32bit的
> thx
Visual Studio 2005 以上的版本的指令,
僅供參考
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 & 0x7FFFFFFFFFFFF;
if(_exp == 0x7FF0000000000000 && _mantissa == 0)
{
return true;
}
else
{
return false;
}
}
--
只有充滿感情的歌聲能阻止世界末日發生,
音樂才是真正的第五元素.
--
☆ [Origin:椰林風情] [From: 58-115-151-138.cable.dynami] [Login: **] [Post: **]
→
11/11 14:35, , 1F
11/11 14:35, 1F
→
11/11 14:35, , 2F
11/11 14:35, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章