Re: [問題] 請問是否有浮點數轉二進制的函式(C)

看板Programming作者時間15年前 (2010/11/11 09:01), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/2 (看更多)
==> 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
(1)用union(2)用一個int *在函數裡面接
11/11 14:35, 1F

11/11 14:35, , 2F
就得了
11/11 14:35, 2F
文章代碼(AID): #1Csq1Em8 (Programming)
文章代碼(AID): #1Csq1Em8 (Programming)