How to use complex number “i” in C++

后端 未结 6 852
暗喜
暗喜 2021-02-06 08:19

I am coding a simple DFT algorithm now and I want to use the complex number i in complex exponential. I saw somebody use #include and #include&

6条回答
  •  爱一瞬间的悲伤
    2021-02-06 09:03

    pi, being an irrational number, cannot be exactly represented by a double. cos of an inexact approximation of pi is likely to yield a result which is close to but perhaps not exactly 1. Likewise sin of an inexact approximation of an inexact approximation of pi is like to result in a number is has a very small magnitude that is perhaps not exactly 0. Why not just define I to be std::complex(0.0, 1.0) and avoid the gratuitous inexactness.

提交回复
热议问题