Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
二つの浮動小数点数が等しいかどうかを等値演算子で比較してはいけない。浮動小数点数には誤差があるため、直観的には等しいはずの二つの数が異なる場合がある。以下のRubyのスクリプトを実行すると 10.times { tmp += 0.1 } values = [[1.0 - 0.9, 0.1], [0.15 + 0.15, 0.1 + 0.2], [tmp, 1.0]] values.each {|pair| lhs, rhs = pair printf("lhs = %.18f, rhs = %.18f, diff = %.18f, == = %p\n", lhs, rhs, (lhs - rhs).abs, lhs == rhs); } lhs = 0.099999999999999978, rhs = 0.100000000000000006, diff = 0.000000000000
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く