How dangerous is it to compare floating point values?

前端 未结 11 797
囚心锁ツ
囚心锁ツ 2020-11-21 06:44

I know UIKit uses CGFloat because of the resolution independent coordinate system.

But every time I want to check if for example fram

11条回答
  •  囚心锁ツ
    2020-11-21 07:09

    The correct question: how does one compare points in Cocoa Touch?

    The correct answer: CGPointEqualToPoint().

    A different question: Are two calculated values are the same?

    The answer posted here: They are not.

    How to check if they are close? If you want to check if they are close, then don't use CGPointEqualToPoint(). But, don't check to see if they are close. Do something that makes sense in the real world, like checking to see if a point is beyond a line or if a point is inside a sphere.

提交回复
热议问题