当前位置:网站首页>[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;
}
边栏推荐
- 华泰证券开户有什么后果 怎么办理开户最安全
- code snippet
- Unable to create process using 'd:\program file
- 加油站(贪心)
- Research and Simulation of chaotic digital image encryption technology based on MATLAB
- Gas station (greedy)
- The boss told me three times: low key, low key, low key
- vector详解+题目
- 猫狗图像数据集上的深度学习模型性能对比
- Which is safer, a securities company or a bank? How to open an account is the safest
猜你喜欢

干货 | 科研人的KPI怎么算,H指数和G指数是什么

Flutter series: offstage in flutter
Technical trendsetter

Opengauss kernel: analysis of SQL parsing process

Ionq and Ge research confirmed that quantum computing has great potential in risk aggregation

从小小线虫谈起——溯源神经系统进化,开启生命模拟

Recommendation letter brain correspondent: if love is just a chemical reaction, can you still believe in love?

美国乔布斯,殁了;中国乔布斯,卖了

Maingene listed on the Hong Kong Stock Exchange: IPO with a market value of HK $4.3 billion was ignored by the market
![[Zhongyi Xinsheng] 5 SPI interface test TF Card](/img/d9/56ded362b3055f4f0efc3ce0eec5d5.jpg)
[Zhongyi Xinsheng] 5 SPI interface test TF Card
随机推荐
Calculator (force buckle)
机器人的运动范围(DFS)
dolphinscheduler2.X的安装(亲测有效)
考了这个PMP证书到底有什么好处?
Send2vec tutorial
324. 摆动排序 II : 不简单的构造题
美因基因港交所上市:市值43亿港元 IPO被市场忽略
Foreign trade SEO Webmaster Tools
Single responsibility principle
使用LamdbaUpdateWrapper的setSql作用及风险
Differences between ram ROM flash
Tencent was underweight again by prosus, the major shareholder: the latter also cashed out $3.7 billion from JD
2022金属非金属矿山(地下矿山)主要负责人考试模拟100题模拟考试平台操作
老板囑咐了三遍:低調、低調、低調
Robot range of motion (DFS)
Summary of technical difficulties of wearable neural signal and behavior data detection and recording system for birds in flight
成龙和快品牌,谁才是快手的救星?
腾讯再遭大股东Prosus减持:后者还从京东套现37亿美元
The boss told me three times: low key, low key, low key
Kwai investment e-commerce service provider Yixin optimization