floating point number imprecision while iterating

后端 未结 3 845
天涯浪人
天涯浪人 2021-01-06 21:30

I have a function that computes a point in 3d spaced based on a value in range [0, 1]. The problem I\'m facing is, that a binary floating-point number canno

3条回答
  •  悲哀的现实
    2021-01-06 22:19

    When comparing floating point numbers you should check if they are close enough not exactly equal, for the reasons mentioned in other answers, something like:

    #define EPSILON 0.000001f
    #define FEQUAL(a,b) (fabs((a) - (b)) < EPSILON)
    

提交回复
热议问题