在C/C++中检查数字是否为整数(不带scanf/gets/etc)



在Python中,我要做的是这样的(其中n为浮点/双精度(:

def check_int(n):
if not isinstance(n, numbers.Integral):
raise TypeError()

既然C/C++是强类型的,那么什么样的投射和比较魔术最适合这个目的呢?

我最好想知道它是如何在C.中完成的

使用floor

#include <cmath>
if (floor(n) == n)
// n is an integer (mathematically speaking)

最新更新