Ziel c
Aus dem Foundation-Quellcode in CoreGraphics CGBase.h:
/* Definition of `CGFLOAT_TYPE', `CGFLOAT_IS_DOUBLE', `CGFLOAT_MIN', and
`CGFLOAT_MAX'. */
#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
/* Definition of the `CGFloat' type and `CGFLOAT_DEFINED'. */
typedef CGFLOAT_TYPE CGFloat;
#define CGFLOAT_DEFINED 1
Copyright (c) 2000-2011 Apple Inc.
Dies ist im Wesentlichen zu tun:
#if defined(__LP64__) && __LP64__
typedef double CGFloat;
#else
typedef float CGFloat;
#endif
Wobei __LP64__angibt, ob die aktuelle Architektur * 64-Bit ist.
Beachten Sie, dass 32-Bit-Systeme weiterhin 64-Bit verwenden doublekönnen. Es dauert lediglich mehr Prozessorzeit. CoreGraphics tut dies daher zu Optimierungszwecken und nicht aus Kompatibilitätsgründen. Wenn Sie sich nicht um die Leistung, sondern um die Genauigkeit sorgen, verwenden Sie einfach double.
Schnell
In Swift gibt CGFloates einen structWrapper entweder Floatfür 32-Bit-Architekturen oder Doublefür 64-Bit -Architekturen (Sie können dies zur Laufzeit oder zur Kompilierung mit erkennen CGFloat.NativeType).
Aus dem CoreGraphics-Quellcode inCGFloat.swift.gyb :
public struct CGFloat {
#if arch(i386) || arch(arm)
/// The native type used to store the CGFloat, which is Float on
/// 32-bit architectures and Double on 64-bit architectures.
public typealias NativeType = Float
#elseif arch(x86_64) || arch(arm64)
/// The native type used to store the CGFloat, which is Float on
/// 32-bit architectures and Double on 64-bit architectures.
public typealias NativeType = Double
#endif
* Insbesondere longs und Zeiger, daher die LP. Siehe auch: http://www.unix.org/version2/whatsnew/lp64_wp.html