<bdo id='ZNiiD'></bdo><ul id='ZNiiD'></ul>
      1. <i id='ZNiiD'><tr id='ZNiiD'><dt id='ZNiiD'><q id='ZNiiD'><span id='ZNiiD'><b id='ZNiiD'><form id='ZNiiD'><ins id='ZNiiD'></ins><ul id='ZNiiD'></ul><sub id='ZNiiD'></sub></form><legend id='ZNiiD'></legend><bdo id='ZNiiD'><pre id='ZNiiD'><center id='ZNiiD'></center></pre></bdo></b><th id='ZNiiD'></th></span></q></dt></tr></i><div id='ZNiiD'><tfoot id='ZNiiD'></tfoot><dl id='ZNiiD'><fieldset id='ZNiiD'></fieldset></dl></div>

      2. <small id='ZNiiD'></small><noframes id='ZNiiD'>

      3. <tfoot id='ZNiiD'></tfoot>
      4. <legend id='ZNiiD'><style id='ZNiiD'><dir id='ZNiiD'><q id='ZNiiD'></q></dir></style></legend>

        在 std::floor 之后转换为 int 是否保证正确的结果

        时间:2023-08-03

          • <i id='dXnwX'><tr id='dXnwX'><dt id='dXnwX'><q id='dXnwX'><span id='dXnwX'><b id='dXnwX'><form id='dXnwX'><ins id='dXnwX'></ins><ul id='dXnwX'></ul><sub id='dXnwX'></sub></form><legend id='dXnwX'></legend><bdo id='dXnwX'><pre id='dXnwX'><center id='dXnwX'></center></pre></bdo></b><th id='dXnwX'></th></span></q></dt></tr></i><div id='dXnwX'><tfoot id='dXnwX'></tfoot><dl id='dXnwX'><fieldset id='dXnwX'></fieldset></dl></div>

              <legend id='dXnwX'><style id='dXnwX'><dir id='dXnwX'><q id='dXnwX'></q></dir></style></legend>
                <tbody id='dXnwX'></tbody>

              <small id='dXnwX'></small><noframes id='dXnwX'>

                <bdo id='dXnwX'></bdo><ul id='dXnwX'></ul>

              • <tfoot id='dXnwX'></tfoot>

                1. 本文介绍了在 std::floor 之后转换为 int 是否保证正确的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想要一个带有语法的 floor 函数

                  I'd like a floor function with the syntax

                  int floor(double x);
                  

                  但是 std::floor 返回一个 double.是

                  but std::floor returns a double. Is

                  static_cast <int> (std::floor(x));
                  

                  保证给我正确的整数,或者我可能有一个一对一的问题?它似乎有效,但我想确定.

                  guaranteed to give me the correct integer, or could I have an off-by-one problem? It seems to work, but I'd like to know for sure.

                  对于奖励积分,为什么 std::floor 一开始会返回 double ?

                  For bonus points, why the heck does std::floor return a double in the first place?

                  推荐答案

                  double 的范围远大于 32 或 64 位整数的范围,这就是为什么 std::floor 返回一个双重.强制转换为 int 应该没问题,只要它在适当的范围内 - 但请注意 double 不能准确表示所有 64 位整数,因此您也可以结束当您超过 double 的准确性使得两个连续双精度之间的差异大于 1 时,就会出现错误.

                  The range of double is way greater than the range of 32 or 64 bit integers, which is why std::floor returns a double. Casting to int should be fine so long as it's within the appropriate range - but be aware that a double can't represent all 64 bit integers exactly, so you may also end up with errors when you go beyond the point at which the accuracy of double is such that the difference between two consecutive doubles is greater than 1.

                  这篇关于在 std::floor 之后转换为 int 是否保证正确的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:剪辑数字的最有效/优雅的方法? 下一篇:矩形与矩形相交的面积

                  相关文章

                  最新文章

                  <i id='GPeUI'><tr id='GPeUI'><dt id='GPeUI'><q id='GPeUI'><span id='GPeUI'><b id='GPeUI'><form id='GPeUI'><ins id='GPeUI'></ins><ul id='GPeUI'></ul><sub id='GPeUI'></sub></form><legend id='GPeUI'></legend><bdo id='GPeUI'><pre id='GPeUI'><center id='GPeUI'></center></pre></bdo></b><th id='GPeUI'></th></span></q></dt></tr></i><div id='GPeUI'><tfoot id='GPeUI'></tfoot><dl id='GPeUI'><fieldset id='GPeUI'></fieldset></dl></div>

                  1. <legend id='GPeUI'><style id='GPeUI'><dir id='GPeUI'><q id='GPeUI'></q></dir></style></legend>
                      <tfoot id='GPeUI'></tfoot>
                        <bdo id='GPeUI'></bdo><ul id='GPeUI'></ul>

                      <small id='GPeUI'></small><noframes id='GPeUI'>