CGFloat addition bug?

后端 未结 1 1802
[愿得一人]
[愿得一人] 2020-12-11 21:22

I was trying to add some CGFloat values recursively in my program. And I just realized in one particular scenario the total generated was incorrect. To ensure I had nothing

相关标签:
1条回答
  • 2020-12-11 22:09

    CGFloat is a single precision float on 32 bit targets such as iOS - it only has a 23 bit mantissa, i.e. around 6 - 7 significant digits. Use a double precision type if you need greater accuracy.

    You should probably read David Goldberg's What Every Computer Scientist Should Know About Floating-Point Arithmetic before proceeding much further with learning to program.

    0 讨论(0)
提交回复
热议问题