gpt4 book ai didi

c++ - 为什么标准同时提供了 is_integer 和 is_exact?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:10:46 25 4
gpt4 key购买 nike

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

  • is_integer : true 对于所有整数算术类型 T

  • is_exact : true 对于所有使用精确表示的算术类型 T

是否存在非精确整数类型的可能性?在这里允许做什么?

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

最佳答案

来自 is_exact cppreference 页面:

Notes

While all fundamental types T for whichstd::numeric_limits<T>::is_exact==true are integer types, a librarymay define exact types that aren't integers, e.g. a rationalarithmetics 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++ - 为什么标准同时提供了 is_integer 和 is_exact?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48227296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com