Re: [問題] no math.h, 如何判斷一浮點數 是否為整數

看板C_and_CPP作者 (我要加入劍道社!)時間14年前 (2011/09/28 02:47), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串3/3 (看更多)
異想天開的方法,別打我 bool check_integer(double x) { stringstream str; str << fixed << setprecision(0) << x; double y; str >> y; return (x == y); } 事後想想如果 float 和 double 未遵循 IEEE754 的話 這方法似乎不錯 XD -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.168.122.156

09/28 02:47, , 1F
喔 被前一篇領先了
09/28 02:47, 1F

09/28 13:35, , 2F
若未遵循IEEE754,此法確實較為簡便。
09/28 13:35, 2F
文章代碼(AID): #1EWXea38 (C_and_CPP)
文章代碼(AID): #1EWXea38 (C_and_CPP)