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

std.math.algebraic

これは std.math.
abssqrtpoly のような古典的な代数関数を含む。
Authors:
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger
pure nothrow @nogc auto abs(Num)(Num x)
if (isIntegral!Num || is(typeof(Num.init >= 0)) && is(typeof(-Num.init)));
数値の絶対値を計算する。
Parameters:
Num (テンプレート・パラメータ) 数値の型
Num x 実数値
Returns:
数値の絶対値。浮動小数点または積分の場合、 の場合、戻り値の型は入力と同じになる。

制限事項 x が符号付き積分でNum.min に等しい場合、x の値が代わりに返される。 2 の補数に対する注釈;-Num.min (=Num.max + 1) はオーバーフローのため表現できない。

Examples:
import std.math.traits : isIdentical, isNaN;

assert(isIdentical(abs(-0.0L), 0.0L));
assert(isNaN(abs(real.nan)));
writeln(abs(-real.infinity)); // real.infinity
writeln(abs(-56)); // 56
writeln(abs(2321312L)); // 2321312L
writeln(abs(23u)); // 23u
pure nothrow @nogc @safe real fabs(real x);

pure nothrow @nogc @safe double fabs(double x);

pure nothrow @nogc @safe float fabs(float x);
x|を返す
特殊値
x ファブ(x)
±0.0 +0.0
±∞ +∞
Examples:
import std.math.traits : isIdentical;

assert(isIdentical(fabs(0.0f), 0.0f));
assert(isIdentical(fabs(-0.0f), 0.0f));
writeln(fabs(-10.0f)); // 10.0f

assert(isIdentical(fabs(0.0), 0.0));
assert(isIdentical(fabs(-0.0), 0.0));
writeln(fabs(-10.0)); // 10.0

assert(isIdentical(fabs(0.0L), 0.0L));
assert(isIdentical(fabs(-0.0L), 0.0L));
writeln(fabs(-10.0L)); // 10.0L
pure nothrow @nogc @safe float sqrt(float x);

pure nothrow @nogc @safe double sqrt(double x);

pure nothrow @nogc @safe real sqrt(real x);
xの平方根を計算する。
特殊値
x sqrt(x) 無効か?
-0.0 -0.0 無効
<0.0 無効 はい
+∞ +∞ いいえ
Examples:
import std.math.operations : feqrel;
import std.math.traits : isNaN;

assert(sqrt(2.0).feqrel(1.4142) > 16);
assert(sqrt(9.0).feqrel(3.0) > 16);

assert(isNaN(sqrt(-1.0f)));
assert(isNaN(sqrt(-1.0)));
assert(isNaN(sqrt(-1.0L)));
nothrow @nogc @trusted real cbrt(real x);
xの立方根を計算する。
特殊値
x cbrt(x) 無効か?
±0.0 ±0.0 無効
NAN 無効 あり
±∞ ±∞ いいえ
Examples:
import std.math.operations : feqrel;

assert(cbrt(1.0).feqrel(1.0) > 16);
assert(cbrt(27.0).feqrel(3.0) > 16);
assert(cbrt(15.625).feqrel(2.5) > 16);
pure nothrow @nogc @safe T hypot(T)(const T x, const T y)
if (isFloatingPoint!T);
の長さを計算する。 辺の長さがxとyの直角三角形の斜辺の長さを計算する。 の平方根の値である。 の平方根の値である:
sqrt(x2+y2)
hypot(x,y)、hypot(y,x)、hypot(x,-y)は等価である。 は等価である。
特殊値
x y hypot(x, y) 無効か?
x ±0.0 |x| いいえ
±∞ y +∞ いいえ
±∞ ナン +∞ ノー
Examples:
import std.math.operations : feqrel;

assert(hypot(1.0, 1.0).feqrel(1.4142) > 16);
assert(hypot(3.0, 4.0).feqrel(5.0) > 16);
writeln(hypot(real.infinity, 1.0L)); // real.infinity
writeln(hypot(real.infinity, real.nan)); // real.infinity
pure nothrow @nogc @safe T hypot(T)(const T x, const T y, const T z)
if (isFloatingPoint!T);
原点(0, 0, 0)からの点(x, y, z)の距離を計算する。 からの点の距離を計算する。 距離はx, y, zの2乗和の平方根の値である。 の平方根の値である:
sqrt(x2+y2+z2)
3次元空間の2点(x1, y1, z1)と(x2, y2, z2)間の距離は、hypot(x2-x1, y2-y1, z2-z1)として計算できる。 の間の距離は、hypot(x2-x1, y2-y1, z2-z1)として計算できる。
Parameters:
T x 浮動小数点値
T y 浮動小数点値
T z 浮動小数点値
Returns:
与えられた引数の2乗和の平方根。
Examples:
import std.math.operations : isClose;

assert(isClose(hypot(1.0, 2.0, 2.0), 3.0));
assert(isClose(hypot(2.0, 3.0, 6.0), 7.0));
assert(isClose(hypot(1.0, 4.0, 8.0), 9.0));
pure nothrow @nogc @trusted Unqual!(CommonType!(T1, T2)) poly(T1, T2)(T1 x, in T2[] A)
if (isFloatingPoint!T1 && isFloatingPoint!T2);

pure nothrow @nogc @safe Unqual!(CommonType!(T1, T2)) poly(T1, T2, int N)(T1 x, const ref T2[N] A)
if (isFloatingPoint!T1 && isFloatingPoint!T2 && (N > 0) && (N <= 10));
多項式A(x) =a0+a1x+a2x2+ を評価する。 a3x3; ...
A(x)=a0+x(a1+x(a2+...))の法則を使う。 x(a3+ ...)) である。)
Parameters:
T1 x 評価する値。
T2[] A 係数a0,a1などの配列。
Examples:
real x = 3.1L;
static real[] pp = [56.1L, 32.7L, 6];

writeln(poly(x, pp)); // (56.1L + (32.7L + 6.0L * x) * x)
T nextPow2(T)(const T val)
if (isIntegral!T);

T nextPow2(T)(const T val)
if (isFloatingPoint!T);
の次の2の累乗を与える。 valT 。 数値型である。
演算がオーバーフロー/アンダーフローにつながる場合、この関数は は0 を返す。
Parameters:
T val 任意の数
Returns:
の次の2のべき乗である。 val
Examples:
writeln(nextPow2(2)); // 4
writeln(nextPow2(10)); // 16
writeln(nextPow2(4000)); // 4096

writeln(nextPow2(-2)); // -4
writeln(nextPow2(-10)); // -16

writeln(nextPow2(uint.max)); // 0
writeln(nextPow2(uint.min)); // 0
writeln(nextPow2(size_t.max)); // 0
writeln(nextPow2(size_t.min)); // 0

writeln(nextPow2(int.max)); // 0
writeln(nextPow2(int.min)); // 0
writeln(nextPow2(long.max)); // 0
writeln(nextPow2(long.min)); // 0
Examples:
writeln(nextPow2(2.1)); // 4.0
writeln(nextPow2(-2.0)); // -4.0
writeln(nextPow2(0.25)); // 0.5
writeln(nextPow2(-4.0)); // -8.0

writeln(nextPow2(double.max)); // 0.0
writeln(nextPow2(double.infinity)); // double.infinity
T truncPow2(T)(const T val)
if (isIntegral!T);

T truncPow2(T)(const T val)
if (isFloatingPoint!T);
の前に2の最後のパワーを与える。 val.<></>は任意の組み込み 数値型である。
Parameters:
T val 任意の数値
Returns:
の前の最後の2のべき乗 val
Examples:
writeln(truncPow2(3)); // 2
writeln(truncPow2(4)); // 4
writeln(truncPow2(10)); // 8
writeln(truncPow2(4000)); // 2048

writeln(truncPow2(-5)); // -4
writeln(truncPow2(-20)); // -16

writeln(truncPow2(uint.max)); // int.max + 1
writeln(truncPow2(uint.min)); // 0
writeln(truncPow2(ulong.max)); // long.max + 1
writeln(truncPow2(ulong.min)); // 0

writeln(truncPow2(int.max)); // (int.max / 2) + 1
writeln(truncPow2(int.min)); // int.min
writeln(truncPow2(long.max)); // (long.max / 2) + 1
writeln(truncPow2(long.min)); // long.min
Examples:
writeln(truncPow2(2.1)); // 2.0
writeln(truncPow2(7.0)); // 4.0
writeln(truncPow2(-1.9)); // -1.0
writeln(truncPow2(0.24)); // 0.125
writeln(truncPow2(-7.0)); // -4.0

writeln(truncPow2(double.infinity)); // double.infinity