当前位置:网站首页>[C language] how to implement plural types
[C language] how to implement plural types
2022-06-28 14:50:00 【Jia Pu】
First statement : stay C99 Plural types are already supported in the standard .
Don't talk about this here , If you want to know something, you can check it directly , Let's talk about the implementation of complex types and operations . It's also very simple , Directly defining a simple structure and related arithmetic functions is OK 了 .
Here is the implementation process :
#include "stdio.h"
#define Real(c) (c).real
#define Imag(c) (c).imag
typedef struct {
double real;
double imag;
}complex;
complex cpx_make(double real, double imag)
{
complex ret;
ret.real = real;
ret.imag = imag;
return ret;
}
complex cpx_add(complex a, complex b)
{
return cpx_make(Real(a) + Real(b), Imag(a) + Imag(b));
}
int main()
{
complex a = cpx_make(1, 2);
complex b = cpx_make(3, 4);
// It can also be written directly as follows
printf("%f", cpx_add(cpx_make(1, 2), cpx_make(3, 4)));
return 0;
}
边栏推荐
- 股票开户优惠链接,我如何才能得到?手机开户是安全么?
- Could you tell me whether the batch addition of Oracle such as insert all was not blocked?
- 物联网低代码平台常用《组件介绍》
- 2022 operation of simulation test platform for 100 simulated questions of main principals of metal and nonmetal mines (underground mines)
- 成龙和快品牌,谁才是快手的救星?
- Softing epGate PB系列网关-可将PROFIBUS总线集成到EtherNet/IP网络
- [Zhongyi Xinsheng] 5 SPI interface test TF Card
- 324. 摆动排序 II : 不简单的构造题
- 名创优品通过上市聆讯:寻求双重主要上市 年营收91亿
- 3. caller service call - dapr
猜你喜欢

IonQ联合GE Research证实:量子计算在风险聚合上有巨大潜力
![[Zhongyi Xinsheng] 5 SPI interface test TF Card](/img/d9/56ded362b3055f4f0efc3ce0eec5d5.jpg)
[Zhongyi Xinsheng] 5 SPI interface test TF Card

智联招聘基于 Nebula Graph 的推荐实践分享

坐拥1200亿,她又要IPO敲钟了

Construction and management practice of ByteDance buried point data flow

Softing epgate Pb series Gateway - integrates the Profibus bus into the ethernet/ip network

Le patron a donné trois ordres: discret, discret, discret

Is PMP really useful?

Practice of constructing ten billion relationship knowledge map based on Nebula graph

Steve Jobs of the United States, died; China jobs, sold
随机推荐
open3d里pointcloud和numpy数组之间的转化
code snippet
Four visualization tools are recommended to solve 99% of large screen visualization projects!
How can I get the stock account opening discount link? Is it safe to open a mobile account?
优巨新材冲刺深交所:拟募资6.5亿 年营收3.33亿
How to solve the following problems in the Seata database?
2022 Chinese cook (Advanced) test questions and online simulation test
functools:对callable对象的高位函数和操作(持续更新ing...)
Numbers that only appear once
【mysql学习笔记23】索引优化
Only four breakthrough Lenovo smart Summer Palace in mainland China won the "IDC Asia Pacific Smart City Award in 2022"
Steve Jobs of the United States, died; China jobs, sold
Vector explanation + topic
动力电池,是这样被“瓜分”的
2022中式烹調師(高級)試題及在線模擬考試
物联网低代码平台常用《组件介绍》
华泰证券app 怎么办理开户最安全
荐书丨《大脑通信员》:如果爱情只是化学反应,那还能相信爱情吗?
Recommended practice sharing of Zhilian recruitment based on Nebula graph
What are the benefits of this PMP certificate?