英語版
このページの英語版を見る

std.complex

このモジュールには Complex型が含まれている。 このモジュールには、複素数を表現するために使用される型と、関連する数学演算と関数が含まれている。
Complexいずれは を置き換える 組み込み型cfloat,cdouble,creal,ifloatidouble およびireal
Authors:
Lars Tandle Kyllingstad, Don Clugston

ソース std/complex.d

pure nothrow @nogc @safe auto complex(R)(const R re)
if (is(R : double));

pure nothrow @nogc @safe auto complex(R, I)(const R re, const I im)
if (is(R : double) && is(I : double));
指定された実部と虚部を持つ複素数を返すヘルパー関数。 を返すヘルパー関数。
Parameters:
R (テンプレートパラメータ) 複素数の実部の型。
I (テンプレートパラメータ) 複素数の虚部の型
R re 構成される複素数の実部
I im (オプション) 複素数の虚部、省略時は0。
Returns:
Complex 実部と虚部が を入力として与えられた値に設定する。 もし reimが浮動小数点数でない場合、戻り値の型は はComplex!double となる。 それ以外の場合、戻り値の型は次のようになる。 std.traits.CommonType!(R, I) を使用して推論される。
Examples:
auto a = complex(1.0);
static assert(is(typeof(a) == Complex!double));
writeln(a.re); // 1.0
writeln(a.im); // 0.0

auto b = complex(2.0L);
static assert(is(typeof(b) == Complex!real));
writeln(b.re); // 2.0L
writeln(b.im); // 0.0L

auto c = complex(1.0, 2.0);
static assert(is(typeof(c) == Complex!double));
writeln(c.re); // 1.0
writeln(c.im); // 2.0

auto d = complex(3.0, 4.0L);
static assert(is(typeof(d) == Complex!real));
writeln(d.re); // 3.0
writeln(d.im); // 4.0L

auto e = complex(1);
static assert(is(typeof(e) == Complex!double));
writeln(e.re); // 1
writeln(e.im); // 0

auto f = complex(1L, 2);
static assert(is(typeof(f) == Complex!double));
writeln(f.re); // 1L
writeln(f.im); // 2

auto g = complex(3, 4.0L);
static assert(is(typeof(g) == Complex!real));
writeln(g.re); // 3
writeln(g.im); // 4.0L
struct Complex(T) if (isFloatingPoint!T);
T でパラメタ化された複素数である。 float double またはreal のいずれかでなければならない。
T re;
数の実数部。
T im;
数値の虚部。
const @safe string toString();

const void toString(Writer, Char)(scope Writer w, ref scope const FormatSpec!Char formatSpec)
if (isOutputRange!(Writer, const(Char)[]));
複素数を文字列表現に変換する。
この関数の2番目の形式は、通常は直接呼ばれない; 代わりに std.string.formatを介して使用される。 を介して使用される。 サポートされるフォーマット文字は、'e'、'f'、'g'、'a'、's'である。
以下の std.formatstd.string.format のドキュメントを参照のこと。
Examples:
auto c = complex(1.2, 3.4);

// Vanilla toString フォーマット:
writeln(c.toString()); // "1.2+3.4i"

// std.string.format仕様によるフォーマット: 精度と幅の
// 指定子は、複素数の実数部と虚数部の
// 両方に適用される。
import std.format : format;
writeln(format("%.2f", c)); // "1.20+3.40i"
writeln(format("%4.1f", c)); // " 1.2+ 3.4i"
this(R : T)(Complex!R z);

this(Rx : T, Ry : T)(const Rx x, const Ry y);

this(R : T)(const R r);
指定された実部と虚部を持つ複素数を作る。 虚部を持つ複素数を構成する。複素数でない単一の引数 が渡された場合、結果の虚部はゼロとなる。 ゼロとなる。
auto toNative();
関連するCコンパイラの 型にサイズとABIで対応する複素数インスタンスを返す。 _Complex に対応する複素数のインスタンスを返す。
pure nothrow @nogc @safe T abs(T)(Complex!T z);
Parameters:
Complex!T z 複素数。
Returns:
の絶対値(またはモジュラス)である。 z.
Examples:
static import core.math;
writeln(abs(complex(1.0))); // 1.0
writeln(abs(complex(0.0, 1.0))); // 1.0
writeln(abs(complex(1.0L, -2.0L))); // core.math.sqrt(5.0L)
pure nothrow @nogc @safe T sqAbs(T)(Complex!T z);

pure nothrow @nogc @safe T sqAbs(T)(const T x)
if (isFloatingPoint!T);
Parameters:
Complex!T z 複素数。
T x 実数。
Returns:
の2乗モジュラス。 z. 汎用性のため、実数で呼ばれた場合はその2乗を返す。
Examples:
import std.math.operations : isClose;
writeln(sqAbs(complex(0.0))); // 0.0
writeln(sqAbs(complex(1.0))); // 1.0
writeln(sqAbs(complex(0.0, 1.0))); // 1.0
assert(isClose(sqAbs(complex(1.0L, -2.0L)), 5.0L));
assert(isClose(sqAbs(complex(-3.0L, 1.0L)), 10.0L));
assert(isClose(sqAbs(complex(1.0f,-1.0f)), 2.0f));
pure nothrow @nogc @safe T arg(T)(Complex!T z);
Parameters:
Complex!T z 複素数である。
Returns:
の引数(または位相)。 z.
Examples:
import std.math.constants : PI_2, PI_4;
writeln(arg(complex(1.0))); // 0.0
writeln(arg(complex(0.0L, 1.0L))); // PI_2
writeln(arg(complex(1.0L, 1.0L))); // PI_4
pure nothrow @nogc @safe T norm(T)(Complex!T z);
複素数のノルムを取り出す。
Parameters:
Complex!T z 複素数
Returns:
の2乗の大きさ。 z.
Examples:
import std.math.operations : isClose;
import std.math.constants : PI;
writeln(norm(complex(3.0, 4.0))); // 25.0
writeln(norm(fromPolar(5.0, 0.0))); // 25.0
assert(isClose(norm(fromPolar(5.0L, PI / 6)), 25.0L));
assert(isClose(norm(fromPolar(5.0L, 13 * PI / 6)), 25.0L));
pure nothrow @nogc @safe Complex!T conj(T)(Complex!T z);
Parameters:
Complex!T z 複素数である。
Returns:
の複素共役。 z.
Examples:
writeln(conj(complex(1.0))); // complex(1.0)
writeln(conj(complex(1.0, 2.0))); // complex(1.0, -2.0)
Complex!T proj(T)(Complex!T z);
のリーマン球への射影を返す。 zをリーマン球に投影したものを返す。
Parameters:
Complex!T z 複素数
Returns:
のリーマン球への射影である。 zをリーマン球に投影したものである。
Examples:
writeln(proj(complex(1.0))); // complex(1.0)
writeln(proj(complex(double.infinity, 5.0))); // complex(double.infinity, 0.0)
writeln(proj(complex(5.0, -double.infinity))); // complex(double.infinity, -0.0)
pure nothrow @nogc @safe Complex!(CommonType!(T, U)) fromPolar(T, U)(const T modulus, const U argument);
複素数の絶対値と引数を指定して複素数を構成する。
Parameters:
T modulus モジュラス
U argument 引数
Returns:
与えられたモジュラスと引数を持つ複素数。
Examples:
import core.math;
import std.math.operations : isClose;
import std.math.algebraic : sqrt;
import std.math.constants : PI_4;
auto z = fromPolar(core.math.sqrt(2.0L), PI_4);
assert(isClose(z.re, 1.0L));
assert(isClose(z.im, 1.0L));
pure nothrow @nogc @safe Complex!T sin(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T cos(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T tan(T)(Complex!T z);
複素数上の三角関数。
Parameters:
Complex!T z 複素数。
Returns:
の正弦、余弦、正接。 zそれぞれを表す。
Examples:
static import core.math;
writeln(sin(complex(0.0))); // 0.0
writeln(sin(complex(2.0, 0))); // core.math.sin(2.0)
Examples:
static import core.math;
static import std.math;
writeln(cos(complex(0.0))); // 1.0
writeln(cos(complex(1.3, 0.0))); // core.math.cos(1.3)
writeln(cos(complex(0.0, 5.2))); // std.math.cosh(5.2)
Examples:
static import std.math;

int ceqrel(T)(const Complex!T x, const Complex!T y) @safe pure nothrow @nogc
{
    import std.math.operations : feqrel;
    const r = feqrel(x.re, y.re);
    const i = feqrel(x.im, y.im);
    return r < i ? r : i;
}
assert(ceqrel(tan(complex(1.0, 0.0)), complex(std.math.tan(1.0), 0.0)) >= double.mant_dig - 2);
assert(ceqrel(tan(complex(0.0, 1.0)), complex(0.0, std.math.tanh(1.0))) >= double.mant_dig - 2);
pure nothrow @nogc @safe Complex!T asin(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T acos(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T atan(T)(Complex!T z);
複素数上の逆三角関数。
Parameters:
Complex!T z 複素数。
Returns:
のアークサイン、アークコサイン、アークタンジェント。 zをそれぞれ表す。
Examples:
import std.math.operations : isClose;
import std.math.constants : PI;
writeln(asin(complex(0.0))); // 0.0
assert(isClose(asin(complex(0.5L)), PI / 6));
Examples:
import std.math.operations : isClose;
import std.math.constants : PI;
import std.math.trigonometry : std_math_acos = acos;
writeln(acos(complex(0.0))); // std_math_acos(0.0)
assert(isClose(acos(complex(0.5L)), PI / 3));
Examples:
import std.math.operations : isClose;
import std.math.constants : PI;
writeln(atan(complex(0.0))); // 0.0
assert(isClose(atan(sqrt(complex(3.0L))), PI / 3));
assert(isClose(atan(sqrt(complex(3.0f))), float(PI) / 3));
pure nothrow @nogc @safe Complex!T sinh(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T cosh(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T tanh(T)(Complex!T z);
複素数上の双曲三角関数。
Parameters:
Complex!T z 複素数。
Returns:
の双曲線正弦、余弦、正接。 zをそれぞれ表す。
Examples:
static import std.math;
writeln(sinh(complex(0.0))); // 0.0
writeln(sinh(complex(1.0L))); // std.math.sinh(1.0L)
writeln(sinh(complex(1.0f))); // std.math.sinh(1.0f)
Examples:
static import std.math;
writeln(cosh(complex(0.0))); // 1.0
writeln(cosh(complex(1.0L))); // std.math.cosh(1.0L)
writeln(cosh(complex(1.0f))); // std.math.cosh(1.0f)
Examples:
import std.math.operations : isClose;
import std.math.trigonometry : std_math_tanh = tanh;
writeln(tanh(complex(0.0))); // 0.0
assert(isClose(tanh(complex(1.0L)), std_math_tanh(1.0L)));
assert(isClose(tanh(complex(1.0f)), std_math_tanh(1.0f)));
pure nothrow @nogc @safe Complex!T asinh(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T acosh(T)(Complex!T z);

pure nothrow @nogc @safe Complex!T atanh(T)(Complex!T z);
複素数上の逆双曲三角関数。
Parameters:
Complex!T z 複素数。
Returns:
の双曲線アークサイン、アークコサイン、アークタンジェント。 zをそれぞれ表す。
Examples:
import std.math.operations : isClose;
import std.math.trigonometry : std_math_asinh = asinh;
writeln(asinh(complex(0.0))); // 0.0
assert(isClose(asinh(complex(1.0L)), std_math_asinh(1.0L)));
assert(isClose(asinh(complex(1.0f)), std_math_asinh(1.0f)));
Examples:
import std.math.operations : isClose;
import std.math.trigonometry : std_math_acosh = acosh;
writeln(acosh(complex(1.0))); // 0.0
assert(isClose(acosh(complex(3.0L)), std_math_acosh(3.0L)));
assert(isClose(acosh(complex(3.0f)), std_math_acosh(3.0f)));
Examples:
import std.math.operations : isClose;
import std.math.trigonometry : std_math_atanh = atanh;
writeln(atanh(complex(0.0))); // 0.0
assert(isClose(atanh(complex(0.5L)), std_math_atanh(0.5L)));
assert(isClose(atanh(complex(0.5f)), std_math_atanh(0.5f)));
pure nothrow @nogc @trusted Complex!real expi(real y);
Parameters:
real y 実数だ。
Returns:
cos(y) + i sin(y) の値。

注釈:この値は、y(cos)+i sin(y)の値である。 expiは、便宜上、またコードの移行を容易にするためにここに含まれている。

Examples:
import core.math : cos, sin;
writeln(expi(0.0L)); // 1.0L
writeln(expi(1.3e5L)); // complex(cos(1.3e5L), sin(1.3e5L))
pure nothrow @nogc @safe Complex!real coshisinh(real y);
Parameters:
real y 実数だ。
Returns:
cosh(y) + i sinh(y) の値。

注釈:」である。 coshisinhは、便宜上、またコードの移行を容易にするためにここに含まれている。

Examples:
import std.math.trigonometry : cosh, sinh;
writeln(coshisinh(3.0L)); // complex(cosh(3.0L), sinh(3.0L))
pure nothrow @nogc @safe Complex!T sqrt(T)(Complex!T z);
Parameters:
Complex!T z 複素数である。
Returns:
の平方根。 z.
Examples:
static import core.math;
writeln(sqrt(complex(0.0))); // 0.0
writeln(sqrt(complex(1.0L, 0))); // core.math.sqrt(1.0L)
writeln(sqrt(complex(-1.0L, 0))); // complex(0, 1.0L)
writeln(sqrt(complex(-8.0, -6.0))); // complex(1.0, -3.0)
pure nothrow @nogc @trusted Complex!T exp(T)(Complex!T x);
元を計算する。
Parameters:
Complex!T x 複素数
Returns:
の複素数の底eの指数 x
特殊な値
x exp(x)
(±0, +0) (1, +0)
(any, +∞) (NAN,NAN)
(任意の、NAN)(NANNAN)
(+∞, +0) (+∞, +0)
(-∞, any) (±0, cis(x.im))
(+∞, any) (±∞, cis(x.im))
(-∞, +∞) (±0, ±0)
(+∞, +∞) (±∞,NAN)
(-∞,NAN) (±0, ±0)
(±∞,NAN) (±∞,NAN)
(NAN、+0) (NAN、+0)
(NAN、任意) (NANNAN)
(NAN、NAN) (ナン、ナン)
Examples:
import std.math.operations : isClose;
import std.math.constants : PI;

writeln(exp(complex(0.0, 0.0))); // complex(1.0, 0.0)

auto a = complex(2.0, 1.0);
writeln(exp(conj(a))); // conj(exp(a))

auto b = exp(complex(0.0L, 1.0L) * PI);
assert(isClose(b, -1.0L, 0.0, 1e-15));
pure nothrow @nogc @safe Complex!T log(T)(Complex!T x);
xの自然対数を計算する。 枝の切り口は負の軸に沿っている。
Parameters:
Complex!T x 複素数
Returns:
の複素自然対数 x
特別な値
x log(x)
(-0, +0) (-∞, π)
(+0, +0) (-∞, +0)
(any, +∞) (+∞, π/2)
(任意の、NAN) (NANNAN)
(-∞, any) (+∞, π)
(+∞, 任意) (+∞, +0)
(-∞, +∞) (+∞, 3π/4)
(+∞, +∞) (+∞, π/4)
(±∞,NAN) (+∞,NAN)
(NAN、任意) (NANNAN)
(NAN、+∞)(+∞、NAN (NAN、+∞)(NAN、+∞)(NAN、+∞)(NAN、+∞)(NAN、+
(NANNAN) (NANNAN)
Examples:
import core.math : sqrt;
import std.math.constants : PI;
import std.math.operations : isClose;

auto a = complex(2.0, 1.0);
writeln(log(conj(a))); // conj(log(a))

auto b = 2.0 * log10(complex(0.0, 1.0));
auto c = 4.0 * log10(complex(sqrt(2.0) / 2, sqrt(2.0) / 2));
assert(isClose(b, c, 0.0, 1e-15));

writeln(log(complex(-1.0L, 0.0L))); // complex(0.0L, PI)
writeln(log(complex(-1.0L, -0.0L))); // complex(0.0L, -PI)
pure nothrow @nogc @safe Complex!T log10(T)(Complex!T x);
xの10進対数を計算する。
Parameters:
Complex!T x 複素数
Returns:
の複素数底10の対数 x
Examples:
import core.math : sqrt;
import std.math.constants : LN10, PI;
import std.math.operations : isClose;

auto a = complex(2.0, 1.0);
writeln(log10(a)); // log(a) / log(complex(10.0))

auto b = log10(complex(0.0, 1.0)) * 2.0;
auto c = log10(complex(sqrt(2.0) / 2, sqrt(2.0) / 2)) * 4.0;
assert(isClose(b, c, 0.0, 1e-15));
pure nothrow @nogc @safe Complex!T pow(T, Int)(Complex!T x, const Int n)
if (isIntegral!Int);

pure nothrow @nogc @trusted Complex!T pow(T)(Complex!T x, const T n);

pure nothrow @nogc @trusted Complex!T pow(T)(Complex!T x, Complex!T y);

pure nothrow @nogc @trusted Complex!T pow(T)(const T x, Complex!T n);
xnを計算する。 枝の切り口は負の軸上にある。
Parameters:
Complex!T x ベース
Int n 指数
Returns:
xの累乗になる。 n
Examples:
import std.math.operations : isClose;

auto a = complex(1.0, 2.0);
writeln(pow(a, 2)); // a * a
writeln(pow(a, 3)); // a * a * a
writeln(pow(a, -2)); // 1.0 / (a * a)
assert(isClose(pow(a, -3), 1.0 / (a * a * a)));
Examples:
import std.math.operations : isClose;
writeln(pow(complex(0.0), 2.0)); // complex(0.0)
writeln(pow(complex(5.0), 2.0)); // complex(25.0)

auto a = pow(complex(-1.0, 0.0), 0.5);
assert(isClose(a, complex(0.0, +1.0), 0.0, 1e-16));

auto b = pow(complex(-1.0, -0.0), 0.5);
assert(isClose(b, complex(0.0, -1.0), 0.0, 1e-16));
Examples:
import std.math.operations : isClose;
import std.math.exponential : exp;
import std.math.constants : PI;
auto a = complex(0.0);
auto b = complex(2.0);
writeln(pow(a, b)); // complex(0.0)

auto c = complex(0.0L, 1.0L);
assert(isClose(pow(c, c), exp((-PI) / 2)));
Examples:
import std.math.operations : isClose;
writeln(pow(2.0, complex(0.0))); // complex(1.0)
writeln(pow(2.0, complex(5.0))); // complex(32.0)

auto a = pow(-2.0, complex(-1.0));
assert(isClose(a, complex(-0.5), 0.0, 1e-16));

auto b = pow(-0.5, complex(-1.0));
assert(isClose(b, complex(-2.0), 0.0, 1e-15));