.NETのfloat.Epsilon定数は計算機イプシロンではない
2018年2月16日 (金) 01:37時点におけるimported>Administratorによる版 (→解決)
C#においてfloat型(Single型)の絶対値をfloat.Epsilon定数と比較している箇所の挙動がどうもおかしい。
原因
The value of the F:System.Single.Epsilon property is not equivalent to machine epsilon, which represents the upper bound of the relative error due to rounding in floating-point arithmetic. https://msdn.microsoft.com/ja-jp/library/system.single.epsilon(v=vs.110).aspx
要約すると「浮動小数点演算の丸の相対誤差の上限(丸め誤差発生時にズレるであろう最大値)」であり「計算機イプシロン」ではない。
まじかよ。名前紛らわしすぎだろ。
解決
static double MachineEpsilon()
{
double eps = 1.0;
do
{
eps /= 2.0;
}
while ((double)(1.0 + eps) != 1.0);
return eps;
}