taotian
V2EX  ›  C++

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

  •  
  •   taotian · Mar 29, 2022 · 2794 views
    This topic created in 1685 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
    midasplus
    Mar 29, 2022❤️1
    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
    taotian
    OP
    Mar 29, 2022
    2
    @111qqz 嗯刚自己搜了下也发现了。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1608 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:54 · PVG 20:54 · LAX 04:54 · JFK 07:54
    ♥ Do have faith in what you're doing.