V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
taotian
V2EX  ›  C++

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

  •  
  •   taotian · Mar 29, 2022 · 2254 views
    This topic created in 1489 days ago, the information mentioned may be changed or developed.

    同样的一段简单代码,我在 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 replies    2022-03-29 19:38:01 +08:00
    midasplus
        1
    midasplus  
       Mar 29, 2022   ❤️ 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
       Mar 29, 2022
    @111qqz 嗯刚自己搜了下也发现了。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5544 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:57 · PVG 13:57 · LAX 22:57 · JFK 01:57
    ♥ Do have faith in what you're doing.