Z is complexis a magic numberr

Z is complex number_百度知道
Z is complex number
3/modules z是不是等于modulos(3/z)
提问者评价
太给力了,你的回答完美地解决了我的问题,非常感谢!
来自团队:
其他类似问题
为您推荐:
number的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁<plex - D Programming Language
experimental
If you spot a problem with this page, click here to create a Bugzilla issue.
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
This module contains the
type, which is used to represent
complex numbers, along with related mathematical operations and functions.
will eventually
the built-in types cfloat, cdouble, creal, ifloat,
idouble, and ireal.
Authors: Lars Tandle Kyllingstad, Don Clugston
pure nothrow @nogc @safe auto complex(R)(R re)if (is(R : double));
pure nothrow @nogc @safe auto complex(R, I)(R re, I im)if (is(R : double) && is(I : double));
Helper function that returns a complex number with the specified
real and imaginary parts.
Parameters: R
(template parameter) type of real part of complex number
(template parameter) type of imaginary part of complex number
real part of complex number to be constructed
(optional) imaginary part of complex number
Returns: Complex instance with real and imaginary parts set
to the values provided as input.
If neither re nor
im are floating-point numbers, the return type will
be Complex!double.
Otherwise, the return type is
deduced using monType!(R, I).
auto a = complex(1.0);
static assert (is(typeof(a) == Complex!double));
assert (a.re == 1.0);
assert (a.im == 0.0);
auto b = complex(2.0L);
static assert (is(typeof(b) == Complex!real));
assert (b.re == 2.0L);
assert (b.im == 0.0L);
auto c = complex(1.0, 2.0);
static assert (is(typeof(c) == Complex!double));
assert (c.re == 1.0);
assert (c.im == 2.0);
auto d = complex(3.0, 4.0L);
static assert (is(typeof(d) == Complex!real));
assert (d.re == 3.0);
assert (d.im == 4.0L);
auto e = complex(1);
static assert (is(typeof(e) == Complex!double));
assert (e.re == 1);
assert (e.im == 0);
auto f = complex(1L, 2);
static assert (is(typeof(f) == Complex!double));
assert (f.re == 1L);
assert (f.im == 2);
auto g = complex(3, 4.0L);
static assert (is(typeof(g) == Complex!real));
assert (g.re == 3);
assert (g.im == 4.0L);
struct Complex(T) if (isFloatingPoint!T);
A complex number parametrised by a type T, which must be either
float, double or real.
The real part of the number.
The imaginary part of the number.
const string toString();
const void toString(Char)(scope void delegate(const(Char)[]) sink, FormatSpec!Char formatSpec);
Converts the complex number to a string representation.
The second form of this function is usually
instead, it is used via , as shown in the examples
Supported format characters are 'e', 'f', 'g', 'a', and 's'.
documentation for more information.
auto c = complex(1.2, 3.4);
assert(c.toString() == "1.2+3.4i");
import std.format :
assert(format("%.2f", c)
== "1.20+3.40i");
assert(format("%4.1f", c) == " 1.2+ 3.4i");
pure nothrow @nogc @safe T abs(T)(Complex!T z);
Parameters: Complex!T z
A complex number.
Returns: The absolute value (or modulus) of z.
static import std.
assert (abs(complex(1.0)) == 1.0);
assert (abs(complex(0.0, 1.0)) == 1.0);
assert (abs(complex(1.0L, -2.0L)) == std.math.sqrt(5.0L));
pure nothrow @nogc @safe T sqAbs(T)(Complex!T z);
pure nothrow @nogc @safe T sqAbs(T)(T x)if (isFloatingPoint!T);
Parameters: Complex!T z
A complex number.
A real number.
Returns: The squared modulus of z.
For genericity, if called on a real number, returns its square.
import std.
assert (sqAbs(complex(0.0)) == 0.0);
assert (sqAbs(complex(1.0)) == 1.0);
assert (sqAbs(complex(0.0, 1.0)) == 1.0);
assert (approxEqual(sqAbs(complex(1.0L, -2.0L)), 5.0L));
assert (approxEqual(sqAbs(complex(-3.0L, 1.0L)), 10.0L));
assert (approxEqual(sqAbs(complex(1.0f,-1.0f)), 2.0f));
pure nothrow @nogc @safe T arg(T)(Complex!T z);
Parameters: Complex!T z
A complex number.
Returns: The argument (or phase) of z.
import std.
assert (arg(complex(1.0)) == 0.0);
assert (arg(complex(0.0L, 1.0L)) == PI_2);
assert (arg(complex(1.0L, 1.0L)) == PI_4);
pure nothrow @nogc @safe Complex!T conj(T)(Complex!T z);
Parameters: Complex!T z
A complex number.
Returns: The complex conjugate of z.
assert (conj(complex(1.0)) == complex(1.0));
assert (conj(complex(1.0, 2.0)) == complex(1.0, -2.0));
pure nothrow @nogc @safe Complex!(CommonType!(T, U)) fromPolar(T, U)(T modulus, U argument);
Constructs a complex number given its absolute value and argument.
Parameters: T modulus
The modulus
U argument
The argument
Returns: The complex number with the given modulus and argument.
import std.
auto z = fromPolar(std.math.sqrt(2.0), PI_4);
assert (approxEqual(z.re, 1.0L, real.epsilon));
assert (approxEqual(z.im, 1.0L, real.epsilon));
pure nothrow @nogc @safe Complex!T sin(T)(Complex!T z);
pure nothrow @nogc @safe Complex!T cos(T)(Complex!T z);
Trigonometric functions on complex numbers.
Parameters: Complex!T z
A complex number.
Returns: The sine and cosine of z, respectively.
static import std.
assert(sin(complex(0.0)) == 0.0);
assert(sin(complex(2.0L, 0)) == std.math.sin(2.0L));
import std.
assert(cos(complex(0.0)) == 1.0);
assert(cos(complex(1.3L)) == std.math.cos(1.3L));
assert(cos(complex(0, 5.2L)) == cosh(5.2L));
pure nothrow @nogc @trusted Complex!real expi(real y);
Parameters: real y
A real number.
Returns: The value of cos(y) + i sin(y).
expi is included here for convenience and for easy migration of code
that uses .
Unlike , which uses the
x87 fsincos instruction when possible, this function is no faster
than calculating cos(y) and sin(y) separately.
static import std.
assert(expi(1.3e5L) == complex(std.math.cos(1.3e5L), std.math.sin(1.3e5L)));
assert(expi(0.0L) == 1.0L);
auto z1 = expi(1.234);
auto z2 = std.math.expi(1.234);
assert(z1.re == z2.re && z1.im == z2.im);
pure nothrow @nogc @safe Complex!T sqrt(T)(Complex!T z);
Parameters: Complex!T z
A complex number.
Returns: The square root of z.
static import std.
assert (sqrt(complex(0.0)) == 0.0);
assert (sqrt(complex(1.0L, 0)) == std.math.sqrt(1.0L));
assert (sqrt(complex(-1.0L, 0)) == complex(0, 1.0L));}

我要回帖

更多关于 complex number wiki 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信