c – 为什么标准同时提供is_integer和is_exact?

std :: numeric_limits提供了2个互斥的常量:

> is_integer :“对于所有整数算术类型T都为真”
> is_exact:“对于使用精确表示的所有算术类型T都是如此”

是否存在非精确积分类型的可能性?在这里试图允许什么?

在我的所有模板中,我知道我是否处理精确数字,我使用了is_integer,我是否还需要为is_exact添加一个检查?

解决方法

is_exact cppreference页面

Notes

While all fundamental types T for which
std::numeric_limits<T>::is_exact==true are integer types,a library
may define exact types that aren’t integers
,e.g. a rational
arithmetics type representing fractions.

而且,正如@Holt所提到的,该标准也描述了它:

21.3.4.1 numeric_limits members [numeric.limits.members]

static constexpr bool is_exact;

true if the type uses an exact representation. All integer types are exact,but not all exact types are integer. For example,rational and fixed-exponent representations are exact but not integer.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...