Skip to content

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

@ichizok

Description

@ichizok

問題

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) のような) や定数を追加する。

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions