Re: [問題] no math.h, 如何判斷一浮點數 是否為整數
異想天開的方法,別打我
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
09/28 13:35, 2F
討論串 (同標題文章)