Why C++ pow(10, 5) = 9999 ? (double type, FPU, SSE)

The question is coming from Why pow(10,5) = 9,999 in C++ in StackOverflow.

Environment

  • OS: Win8.1, 64bit
  • IDE: Code::Blocks 13.12

Code:

const int num = 10;

    for(int i = 0; i < 5; ++i){
        int res = pow(num, i);
    cout << res << endl;
    }

Wrong result:

1
10
99
1000
9999

Why?

继续阅读Why C++ pow(10, 5) = 9999 ? (double type, FPU, SSE)

Code::Blocks 12.11 error: ‘nullptr’ was not declared in this scope&GNU GCC -std=gnu++0x

C++primer英文版(第五版)p54 Null Pointers章节:Modern C++ programs generally should avoid using NULL and use nullptr instead.本人通俗理解为指针初始化尽量用nullptr而避免用NULL。于是乎用Code::Blocks敲敲代码,问题来了。

error: ‘nullptr’ was not declared in this scope

于是网上Google答案,一大堆英文,最后大概了解到是GNU GCC编译器的问题,而不是Code::Blocks这个IDE问题,只需要在编译器里敲入命令行-std=gnu++0x。解决方法:Code::Blocks集成了GNU GCC编译器,所以 菜单栏->Setting->compiler…,选择Global compiler settings页面,页面上部selected compiler选择GNU GCC Comiler,然后页面选择中部选择Compiler settings->Compiler Flags,勾选Have g++ follow the coming C++0x ISO C++ language standard [-std=gnu++0x],图片一切明了:

GNU GCC -std=gnu++0x

好了,接下来再编译就成功啦!O(∩_∩)O~