问题标签 [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 投票
2 回答
12802 浏览

c++ - 当浮动变量超出浮动限制时,会发生什么?

我注意到两点:

  1. std::numeric_limits<float>::max()+(a small number) 给出: std::numeric_limits<float>::max()

  2. std::numeric_limits<float>::max()+(a large number喜欢:std::numeric_limits<float>::max()/3) 给出信息。

为什么会有这种差异?1 或 2 是否会导致溢出并因此导致未定义的行为?

编辑:用于测试的代码:

1.

2.

0 投票
1 回答
108 浏览

c++11 - C ++ 11,整数类型由范围确定?

所以这个问题出现了,在进行一些简单的编码时,请考虑以下内容;

上面的代码在假设'sizeof(unsigned int) >= 4'的情况下按预期工作,但是正如我们所知,在某些平台上这可能不是真的,因此我对类似的东西很感兴趣;

其中'RangeInt'是一个模板,'type'是最小的整数类型,足以容纳从MINIMUM(0x00000000)到MAXIMUM(0xFFFFFFFF)的值范围;

所以问题很简单:

  1. 这是在标准库的某个地方实现的吗?
  2. 如果没有,是否有实现此功能的库,或者我是否必须基于 std::numeric_limits 构建自己的库
0 投票
3 回答
9464 浏览

c++ - c++中“unsigned long int”的最大值

我如何知道“unsigned long int”类型的变量的最大可分配值是多少?

0 投票
1 回答
128 浏览

c++ - boost::graph 自定义权重类型:numeric_limits 必要吗?

MyWeight在 boost 图中有一个自定义边属性 ( ),并且想要应用 Dijkstra 最短路径搜索。

我的体重类型是,在 boost::operators 的帮助下,可加、可减、小于可比和相等可比。

因为我知道搜索必须从某些东西开始,所以我需要一个相当于零的值,并且要找出一个节点是否可以到达,这是一个非常大的东西。

这是我使用自定义重量的原则。它使用 gcc 4.8.1 编译(并且似乎可以正常工作),但是使用 gcc 4.7.3 我得到以下错误(有点缩短):

MyWeight实际上是一个模板)

我将此消息解释为“您的类型没有 std::numeric_limit”,另一方面,我告诉 BGL 使用哪个极值并且不明白为什么它会尝试调用数字限制。我认为在这里尝试的最好方法是numeric_limits识别我的自定义数据类型。

有人可以指出我如何做到这一点吗?

我在这里找到了第一个提示,但是该示例使用了digits和之类的成员digits10,我想知道它们的来源。

编辑

是一个像我一样的例子。无法编译,错误见上。

0 投票
1 回答
429 浏览

c++ - boost::multiprecision::cpp_dec_float_50 overflow checking

I am trying to use the boost::multiprecision library for floating (or in that case, fixed) point arithmetic. However, I am having trouble detecting potential overflow in the following way:

Shouldn't even adding 1 to max() for the type trigger the throw of the exception? I have also checked the underlying type after the overflow, and it's not cpp_dec_float_inf, still cpp_dec_float_finite. Also, the value of dtNew is equal to std::numeric_limits::max()

Am I under a complete conceptual misapprehension here? If so, what would be the correct way to prevent a boost::multiprecision::cpp_dec_float<50> from overflowing?

0 投票
1 回答
347 浏览

c++ - C++ 类 std::numeric_limits 中的字段与方法

std::numeric_limits为什么在 C++的模板类中, digits(和其他)被定义为类的(静态常量)字段,但是min()max()是方法,因为这些方法只返回一个字面值?

提前致谢。

0 投票
3 回答
61006 浏览

c++ - 负无穷大

我试图弄清楚如何将负无穷大的值分配给 float 或 double 变量。似乎包括标准库限制,我可以获得无穷大表示,并且我知道(非常肯定)在它前面添加一个减号(-infinity)可能会导致我在 IEEE754 浮点中寻找的值标准(因为 0x7FFFFFFF 可能会导致 0xFFFFFFFF),但我什至不确定,更不用说可能存在的其他标准(如果有的话)。我发现它真的非常不专业并且依赖于实施。

有没有什么好的方法可以独立获取负无穷平台的值和实现,不然我还不如用#define,大家都喜欢预处理。

0 投票
2 回答
2994 浏览

sql - SQL 中的最大日期范围

来自多条记录的最大日期范围

我有一张如下表。

我需要通过给出结束日期范围来获得结果。例如:如果输入:(end date 01-NOV-2013 to 30-NOV-2013搜索谁将在 11 月到期)

结果应该是

请注意,第 1 条和第 4 条记录不应存在,因为它们已更新其出版订阅期。

我怎样才能得到这些结果。请帮忙。

亲爱的,我可以获得给定日期范围的数据。但它返回 1 , 4 ,6 。我只需要记录 6 即可返回。因为我需要指定客户发布的最新日期范围。(每个客户每个出版物的最高日期范围)。至于我的输入(搜索 11 月的结束日期)。1 不是必需的,因为该客户已在 2 中延长了“DLD”期限。在第 4 条记录中也是如此。第 4 次不需要,因为它在记录 3 中扩展(更新)

0 投票
2 回答
1011 浏览

c++ - Should I be using numeric_limits or C limit macros?

I'm new to SO and this is my first question, but I've read the rules and I hope that I won't break any of them.

I have recently started learning programming and have chosen C++ as my first language. Today I have reached a point where I need help to make a proper decision. I'm learning from a 6th edition of C++ Primer Plus and so far author have only introduced C macros and haven't said a single word about numeric_limits template ( at least I think it's a template ) about which I have learned from internet thanks to my curiosity.

So, now I'm a bit lost, because if I understood correctly numeric_limits are a modern way for checking the limits of C++ types thanks to its easy expandability. Furthermore AFAIK among the C macros there aren't definitions for C++11 types like char16_t.

While searching only thing I have found is that question, but provided answers as helpful as they are, unfortunately they doesn't answer what is specifically interesting for me. Also they are mostly quite old actually.

Now, the specific question:

Basing on the needs for speed of code execution, safety and usefulness in future ( I don't care that much about simplicity ) is it better idea to use those old C macros or should I stick to numeric_limits considering the aspects I have mentioned?

Please, forgive me any mistakes in my English. It's not my native language.

0 投票
2 回答
3745 浏览

c++ - max_digits10 的用途是什么,它与 digits10 有何不同?

我对代表什么感到困惑max_digits10。根据其文档,对于所有整数类型,它都是 0。浮点类型的公式max_digits10看起来类似于int' digits10s 。