New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float 型の等値比較について #1163

Open
ichizok opened this Issue Apr 12, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@ichizok
Member

ichizok commented Apr 12, 2018

問題

Vim script で float 型変数を等値比較する際、内部では単純に x == y としているが、誤差を考慮しなくてよいか?

:echo 0.1+0.2 == 0.15+0.15
" 0

:let x = 1.0
:let x += 0.001
:let x -= 0.001
:echo x == 1.0
" 0

Vim 内部で誤差評価する (float_equal())
vim/vim@master...ichizok:fix/float_equal

あるいは、Vim script に誤差評価用の関数 (isclose(x, y) のような) や定数を追加する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment