首页 > 编程语言 >C++将角度转为复数

C++将角度转为复数

时间:2023-10-06 18:45:20浏览次数:36  
标签:std pi cout float C++ 复数 theta include 转为

  • 1.角度转复数,使用std::polar
#include <iostream>
#include <complex>
#include <cmath>

int main () {
   float theta = 45;
   float theta_pi = theta*(M_PI/180); 
   std::cout << " is " << std::polar (1.0f, theta_pi) << '\n';

   return 0;
}
  • 2.角度转复数,使用cos+i*sin
#include <iostream>
#include <complex>
#include <cmath>

int main () {
   double theta = 45;
   double theta_pi = theta*(M_PI/180);
   std::complex<double> rst;
   std::complex<double> I = std::complex<double>(0.0f, 1.0f);
   rst = cos(theta_pi) + I*sin(theta_pi);
   std::cout << " is " << rst << '\n';
   return 0;
}
  • 3.角度转复指数,使用C库<complex.h>中的_Complex_I
#include <iostream>
#include <complex.h>
#include <cmath>

int main () {
   float theta = 45;
   float theta_pi = theta*(M_PI/180);
   std::cout << " is " << std::exp(_Complex_I * theta_pi);

   return 0;
}
  • 4.角度转复指数,使用(0,1)表示虚数单位
#include <iostream>
#include <complex>
#include <cmath>

int main () {
   float theta = 45;
   float theta_pi = theta*(M_PI/180);
   std::cout << " is " << std::exp(std::complex<float>(0, 1) * theta_pi);

   return 0;
}

标签:std,pi,cout,float,C++,复数,theta,include,转为
From: https://www.cnblogs.com/judes/p/17744823.html

相关文章

  • 十四天学会C++之第四天(面向对象编程基础)
    类和对象是什么?在C++中,类是一种用户定义的数据类型,它可以包含数据成员(也就是属性)和成员函数(也就是方法)。类是一种模板或蓝图,用于创建具体的对象。对象是类的实例,它是根据类的定义创建的,可以用来表示现实世界中的各种事物。对象具有类定义的属性和行为。面向对象编程思想面向对象编......
  • C++断言之assert和static_assert的区别
    C++断言之assert和static_assert的区别参考链接:c++11:static_assert与assert_夜夜夜夜-CSDN博客_static_assert断言分为动态断言和静态断言2种。c++11引入了static_assert关键字,用来实现编译期间的断言,叫静态断言。1.static_assert静态断言static_assert(常量表达式,要提示......
  • C++ 信号
    信号概念信号是Linux进程间通信的一种机制,是软件层次上对中断的一种模拟,用在进程之间的传递消息。来源内核产生内存错误,除0错误等由其他进程产生,传递给目标进程kill信号自定义信号:SIGURG硬件产生键盘处理方式发送阶段内核将信号放到对应的pendi......
  • C++算法之旅、08 基础篇 | 质数、约数
    质数在>1的整数中,如果只包含1和本身这两个约数,就被称为质数(素数)866试除法判定866.试除法判定质数-AcWing题库\(O(n)\)boolisprime(intx){if(x<2)returnfalse;for(inti=2;i<x;i++)if(x%i==0)returnfalse;returntrue;......
  • 14_C++对c的扩展
    c++对c的扩展::作用域运算符::使用全局变量usingnamespacestd;inta=10;voidtest01(){inta=20;cout<<a<<endl;//20cout<<::a<<endl;//10}命名空间namespacenamespace和c语言中static只在本源文件中有效差不多命名空间使用语法创建一......
  • C++ 数据结构插入效率学习
    转自:https://blog.csdn.net/breaksoftware/article/details/829478381.总结在头部插入。元素数量>15k时,效率unordered_set>set,unordered_map>map。元素数量<1024时,效率unordered_set>set,map> unordered_map。元素数量<256时,效率unordered_set>set,map> unorder......
  • C++ namespace User_Unauthorized version 1.0.0 is officially released
    CodenamespaceUser_Unauthorized{/***@briefThisisaheaderfileforcompetitiveprogramming.*@authorUser-Unauthorized*@version1.0.0*@date2023-10-5*/typedeflonglongvalueType;typedefstd::vector<......
  • 将np.datetime64的时间差转为秒
    print((np.datetime64('2023-01-0200:00:00')-np.datetime64('2023-01-0100:00:00'))/np.timedelta64(1,'s'),(pd.Series(np.datetime64('2023-01-0200:00:00'))-pd.Series(np.datetime64('2023-01-0100:0......
  • C++ Profiler Introduction [CPU Time Only]
    C++ProfilerIntroduction[CPUTimeOnly]author:LastWhisperdate:2023/10/05ThereareseveralprofilersforC++.Basedonmyresearch,I'vefoundthattracyisthemostpowerful.However,it'schallengingtoconfigure.Toquicklybenchmark......
  • C/C++学习 -- HMAC算法
    1.HMAC算法概述HMAC,全称为HMAC-MD5、HMAC-SHA1、HMAC-SHA256等,是一种在数据传输中验证完整性和认证来源的方法。它结合了哈希函数和密钥,通过在数据上应用哈希函数,生成一个带密钥的散列值,用于验证数据的完整性。HMAC算法广泛应用于网络协议、数字签名、认证和访问控制等领域。2.HM......