#include <ccomplex>

C++ 标准库中的 <complex> 头文件提供了对复数的支持。复数是实数和虚数的组合,通常表示为 a + bi,其中 a 是实部,b 是虚部,i 是虚数单位,满足 i^2 = -1

在 C++ 中,复数类型由 std::complex<T> 表示,其中 T 可以是任意的算术类型,如 floatdouble 或 long double

// <ccomplex> -*- C++ -*-

// Copyright (C) 2007-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file include/ccomplex
 *  This is a Standard C++ Library header.
 */

#pragma GCC system_header

#ifndef _GLIBCXX_CCOMPLEX
#define _GLIBCXX_CCOMPLEX 1

#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#endif

extern "C++" {
#include <complex>
}

#endif

创建复数

std::complex<double> c(5.0, 3.0); // 创建一个复数 5 + 3i

访问实部和虚部

double realPart = c.real(); // 获取实部
double imagPart = c.imag(); // 获取虚部

复数的基本运算

C++ 标准库 <complex> 支持以下基本运算:

  • 加法:operator+
  • 减法:operator-
  • 乘法:operator*
  • 除法:operator/
  • 共轭:conj
  • 模:abs
  • 辐角:arg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值