📄 complex.c
字号:
/*
* *************************************************************************
* * *
* * This confidential and proprietary software may be used only *
* * as authorized by a licensing agreement from the Alta Group of *
* * Cadence Design Systems, Inc. In the event of publication, the *
* * following notice is applicable: *
* * *
* * (c) COPYRIGHT 1995 ALTA GROUP OF CADENCE DESIGN SYSTEMS, INC. *
* * ALL RIGHTS RESERVED *
* * *
* * The entire notice above must be reproduced on all authorized *
* * copies. *
* * *
* *************************************************************************
*
*/
/*
* FILE: complex.c
* DATE: Feb. 19, 1990
* RELATED FILES:
* AUTHOR: John Lundell
* DESCRIPTION:
* Complex math support functions
*
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
#include "cgs.h"
/*
* Functions
*/
/*---------------------------------------------------------------
* FUNCTION: c_add
* DESCRIPTION:
* Add two complex numbers
*
* RETURN VALUE: The complex sum
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
Complex c_add(s_c1, s_c2)
Complex s_c1, s_c2;
{
s_c1.real += s_c2.real;
s_c1.imag += s_c2.imag;
return s_c1;
}
/*---------------------------------------------------------------
* FUNCTION: c_sub
* DESCRIPTION:
* Subtract two complex numbers.
*
* RETURN VALUE: The complex difference
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
Complex c_sub(s_c1, s_c2)
Complex s_c1, s_c2;
{
s_c1.real -= s_c2.real;
s_c1.imag -= s_c2.imag;
return s_c1;
}
/*---------------------------------------------------------------
* FUNCTION: c_conj
* DESCRIPTION:
* Take the complex conjugate of a complex number
*
* RETURN VALUE: The complex conjugate.
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
Complex c_conj(s_c)
Complex s_c;
{
s_c.imag = -s_c.imag;
return s_c;
}
/*---------------------------------------------------------------
* FUNCTION: c_mag
* DESCRIPTION:
* Take the complex magnitude.
*
* RETURN VALUE: The complex magnitude.
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
double c_mag(s_c)
Complex s_c;
{
return sqrt(s_c.real * s_c.real + s_c.imag * s_c.imag);
}
/*---------------------------------------------------------------
* FUNCTION: c_mul
* DESCRIPTION:
* Multiply two complex numbers
*
* RETURN VALUE: The complex product.
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
Complex c_mul(s_c1, s_c2)
Complex s_c1, s_c2;
{
Complex ret;
ret.real = s_c1.real * s_c2.real - s_c1.imag * s_c2.imag;
ret.imag = s_c1.real * s_c2.imag + s_c1.imag * s_c2.real;
return ret;
}
/*---------------------------------------------------------------
* FUNCTION: c_dvd
* DESCRIPTION:
* Divide two complex numbers
*
* RETURN VALUE: The complex quotient
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
Complex c_dvd(s_c1, s_c2)
Complex s_c1, s_c2;
{
Complex ret;
double den = 1.0 / (s_c2.real * s_c2.real + s_c2.imag * s_c2.imag);
ret.real = (s_c1.real * s_c2.real + s_c1.imag * s_c2.imag) * den;
ret.imag = (s_c1.imag * s_c2.real - s_c1.real * s_c2.imag) * den;
return ret;
}
/*---------------------------------------------------------------
* FUNCTION: c_sqrt
* DESCRIPTION:
* Square root of a complex number.
*
* RETURN VALUE: Complex square root.
* NOTES/WARNINGS:
* REVISION HISTORY:
* Release Who Date Comments
*/
Complex c_sqrt(s_v)
Complex s_v;
{
double theta = 0.5 * atan2(s_v.imag, s_v.real);
double radius = sqrt(sqrt(s_v.real * s_v.real + s_v.imag * s_v.imag));
/*
* Get the square root from the complex plane value
*/
s_v.real = radius * cos(theta);
s_v.imag = radius * sin(theta);
return s_v;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -