V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
taotian
V2EX  ›  C++

求助: C++ std::polar 函数在 macOS 下的奇怪表现

  •  
  •   taotian · 2022-03-29 19:32:12 +08:00 · 1317 次点击
    这是一个创建于 729 天前的主题,其中的信息可能已经有所发展或是发生改变。

    同样的一段简单代码,我在 mac 本地运行与在 cpp.sh 运行结果完全不同:

    本地:

    cpp.sh

    代码是这样的:

    // Example program
    #include <iostream>
    #include <complex>
    
    using namespace std;
    
    int main()
    {
    
      complex<double> res;
    
      res = std::polar(-0.01220608002543111,1.5173900856275251);
    
      cout << res;
    
    }
    
    ``
    2 条回复    2022-03-29 19:38:01 +08:00
    111qqz
        1
    111qqz  
       2022-03-29 19:36:33 +08:00   ❤️ 1
    "The behavior is undefined if r is negative or NaN, or if theta is infinite."
    https://en.cppreference.com/w/cpp/numeric/complex/polar
    taotian
        2
    taotian  
    OP
       2022-03-29 19:38:01 +08:00
    @111qqz 嗯刚自己搜了下也发现了。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5442 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 08:39 · PVG 16:39 · LAX 01:39 · JFK 04:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.