为什么CGFloat在32位上浮动,而在64位上浮动两倍? [英] Why is CGFloat float on 32 bit and double on 64 bit?
问题描述
来自"CoreGraphics/CGBase.h":
From "CoreGraphics/CGBase.h":
#if defined(__LP64__) && __LP64__
# define CGFLOAT_TYPE double
# define CGFLOAT_IS_DOUBLE 1
# define CGFLOAT_MIN DBL_MIN
# define CGFLOAT_MAX DBL_MAX
#else
# define CGFLOAT_TYPE float
# define CGFLOAT_IS_DOUBLE 0
# define CGFLOAT_MIN FLT_MIN
# define CGFLOAT_MAX FLT_MAX
#endif
Apple为什么要这样做?有什么好处?
Why did Apple do this? What's the advantage?
我似乎只能想到缺点.请赐教.
I can seem to think of downsides only. Please enlighten me.
推荐答案
Apple明确表示他们做到了您可以争论是否更大的范围和准确性在实践中确实有帮助,但是Apple很清楚他们在想什么.
Apple explicitly says they did it "to provide a wider range and accuracy for graphical quantities." You can debate whether the wider range and accuracy have been really helpful in practice, but Apple is clear on what they were thinking.
值得一提的是,值得一提的是,在OS X 10.5中添加了CGFloat
,早于iPhone(当然也很早于64位iPhone).在Mac之类的大内存"计算机上,使用64位显然更有利.苹果公司制造了本地建筑"类型,以简化在旧"世界与新"世界之间的过渡.我认为Swift带来NSInteger
作为默认的Int
类型(即Int
是特定于体系结构的)很有趣.但是他们使Float
和Double
体系结构独立.该语言没有与CGFloat
等效的语言.我将其理解为默认的认识,即CGFloat
不是最好的主意. NEON仅支持单精度浮点数学运算.必须在VFP上执行双精度数学. (并不是发明CGFloat
时考虑了NEON.)
It's worth remembering, BTW, that CGFloat
was added in OS X 10.5, long before iPhones (and certainly long before 64-bit iPhones). Going 64-bit is more obviously beneficial on "big memory" machines like Macs. And Apple made "local architecture" types that were supposed to make it easier to transition between the "old" and "new" worlds. I think it's interesting that Swift brought over NSInteger
as the default Int
type (i.e. Int
is architecture-specific). But they made Float
and Double
architecture independent. There is no equivalent of CGFloat
in the language. I read this as a tacit acknowledgement that CGFloat
wasn't the greatest idea. NEON only supports single precision floating point math. Double precision math has to be done on the VFP. (Not that NEON was a consideration when CGFloat
was invented.)
这篇关于为什么CGFloat在32位上浮动,而在64位上浮动两倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!