Why my double can contain a value below the machine epsilon?

前端 未结 3 1531
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 00:40

I was solving an equation using double precision and I got -7.07649e-17 as a solution instead of 0.

I agree it\'s close enough that I can s

3条回答
  •  既然无缘
    2021-01-14 01:08

    There are two different constants in this story. One is epsilon, which is a minimal value that when added to 1.0 produces a value different from 1.0. If you add a smaller value to 1.0 you will again get a 1.0, because there are physical limits to the representation of a number in a computer. But there are values that are less than epsilon and greater than zero. Smallest such number for a double you get with std::numeric_limits::min.

    For reference, you get epsilon with std::numeric_limits::epsilon.

提交回复
热议问题