_imaginary usage in c language

下次还敢
Release: 2024-05-09 09:48:18
Original
383 people have browsed it

In C language, the _imaginary macro is used to obtain the imaginary part of a complex number. The usage is as follows: declare a complex variable in the format a bi (a is the real part, b is the imaginary part). Use the _imaginary(z) function to get the imaginary part of the complex number z. The _imaginary function returns type double even if the input complex number is of type complex float.

_imaginary usage in c language

Usage of _imaginary in C language

In C language, _imaginary is A macro used to represent the imaginary part of complex numbers. Its usage is as follows:

Format:

<code class="c">#include <complex.h>

double _imaginary(complex double z);
float _imaginary(complex float z);</code>
Copy after login

Parameters:

  • z: A complex number represented as a bi, where a is the real part and b is the imaginary part.

Return value:

  • b, the imaginary part of the complex number z.

Example:

<code class="c">#include <complex.h>

int main() {
    complex double z = 3.0 + 4.0i;

    // 获取虚部
    double imaginary_part = _imaginary(z);

    // 输出虚部
    printf("虚部:%f\n", imaginary_part);

    return 0;
}</code>
Copy after login

Output:

<code>虚部:4.000000</code>
Copy after login

Notes:

  • _imaginary can only be used for complex numbers, not real numbers. The result of
  • _imaginary is always of type double, even if the input complex number is of type complex float.

The above is the detailed content of _imaginary usage in c language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!