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

    1. <legend id='o32OA'><style id='o32OA'><dir id='o32OA'><q id='o32OA'></q></dir></style></legend>

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

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

        “.f"的目的附加到一个数字?

        Purpose of a quot;.fquot; appended to a number?(“.f的目的附加到一个数字?)

              <tbody id='rjp2C'></tbody>
            <tfoot id='rjp2C'></tfoot>

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

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

                • <bdo id='rjp2C'></bdo><ul id='rjp2C'></ul>

                  <legend id='rjp2C'><style id='rjp2C'><dir id='rjp2C'><q id='rjp2C'></q></dir></style></legend>
                  本文介绍了“.f"的目的附加到一个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在一个程序中看到 1/3.f 并想知道 .f 是做什么用的.所以尝试了我自己的程序:

                  I saw 1/3.f in a program and wondered what the .f was for. So tried my own program:

                  #include <iostream>
                  
                  int main()
                  {
                      std::cout << (float) 1/3 << std::endl;
                      std::cout << 1/3.f << std::endl;
                      std::cout << 1/3 << std::endl;
                  }
                  

                  .f 是否像演员表一样使用?有什么地方可以让我详细了解这种有趣的语法吗?

                  Is the .f used like a cast? Is there a place where I can read more about this interesting syntax?

                  推荐答案

                  没有 .f 数字被解释为整数,因此 1/3(int)1/(int)3 => (int)0 而不是所需的 (float)0.333333..f 告诉编译器将文字解释为 float 类型的浮点数.还有其他这样的结构,例如 0UL 表示 (unsigned long)0,而普通的 0 将是 (int)0.

                  Without the .f the number gets interpreted as an integer, hence 1/3 is (int)1/(int)3 => (int)0 instead of the desired (float)0.333333. The .f tells the compiler to interpret the literal as a floating point number of type float. There are other such constructs such as for example 0UL which means a (unsigned long)0, whereas a plain 0 would be an (int)0.

                  .f 实际上是两个组件,. 表示文字是浮点数而不是整数,fcode> 后缀,它告诉编译器文字应该是 float 类型,而不是用于浮点文字的默认 double 类型.

                  The .f is actually two components, the . which indicates that the literal is a floating point number rather than an integer, and the f suffix which tells the compiler the literal should be of type float rather than the default double type used for floating point literals.

                  免责声明;上面解释中使用的强制转换结构"并不是实际的强制转换,而只是表示文字类型的一种方式.

                  Disclaimer; the "cast construct" used in the above explanation is not an actual cast, but just a way to indicate the type of the literal.

                  如果你想知道所有关于文字和你可以在其中使用的后缀,你可以阅读 C++ 标准,(1997 年草案,C++11 草案,C++14 草案,C++17 草案) 或者,看看一本像样的教科书,例如 Stroustrup 的 C++ 编程语言.

                  If you want to know all about literals and the suffixes you can use in them, you can read the C++ standard, (1997 draft, C++11 draft, C++14 draft, C++17 draft) or alternatively, have a look at a decent textbook, such as Stroustrup's The C++ Programming Language.

                  顺便说一句,在您的示例 (float)1/3 中,文字 13 实际上是整数,但 1 是首先由您的演员转换为浮点数,然后 3 隐式转换为浮点数,因为它是浮点运算符的右侧操作数.(运算符是浮点数,因为它的左手操作数是浮点数.)

                  As an aside, in your example (float)1/3 the literals 1 and 3 are actually integers, but the 1 is first cast to a float by your cast, then subsequently the 3 gets implicitly cast to a float because it is a righthand operand of a floating point operator. (The operator is floating point because its lefthand operand is floating point.)

                  这篇关于“.f"的目的附加到一个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                  <i id='1bPi9'><tr id='1bPi9'><dt id='1bPi9'><q id='1bPi9'><span id='1bPi9'><b id='1bPi9'><form id='1bPi9'><ins id='1bPi9'></ins><ul id='1bPi9'></ul><sub id='1bPi9'></sub></form><legend id='1bPi9'></legend><bdo id='1bPi9'><pre id='1bPi9'><center id='1bPi9'></center></pre></bdo></b><th id='1bPi9'></th></span></q></dt></tr></i><div id='1bPi9'><tfoot id='1bPi9'></tfoot><dl id='1bPi9'><fieldset id='1bPi9'></fieldset></dl></div>
                    <tfoot id='1bPi9'></tfoot>
                            <tbody id='1bPi9'></tbody>

                          <small id='1bPi9'></small><noframes id='1bPi9'>

                        • <legend id='1bPi9'><style id='1bPi9'><dir id='1bPi9'><q id='1bPi9'></q></dir></style></legend>
                            <bdo id='1bPi9'></bdo><ul id='1bPi9'></ul>