问题标签 [numeric-limits]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1751 浏览

c++ - elegant way to get a variables limit

is there an better way to set a variables to one of its limits than

especially when initializing

I normally do not want to use the type in such expressions since its easy to miss this if type is changed.

0 投票
2 回答
1517 浏览

c++ - gdb中的inf是什么

我正在调试一个 C++ 程序。有一个xdouble 类型的变量,gdb 将其值打印为inf. false然而,即使 的值x没有改变,以下表达式也会返回

x == std::numeric_limits<double>::max()

当 gdb 说inf时,这不是指这种类型的最大可能值(双精度)吗?如果不是,那是什么意思?

0 投票
2 回答
1114 浏览

c++ - C++ 整数限制

所以我觉得我有点困惑。我正在搜索有关不同类型整数的限制的信息。我已经看到 unsigned long int 的限制是 4294967295 但是当我这样做时:

我越来越:

如果我没记错的话,这个数字是 unsigned long long 的极限,不是吗?那么发生了什么?谢谢

0 投票
2 回答
1490 浏览

c++ - 浮点数的整数部分中以 10 为基数的最大位数是多少

我想知道标准中是否有某些内容,例如 a#define或某些numeric_limits内容可以告诉我浮点类型的整数部分中基数为 10 位的最大位数。

例如,如果我有一些浮点类型,其最大值是:1234.567。我想要标准中定义的东西,它会告诉我 4 那种类型。

我可以选择这样做吗?

0 投票
5 回答
1533 浏览

c++ - 浮点数小数部分中以 10 为基数的最大位数是多少

如果可以输出一个浮点数,从而没有截断值(比如setpercisionfixed浮点数可以存储在缓冲区中吗?

我希望标准中有一些东西,比如 a#define或其他东西,numeric_limits它会告诉我浮点类型小数部分的最大基数为 10 值的位置。

我在这里询问了浮点类型小数部分中基数为 10 位的最大位数:What are the Maximum Number of Base-10 Digits in the Integral Part of a Floating Point Number

但我意识到这可能更复杂。例如,1.0 / 3.0是一个无限重复的数字序列。当我使用fixed格式输出时,我会在重复 0 之前得到这么多地方:

0.333333333333333314829616256247390992939472198486328125

但我不一定说这是最大精度,因为我不知道有多少尾随的 0 实际上表示在浮点的分数中,并且它没有被负指数向下移动。

我知道我们有min_exponent10这就是我应该寻找的?

0 投票
2 回答
1104 浏览

c++ - Obtaining max of unsigned integer with bitwise not on zero value

I'm trying to obtain the maximum value of a certain unsigned integer type without including any headers like <limits>. So I thought I'd simply flip the bits of the unsigned integer value 0.

I'm not very experienced on the subtle differences between these. Which is why I'm asking if some unexpected behavior or some platform/architecture issues could occur by using the first method.

0 投票
2 回答
182 浏览

c++ - 为 numeric_limit 指定无界限制::最大限度()?

我有一个任意精度Integer类,它很像 JavaBigInteger或 OpenSSL 的BIGNUM操作。我无法理解我应该如何表达numeric_limit<Integer>::max().

Stack Overflow 有几个问题询问是否可以这样做(例如是否可以将 std::numeric_limits 专门用于用户定义的类数字类?),以及一些使用原语的示例的答案,但我没有看到使用任意精度整数类的示例。我还访问了std::numeric_limits参考页面,但我不清楚在这种情况下我应该做什么。

在这一点上,我的外卖是可以专门numeric_limit用于 my Integer,并且可以将其放在标准命名空间中。我还需要专攻所有numeric_limits

如何为 指定无界限制numeric_limit<T>::max()


以下来自 GCC 4.2.1 <limits>(OS X 机器)。

0 投票
1 回答
303 浏览

c++ - 为什么 std::numeric_limits::min() 在使用不同功能流式传输到输出时的行为不同?

我有一个奇怪的行为

当我调用 std::cout 时,我得到的输出值为 1.17549e-38

相反,当我使用

我得到的值为 0.000000。

请注意,当我评估 ( std::numeric_limits<float>::min() == std::numeric_limits<float>::min()) 时,我得到true(这是直观且合乎逻辑的)

那么,任何人都可以向我解释这种输出差异吗?

0 投票
2 回答
238 浏览

c++ - 为什么 std::numeric_limits::is_integer 对于 volatile 类型为假?

评估为“假”。

但为什么?volatile int 不还是整数类型吗?我想知道这其中是否有某种深意。

UPD:编译器是来自 Keil 4.72 的 armcc

0 投票
1 回答
1475 浏览

c++ - Apple Clang 和 numeric_limits::max() 为 0?

我试图找出解决numeric_limits<T>::max()返回 0 而不是最大值的明显错误的最佳方法。

一、测试程序:

__SIZEOF_INT128__ >= 16测试来自关于128 位整数的 GCC 邮件列表的讨论 - 无意义的文档?.

结果:

Apple 也放弃了平台和工具,因此错误报告无法解决问题。

我们如何解决这个问题?


我不确定如何进行。要解决代码中的问题,与上面的最小示例相反,我们确实需要覆盖std命名空间中的函数。但是不允许重写函数std

这是一个示例,说明为什么它在实际代码中存在问题:

T1 = __int128在上面的代码中,我们必须为每个T2可以想象的组合提供完整的专业化。它不现实。


问题机器上的编译器版本:

但是,跳转到非 Apple 测试机器会产生预期的结果: