英語版
このページの英語版を見る
std.math.exponential
これは std.math.
いくつかの指数関数と対数関数が含まれている。
License:
Authors:
Walter Bright, Don Clugston,
Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger
- pure nothrow @nogc @trusted Unqual!F
pow
(F, G)(Fx
, Gn
)
if (isFloatingPoint!F && isIntegral!G); - xn の値を計算する(n は整数)。Examples:
import std.math.operations : feqrel; writeln(pow(2.0, 5)); // 32.0 assert(pow(1.5, 9).feqrel(38.4433) > 16); assert(pow(real.nan, 2) is real.nan); writeln(pow(real.infinity, 2)); // real.infinity
- pure nothrow @nogc @trusted typeof(Unqual!F.init * Unqual!G.init)
pow
(F, G)(Fx
, Gn
)
if (isIntegral!F && isIntegral!G); - つの積分数のべき乗を計算する。Parameters:
F x
底 G n
指数 Returns:nが負の場合、結果は1 / pow(x, -n)となる、 となり、余りのある整数除算として計算される。この結果 となる。 xとnの両方が0の場合、結果は1になる。Throws:xが0でnが負の場合、結果は0による除算の結果と同じである。 の結果と同じである。Examples:writeln(pow(2, 3)); // 8 writeln(pow(3, 2)); // 9 writeln(pow(2, 10)); // 1_024 writeln(pow(2, 20)); // 1_048_576 writeln(pow(2, 30)); // 1_073_741_824 writeln(pow(0, 0)); // 1 writeln(pow(1, -5)); // 1 writeln(pow(1, -6)); // 1 writeln(pow(-1, -5)); // -1 writeln(pow(-1, -6)); // 1 writeln(pow(-2, 5)); // -32 writeln(pow(-2, -5)); // 0 writeln(pow(cast(double)-2, -5)); // -0.03125
- pure nothrow @nogc @trusted real
pow
(I, F)(Ix
, Fy
)
if (isIntegral!I && isFloatingPoint!F); - 整数から浮動小数点への累乗を計算する。Examples:
writeln(pow(2, 5.0)); // 32.0 writeln(pow(7, 3.0)); // 343.0 assert(pow(2, real.nan) is real.nan); writeln(pow(2, real.infinity)); // real.infinity
- pure nothrow @nogc @trusted Unqual!(Largest!(F, G))
pow
(F, G)(Fx
, Gy
)
if (isFloatingPoint!F && isFloatingPoint!G); - xyを計算する。
特殊値 x y pow(x, y) div 0 無効か? 何でも ±0.0 1.0 無効 いいえ |x| > 1 +∞ +∞ no ノー |x| < 1 +∞ +0.0 いいえ いいえ |x| > 1 -∞ +0.0 no いいえ |x| < 1 -∞ +∞ no ノー +∞ > 0.0 +∞ no ノー +∞ < 0.0 +0.0 いいえ いいえ -∞ 奇数整数 > 0.0 -∞ no いいえ -∞ > 0.0, 奇数整数ではない +∞ なし いいえ -∞ 奇数整数 < 0.0 -0.0 いいえ いいえ -∞ < 0.0、奇数整数ではない +0.0 いいえ いいえ ±1.0 ±∞ -ナン ノー あり < 0.0 有限、非整数 なし いいえ あり ±0.0 奇数整数 < 0.0 ±∞ あり いいえ ±0.0 < 0.0、奇数整数ではない +∞ あり いいえ ±0.0 奇数整数 > 0.0 ±0.0 いいえ いいえ ±0.0 > 0.0, 奇数整数ではない +0.0 なし いいえ Examples:import std.math.operations : isClose; assert(isClose(pow(2.0, 3.0), 8.0)); assert(isClose(pow(1.5, 10.0), 57.6650390625)); // 9の平方根 assert(isClose(pow(9.0, 0.5), 3.0)); // 1024の10乗根 assert(isClose(pow(1024.0, 0.1), 2.0)); assert(isClose(pow(-4.0, 3.0), -64.0)); // 4^ 2の逆数 assert(isClose(pow(4.0, -2.0), 0.0625)); // (-2)の逆数^ 3 assert(isClose(pow(-2.0, -3.0), -0.125)); assert(isClose(pow(-2.5, 3.0), -15.625)); // 2.5 ^^ 3の逆数 assert(isClose(pow(2.5, -3.0), 0.064)); // (-2.5)の逆数^ 3 assert(isClose(pow(-2.5, -3.0), -0.064)); // 4の平方根の逆数 assert(isClose(pow(4.0, -0.5), 0.5)); // 定義による assert(isClose(pow(0.0, 0.0), 1.0));
Examples:import std.math.operations : isClose; // the result is a complex number // 結果は浮動小数点数として表現できない複素数である import std.math.traits : isNaN; assert(isNaN(pow(-2.5, -1.5))); // 代わりにstd.complexの^^演算子を使う import std.complex : complex; auto c1 = complex(-2.5, 0.0); auto c2 = complex(-1.5, 0.0); auto result = c1 ^^ c2; // 正確な結果は`real`の精度に依存するようだ => increased tolerance assert(isClose(result.re, -4.64705438e-17, 2e-4)); assert(isClose(result.im, 2.52982e-1, 2e-4));
- Unqual!(Largest!(F, H))
powmod
(F, G, H)(Fx
, Gn
, Hm
)
if (isUnsigned!F && isUnsigned!G && isUnsigned!H); - 正の整数の"値"を計算する。
x
乗するn
モジュロm
.Parameters:F x
ベース G n
指数 H m
モジュラス Returns:x
乗n
モジュロm
. のうち最大のものを返す。x
とm
の型である。 この関数は、すべての値が符号なし型であることを要求する。Examples:writeln(powmod(1U, 10U, 3U)); // 1 writeln(powmod(3U, 2U, 6U)); // 3 writeln(powmod(5U, 5U, 15U)); // 5 writeln(powmod(2U, 3U, 5U)); // 3 writeln(powmod(2U, 4U, 5U)); // 1 writeln(powmod(2U, 5U, 5U)); // 2
- pure nothrow @nogc @trusted real
exp
(realx
);
pure nothrow @nogc @safe doubleexp
(doublex
);
pure nothrow @nogc @safe floatexp
(floatx
); - 元を計算する。
特殊値 x 元 +∞ +∞ -∞ +0.0 NAN NAN Examples:import std.math.operations : feqrel; import std.math.constants : E; writeln(exp(0.0)); // 1.0 assert(exp(3.0).feqrel(E * E * E) > 16);
- pure nothrow @nogc @trusted real
expm1
(realx
);
pure nothrow @nogc @safe doubleexpm1
(doublex
);
pure nothrow @nogc @safe floatexpm1
(floatx
); - 自然対数の底(e)の値を計算する。 xのべき乗から1を引いた値を計算する。xが非常に小さい場合、expm1(x)はexp(x)-1より正確である。 exp(x)-1よりも正確である。
特殊な値 x 元-1 ±0.0 ±0.0 +∞ +∞ -∞ -1.0 NAN NAN Examples:import std.math.traits : isIdentical; import std.math.operations : feqrel; assert(isIdentical(expm1(0.0), 0.0)); assert(expm1(1.0).feqrel(1.71828) > 16); assert(expm1(2.0).feqrel(6.3890) > 16);
- pure nothrow @nogc @trusted real
exp2
(realx
);
pure nothrow @nogc @safe doubleexp2
(doublex
);
pure nothrow @nogc @safe floatexp2
(floatx
); - 2倍を計算する。
特別な値 x exp2(x) +∞ +∞ -∞ +0.0 NAN NAN Examples:import std.math.traits : isIdentical; import std.math.operations : feqrel; assert(isIdentical(exp2(0.0), 1.0)); assert(exp2(2.0).feqrel(4.0) > 16); assert(exp2(8.0).feqrel(256.0) > 16);
- pure nothrow @nogc @trusted T
frexp
(T)(const Tvalue
, out intexp
)
if (isFloatingPoint!T); - 浮動小数点値をシグニフィカンドと指数に分離する。Returns:次のようなxと expを計算して返す。 値=x*2expおよび .5 <=|x|< 1.0 xは値と同じ符号を持つ。
特殊な値 値 戻り値 指数 ±0.0 ±0.0 0 +∞ +∞ int.max -∞ -∞ int.min ±NAN ±NAN int.min Examples:import std.math.operations : isClose; int exp; real mantissa = frexp(123.456L, exp); assert(isClose(mantissa * pow(2.0L, cast(real) exp), 123.456L)); assert(frexp(-real.nan, exp) && exp == int.min); assert(frexp(real.nan, exp) && exp == int.min); assert(frexp(-real.infinity, exp) == -real.infinity && exp == int.min); assert(frexp(real.infinity, exp) == real.infinity && exp == int.max); assert(frexp(-0.0, exp) == -0.0 && exp == 0); assert(frexp(0.0, exp) == 0.0 && exp == 0);
- pure nothrow @nogc @trusted int
ilogb
(T)(const Tx
)
if (isFloatingPoint!T);
pure nothrow @nogc @safe intilogb
(T)(const Tx
)
if (isIntegral!T && isUnsigned!T);
pure nothrow @nogc @safe intilogb
(T)(const Tx
)
if (isIntegral!T && isSigned!T); - x の指数を符号付き積分値として取り出す。xが特別な値でない場合、結果は次のようになる。 cast(int) logb(x).
特別な値 x ilogb(x) 範囲エラー? 0 FP_ILOGB0 Yes ±∞ int.max いいえ ナン FP_ILOGBNAN いいえ Examples:writeln(ilogb(1)); // 0 writeln(ilogb(3)); // 1 writeln(ilogb(3.0)); // 1 writeln(ilogb(100_000_000)); // 26 writeln(ilogb(0)); // FP_ILOGB0 writeln(ilogb(0.0)); // FP_ILOGB0 writeln(ilogb(double.nan)); // FP_ILOGBNAN writeln(ilogb(double.infinity)); // int.max
- alias
FP_ILOGB0
= core.stdc.math.FP_ILOGB0
;
aliasFP_ILOGBNAN
= core.stdc.math.FP_ILOGBNAN
; - の特別な戻り値である。 ilogb.Examples:
writeln(ilogb(0)); // FP_ILOGB0 writeln(ilogb(0.0)); // FP_ILOGB0 writeln(ilogb(double.nan)); // FP_ILOGBNAN
- pure nothrow @nogc @safe real
ldexp
(realn
, intexp
);
pure nothrow @nogc @safe doubleldexp
(doublen
, intexp
);
pure nothrow @nogc @safe floatldexp
(floatn
, intexp
); - n *2expを計算する
参考文献 frexp
Examples:import std.meta : AliasSeq; static foreach (T; AliasSeq!(float, double, real)) {{ T r; r = ldexp(3.0L, 3); writeln(r); // 24 r = ldexp(cast(T) 3.0, cast(int) 3); writeln(r); // 24 T n = 3.0; int exp = 3; r = ldexp(n, exp); writeln(r); // 24 }}
- pure nothrow @nogc @safe real
log
(realx
);
pure nothrow @nogc @safe doublelog
(doublex
);
pure nothrow @nogc @safe floatlog
(floatx
); - xの自然対数を計算する。
特別な値 x log(x) を0で割るか? 無効か? ±0.0 -∞ はい いいえ <0.0 ナン いいえ はい +∞ +∞ いいえ いいえ - pure nothrow @nogc @safe real
log10
(realx
);
pure nothrow @nogc @safe doublelog10
(doublex
);
pure nothrow @nogc @safe floatlog10
(floatx
); - xの10進対数を計算せよ。
特別な値 x log10(x) を0で割るか? 無効か? ±0.0 -∞ はい いいえ <0.0 ナン いいえ はい +∞ +∞ いいえ いいえ - pure nothrow @nogc @safe real
log1p
(realx
);
pure nothrow @nogc @safe doublelog1p
(doublex
);
pure nothrow @nogc @safe floatlog1p
(floatx
); - 1 + xの自然対数を計算する。xが非常に小さい場合、log1p(x)の方が log(1+x)よりも正確である。
特別な値 x log1p(x) 0で割るか? 無効か? ±0.0 ±0.0 無効? いいえ -1.0 -∞ なし いいえ <-1.0 -ナン いいえ はい +∞ +∞ いいえ いいえ - pure nothrow @nogc @safe real
log2
(realx
);
pure nothrow @nogc @safe doublelog2
(doublex
);
pure nothrow @nogc @safe floatlog2
(floatx
); - xの底2対数を計算する: ⊂x
特殊値 x log2(x) 0で割るか? 無効か? ±0.0 -∞ はい いいえ <0.0 ナン いいえ はい +∞ +∞ いいえ いいえ - pure nothrow @nogc @trusted real
logb
(realx
);
pure nothrow @nogc @trusted doublelogb
(doublex
);
pure nothrow @nogc @trusted floatlogb
(floatx
); - x の指数を符号付き積分値として取り出す。xが正規化されていない場合は、正規化されているものとして扱われる。 正の有限のxの場合: 1 <=x* FLT_RADIX-logb(x)< FLT_RADIX
特別な値 x logb(x) を0で割るか? ±∞ +∞ を0で割るか? ±0.0 -∞ あり Examples:writeln(logb(1.0)); // 0 writeln(logb(100.0)); // 6 writeln(logb(0.0)); // -real.infinity writeln(logb(real.infinity)); // real.infinity writeln(logb(-real.infinity)); // real.infinity
- pure nothrow @nogc @safe real
scalbn
(realx
, intn
);
pure nothrow @nogc @safe doublescalbn
(doublex
, intn
);
pure nothrow @nogc @safe floatscalbn
(floatx
, intn
); - x *2nを効率的に計算する。scalbnは基本的な算術演算子と同じ方法でアンダーフローとオーバーフローを処理する。 を処理する。
特殊値 x scalb(x) ±∞ ±∞ ±0.0 ±0.0 Examples:writeln(scalbn(0x1.2345678abcdefp0L, 999)); // 0x1.2345678abcdefp999L writeln(scalbn(-real.infinity, 5)); // -real.infinity writeln(scalbn(2.0, 10)); // 2048.0 writeln(scalbn(2048.0f, -10)); // 2.0f
Copyright © 1999-2024 by the D Language Foundation
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.108.0
ドキュメントのdmdのバージョン: 2.109.1
翻訳日付 :
HTML生成日時:
編集者: dokutoku