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

std.math.remainder

これは std.math.
このモジュールには、いくつかのバージョンの剰余計算が含まれている。
Authors:
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger
nothrow @nogc @trusted real fmod(real x, real y);
x/y の計算から余りを計算する。
Returns:
ここでiはyがxから完全に引くことができる回数である。 結果は x と同じ符号を持つ。
特殊な値
x y fmod(x, y) 無効か?
±0.0 0.0ではない ±0.0 0.0
±∞ 何もない ナン あり
何でも ±0.0 ナン あり
!=±∞ ±∞ x いいえ
Examples:
import std.math.operations : feqrel;
import std.math.traits : isIdentical, isNaN;

assert(isIdentical(fmod(0.0, 1.0), 0.0));
assert(fmod(5.0, 3.0).feqrel(2.0) > 16);
assert(isNaN(fmod(5.0, 0.0)));
nothrow @nogc @trusted real modf(real x, ref real i);
xを積分部分と小数部分に分解する。 積分部はiに格納される。
Returns:
xの小数部。
特殊値
x i (入力時) modf(x, i) i (戻り値)
±∞ 何でも ±0.0 ±∞
Examples:
import std.math.operations : feqrel;

real frac;
real intpart;

frac = modf(3.14159, intpart);
assert(intpart.feqrel(3.0) > 16);
assert(frac.feqrel(0.14159) > 16);
nothrow @nogc @trusted real remainder(real x, real y);

nothrow @nogc @trusted real remquo(real x, real y, out int n);
IEC 60559に従い、余り x REM y を計算する。
REM は x - y * n の値であり、n は x / y の正確な値に最も近い整数である。 ここで n は x / y の正確な値に最も近い整数である。 n - x / y| == 0.5の場合、nは偶数である。 結果がゼロの場合、xと同じ符号を持つ。 そうでなければ、結果の符号は x / y の符号となる。 精度モードは剰余関数には影響しない。
remquoは nをパラメータ n.
特殊値
x y 剰余(x, y) n 無効か?
±0.0 0.0ではない ±0.0 0.0 無効
±∞ 何もない -ナン ? イエス
何でも ±0.0 ±NAN ? イエス
!= ±∞ ±∞ x ? いいえ
Examples:
import std.math.operations : feqrel;
import std.math.traits : isNaN;

assert(remainder(5.1, 3.0).feqrel(-0.9) > 16);
assert(remainder(-5.1, 3.0).feqrel(0.9) > 16);
writeln(remainder(0.0, 3.0)); // 0.0

assert(isNaN(remainder(1.0, 0.0)));
assert(isNaN(remainder(-1.0, 0.0)));
Examples:
import std.math.operations : feqrel;

int n;

assert(remquo(5.1, 3.0, n).feqrel(-0.9) > 16 && n == 2);
assert(remquo(-5.1, 3.0, n).feqrel(0.9) > 16 && n == -2);
assert(remquo(0.0, 3.0, n) == 0.0 && n == 0);