Structure

CGFloat

The basic type for floating-point scalar values in Core Graphics and related frameworks.

Overview

The size and precision of this type depend on the CPU architecture. When you build for a 64-bit CPU, the CGFloat type is a 64-bit, IEEE double-precision floating point type, equivalent to the Double type. When you build for a 32-bit CPU, the CGFloat type is a 32-bit, IEEE single-precision floating point type, equivalent to the Float type.

Topics

Type Aliases

typealias CGFloat.Exponent

An integer type that can represent any written exponent.

typealias CGFloat.NativeType

The native type used to store the CGFloat, which is Float on 32-bit architectures and Double on 64-bit architectures.

typealias CGFloat.RawSignificand

An unsigned integer type that can represent the significand of any value.

Initializers

init()

Create an instance initialized to zero.

init(NSNumber)Deprecated
init(Int)

value rounded to the closest representable Self.

init(Int64)

value rounded to the closest representable Self.

init(Float)

value rounded to the closest representable Self.

init(Int8)

value rounded to the closest representable Self.

init(UInt8)

value rounded to the closest representable Self.

init(Double)

value rounded to the closest representable Self.

init(Int16)

value rounded to the closest representable Self.

init(UInt32)

value rounded to the closest representable Self.

init(UInt)

value rounded to the closest representable Self.

init(UInt16)

value rounded to the closest representable Self.

init(Int32)

value rounded to the closest representable Self.

init(UInt64)

value rounded to the closest representable Self.

init(CGFloat)

Create an instance initialized to value.

init(Float80)

value rounded to the closest representable Self.

init(floatLiteral: CGFloat.NativeType)

Create an instance initialized to value.

init(floatLiteral: CGFloat.NativeType)

Create an instance initialized to value.

init(integerLiteral: Int)

Create an instance initialized to value.

init(sign: FloatingPointSign, exponent: Int, significand: CGFloat)

Initialize from sign, exponent, and significand.

init(sign: FloatingPointSign, exponentBitPattern: UInt, significandBitPattern: UInt)

Combines sign, exponent and significand bit patterns to produce a floating-point value.

init(signOf: CGFloat, magnitudeOf: CGFloat)

Creates a new floating-point value using the sign of one value and the magnitude of another.

Instance Properties

var binade: CGFloat

The least-magnitude member of the binade of self.

var customMirror: Mirror

A mirror that reflects the CGFloat instance.

var description: String

A textual representation of self.

var exponent: Int

The integer part of the base-r logarithm of the magnitude of self, where r is the radix (2 for binary, 10 for decimal). Implements the IEEE 754 logB operation.

var exponentBitPattern: UInt

The raw encoding of the exponent field of the floating-point value.

var hashValue: Int

The hash value.

var isCanonical: Bool

True if and only if self is canonical.

var isFinite: Bool

true iff self is zero, subnormal, or normal (not infinity or NaN).

var isInfinite: Bool

true iff self is infinity.

var isNaN: Bool

true iff self is NaN.

var isNormal: Bool

true iff self is normal (not zero, subnormal, infinity, or NaN).

var isSignalingNaN: Bool

True if and only if self is a signaling NaN.

var isSubnormal: Bool

true iff self is subnormal.

var isZero: Bool

true iff self is +0.0 or -0.0.

var nextDown: CGFloat

The greatest representable value that compares less than this value.

var nextUp: CGFloat

The least representable value that compares greater than self.

var sign: FloatingPointSign

minus if the sign bit of self is set, and plus otherwise. Implements the IEEE 754 signbit operation.

var significand: CGFloat

The significant digits, or mantissa, of the floating-point number.

var significandBitPattern: UInt

The raw encoding of the significand field of the floating-point value.

var significandWidth: Int

The number of bits required to represent significand.

var ulp: CGFloat

The unit in the last place of self.

Type Properties

static var exponentBitCount: Int

The number of bits used to represent the exponent.

static var infinity: CGFloat

The positive infinity.

static var leastNormalMagnitude: CGFloat

The least positive normal number.

static var pi: CGFloat

The mathematical constant pi = 3.14159…

static var radix: Int

The radix, or base of exponentiation, for this floating-point type.

static var signalingNaN: CGFloat

A signaling NaN (not-a-number).

static var significandBitCount: Int

For fixed-width floating-point types, this is the number of fractional significand bits.

static var ulpOfOne: CGFloat

The unit in the last place of 1.0.

Instance Methods

func addingProduct(CGFloat, CGFloat)

Returns the result of adding the product of the two given values to this value, computed without intermediate rounding.

func advanced(by: CGFloat)

Returns a Self x such that self.distance(to: x) approximates n.

func distance(to: CGFloat)

Returns a stride x such that self.advanced(by: x) approximates other.

func formTruncatingRemainder(dividingBy: CGFloat)

Replace self with the remainder of self divided by other using truncating division. Similar to the C standard library function fmod.

func isEqual(to: CGFloat)

IEEE 754 equality predicate.

func isLess(than: CGFloat)

IEEE 754 less-than predicate.

func isLessThanOrEqualTo(CGFloat)

IEEE 754 less-than-or-equal predicate.

func isTotallyOrdered(belowOrEqualTo: CGFloat)

Returns a Boolean value indicating whether this instance should precede or tie positions with the given value in an ascending sort.

func negate()

Replace self with its additive inverse.

func negate()

Replaces this value with its additive inverse.

func remainder(dividingBy: CGFloat)

Returns the remainder of this value divided by the given value.

func round()

Rounds this value to an integral value using “schoolbook rounding.”

func rounded()

Returns this value rounded to an integral value using “schoolbook rounding.”

func rounded(FloatingPointRoundingRule)

Returns this value rounded to an integral value using the specified rounding rule.

func squareRoot()

Returns the square root of the value, rounded to a representable value.

func truncatingRemainder(dividingBy: CGFloat)

Returns the remainder of this value divided by the given value using truncating division.

Type Methods

static func maximum(CGFloat, CGFloat)

Returns the greater of the two given values.

static func maximumMagnitude(CGFloat, CGFloat)

Returns the value with greater magnitude.

static func minimum(CGFloat, CGFloat)

Returns the lesser of the two given values.

static func minimumMagnitude(CGFloat, CGFloat)

Returns the value with lesser magnitude.

Operator Functions

static func !=(CGFloat, CGFloat)

Returns a Boolean value indicating whether two values are not equal.

static func +(CGFloat)

Returns the given number unchanged.

static func -(CGFloat)

Returns the additive inverse of the specified value.

static func ...(CGFloat)

Returns a partial range up to, and including, its upper bound.

static func ...(CGFloat)

Returns a partial range extending upward from a lower bound.

static func ..<(CGFloat)

Returns a partial range up to, but not including, its upper bound.

static func <=(CGFloat, CGFloat)

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

static func >(CGFloat, CGFloat)

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

static func >=(CGFloat, CGFloat)

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

See Also

Geometric Data Types

struct CGPoint

A structure that contains a point in a two-dimensional coordinate system.

struct CGSize

A structure that contains width and height values.

struct CGRect

A structure that contains the location and dimensions of a rectangle.

struct CGVector

A structure that contains a two-dimensional vector.

struct CGAffineTransform

An affine transformation matrix for use in drawing 2D graphics.