当前位置:网站首页>[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;
}
边栏推荐
- 第四大运营商,难成「鲶鱼」
- [spatial & single cellomics] phase 1: Study on PDAC tumor microenvironment by single cell binding spatial transcriptome
- Conversion between pointcloud and numpy arrays in open3d
- 荐书丨《大脑通信员》:如果爱情只是化学反应,那还能相信爱情吗?
- 快手投资电商服务商易心优选
- PMP真的有用吗?
- Combined sum leetcode
- dolphinscheduler2.X的安装(亲测有效)
- [collection of excellent articles on Digital IC] nearly 500 articles | learning route | basic knowledge | interface | bus | scripting language | chip job search | security | EDA | tools | low power de
- Rails advanced -- framework theory cognition and construction scheme construction (I)
猜你喜欢
成龙和快品牌,谁才是快手的救星?
Tencent cloud international ECS has no network after logging in. How to troubleshoot?
运行近20年,基于Win 98的火星探测器软件迎来首次升级
dolphinscheduler2. Installation of X (valid for personal test)
Steve Jobs of the United States, died; China jobs, sold
3. caller service call - dapr
老板囑咐了三遍:低調、低調、低調
名创优品通过上市聆讯:寻求双重主要上市 年营收91亿
干货 | 科研人的KPI怎么算,H指数和G指数是什么
安杰思医学冲刺科创板:年营收3亿 拟募资7.7亿
随机推荐
Angers medical sprint scientific innovation board: annual revenue of RMB 300million and proposed fund raising of RMB 770million
Vector explanation + topic
2022金属非金属矿山安全检查(地下矿山)复训题库及在线模拟考试
Technical trendsetter
Opening and closing principle
推荐四款可视化工具,解决 99% 的可视化大屏项目!
字节跳动埋点数据流建设与治理实践
vector详解+题目
Which securities company is the largest and safest? How to open an account is the safest
Leetcode(167)——两数之和 II - 输入有序数组
2022 Chinese cook (Advanced) test questions and online simulation test
Dry goods | how to calculate the KPI of scientific researchers, and what are the h index and G index
老板囑咐了三遍:低調、低調、低調
[MySQL learning notes 24] index design principles
2022年最新PyCharm激活破解码永久_详细安装教程(适用多版本)
openGauss内核:SQL解析过程分析
Maingene listed on the Hong Kong Stock Exchange: IPO with a market value of HK $4.3 billion was ignored by the market
美因基因港交所上市:市值43亿港元 IPO被市场忽略
How to solve the following problems in the Seata database?
10 key points to effectively improve performance interview