当前位置:网站首页>[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;
}
边栏推荐
- Which securities company is the largest and safest? How to open an account is the safest
- [spatial & single cellomics] phase 1: Study on PDAC tumor microenvironment by single cell binding spatial transcriptome
- Quantum frontier hero spectrum - "light quantum Explorer" McMahon: turning any physical system into a neural network
- 2022 questions d'examen pour les cuisiniers chinois (Senior) et l'examen de simulation en ligne
- 2022 Chinese cook (Advanced) test questions and online simulation test
- Does Frankfurt currently support SQL?
- Leetcode(406)——根据身高重建队列
- How can I get the stock account opening discount link? Is it safe to open a mobile account?
- Mingchuangyou products passed the listing hearing: seeking dual main listing with an annual revenue of 9.1 billion
- dolphinscheduler2.X的安装(亲测有效)
猜你喜欢

QQ被盗号后群发黄图,大批用户“社死”

Performance comparison of deep learning models on cat and dog image data sets

IonQ联合GE Research证实:量子计算在风险聚合上有巨大潜力

Steve Jobs of the United States, died; China jobs, sold

Jingyuan's safe sprint to the Growth Enterprise Market: it plans to raise 400million yuan for investment and Yunyou software is the shareholder

Construction and management practice of ByteDance buried point data flow

量子前沿英雄谱|“光量子探险家”McMahon:将任何物理系统变成神经网络

【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境

Introduction to common components of IOT low code platform

Recommended practice sharing of Zhilian recruitment based on Nebula graph
随机推荐
open3d里pointcloud和numpy数组之间的转化
dolphinscheduler2. Installation of X (valid for personal test)
[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
Opengauss kernel: analysis of SQL parsing process
Leetcode(88)——合并两个有序数组
证券公司和银行哪个更安全 怎么办理开户最安全
【空间&单细胞组学】第1期:单细胞结合空间转录组研究PDAC肿瘤微环境
Opening and closing principle
2022中式烹调师(高级)试题及在线模拟考试
物联网低代码平台常用《组件介绍》
[Zhongyi Xinsheng] 5 SPI interface test TF Card
字节跳动埋点数据流建设与治理实践
老板嘱咐了三遍:低调、低调、低调
华泰证券app 怎么办理开户最安全
Differences between ram ROM flash
第四大运营商,难成「鲶鱼」
Vscode writes markdown file and generates pdf
Combined sum leetcode
Flutter series: offstage in flutter
【数字IC精品文章收录】近500篇文章|学习路线|基础知识|接口|总线|脚本语言|芯片求职|安全|EDA|工具|低功耗设计|Verilog|低功耗|STA|设计|验证|FPGA|架构|AMBA|书籍|