看板 Programming 關於我們 聯絡資訊
==> 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: **]
MOONRAKER:(1)用union(2)用一個int *在函數裡面接 59.120.168.228 11/11 14:35
MOONRAKER:就得了 59.120.168.228 11/11 14:35