<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Float",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sf"
  },
  "title" : "Float"
}
-->

# Float

A single-precision (32-bit), floating-point value type.

```
@frozen struct Float
```

## Topics

### Converting Integers

[`init<Source>(Source)`](/documentation/Swift/Float/init(_:)-7e965)

Creates a new value, rounded to the closest possible representation.

[`init(Int)`](/documentation/Swift/Float/init(_:)-6cvkq)

Creates a new value, rounded to the closest possible representation.

### Converting Strings

[`init?<S>(S)`](/documentation/Swift/Float/init(_:)-h2f4)

Creates a new instance from the given string.

[`init?(Substring)`](/documentation/Swift/Float/init(_:)-4xsj6)

### Converting Floating-Point Values

[`init<Source>(Source)`](/documentation/Swift/Float/init(_:)-1488f)

Creates a new instance from the given value, rounded to the closest
possible representation.

[`init<Source>(Source)`](/documentation/Swift/Float/init(_:)-1oh9p)

Creates a new value, rounded to the closest possible representation.

[`init(Double)`](/documentation/Swift/Float/init(_:)-1kp2p)

Creates a new instance that approximates the given value.

[`init(Float)`](/documentation/Swift/Float/init(_:)-975tv)

Creates a new instance initialized to the given value.

[`init(Float80)`](/documentation/Swift/Float/init(_:)-11orc)

Creates a new instance that approximates the given value.

[`init(CGFloat)`](/documentation/Swift/Float/init(_:)-5soww)

[`init(Float16)`](/documentation/Swift/Float/init(_:)-ussz)

Creates a new instance that approximates the given value.

[`init(signOf: Float, magnitudeOf: Float)`](/documentation/Swift/Float/init(signOf:magnitudeOf:))

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

[`init(sign: FloatingPointSign, exponent: Int, significand: Float)`](/documentation/Swift/Float/init(sign:exponent:significand:))

Creates a new value from the given sign, exponent, and significand.

[`init(truncating: NSNumber)`](/documentation/Swift/Float/init(truncating:))

### Converting with No Loss of Precision

These initializers result in `nil` if the value passed can’t be represented without
any loss of precision.

[`init?<Source>(exactly: Source)`](/documentation/Swift/Float/init(exactly:)-8esr8)

Creates a new instance from the given value, if it can be represented
exactly.

[`init?(exactly: Double)`](/documentation/Swift/Float/init(exactly:)-89na7)

Creates a new instance initialized to the given value, if it can be
represented without rounding.

[`init?(exactly: Float)`](/documentation/Swift/Float/init(exactly:)-89pn7)

Creates a new instance initialized to the given value, if it can be
represented without rounding.

[`init?(exactly: Float80)`](/documentation/Swift/Float/init(exactly:)-6l5fa)

Creates a new instance initialized to the given value, if it can be
represented without rounding.

[`init?(exactly: NSNumber)`](/documentation/Swift/Float/init(exactly:)-zknq)

[`init?<Source>(exactly: Source)`](/documentation/Swift/Float/init(exactly:)-1h1oe)

Creates a new value, if the given integer can be represented exactly.

[`init?(exactly: Float16)`](/documentation/Swift/Float/init(exactly:)-8ho5q)

Creates a new instance initialized to the given value, if it can be
represented without rounding.

### Creating a Random Value

[`static func random(in: Range<Self>) -> Self`](/documentation/Swift/Float/random(in:)-6ided)

Returns a random value within the specified range.

[`static func random<T>(in: Range<Self>, using: inout T) -> Self`](/documentation/Swift/Float/random(in:using:)-1m6gf)

Returns a random value within the specified range, using the given
generator as a source for randomness.

[`static func random(in: ClosedRange<Self>) -> Self`](/documentation/Swift/Float/random(in:)-5o5h8)

Returns a random value within the specified range.

[`static func random<T>(in: ClosedRange<Self>, using: inout T) -> Self`](/documentation/Swift/Float/random(in:using:)-613hx)

Returns a random value within the specified range, using the given
generator as a source for randomness.

### Performing Calculations

  <doc://com.apple.Swift/documentation/Swift/floating-point-operators-for-float>

[`func addingProduct(Self, Self) -> Self`](/documentation/Swift/Float/addingProduct(_:_:))

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

[`func addProduct(Float, Float)`](/documentation/Swift/Float/addProduct(_:_:))

Adds the product of the two given values to this value in place, computed
without intermediate rounding.

[`func squareRoot() -> Self`](/documentation/Swift/Float/squareRoot())

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

[`func formSquareRoot()`](/documentation/Swift/Float/formSquareRoot())

Replaces this value with its square root, rounded to a representable
value.

[`func remainder(dividingBy: Self) -> Self`](/documentation/Swift/Float/remainder(dividingBy:))

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

[`func formRemainder(dividingBy: Float)`](/documentation/Swift/Float/formRemainder(dividingBy:))

Replaces this value with the remainder of itself divided by the given
value.

[`func truncatingRemainder(dividingBy: Self) -> Self`](/documentation/Swift/Float/truncatingRemainder(dividingBy:))

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

[`func formTruncatingRemainder(dividingBy: Float)`](/documentation/Swift/Float/formTruncatingRemainder(dividingBy:))

Replaces this value with the remainder of itself divided by the given
value using truncating division.

[`func negate()`](/documentation/Swift/Float/negate())

Replaces this value with its additive inverse.

### Rounding Values

[`func rounded() -> Self`](/documentation/Swift/Float/rounded())

[`func rounded(FloatingPointRoundingRule) -> Self`](/documentation/Swift/Float/rounded(_:))

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

[`func round()`](/documentation/Swift/Float/round())

[`func round(FloatingPointRoundingRule)`](/documentation/Swift/Float/round(_:))

Rounds the value to an integral value using the specified rounding rule.

### Comparing Values

  <doc://com.apple.Swift/documentation/Swift/floating-point-operators-for-float>

[`func isEqual(to: Float) -> Bool`](/documentation/Swift/Float/isEqual(to:))

Returns a Boolean value indicating whether this instance is equal to the
given value.

[`func isLess(than: Float) -> Bool`](/documentation/Swift/Float/isLess(than:))

Returns a Boolean value indicating whether this instance is less than the
given value.

[`func isLessThanOrEqualTo(Float) -> Bool`](/documentation/Swift/Float/isLessThanOrEqualTo(_:))

Returns a Boolean value indicating whether this instance is less than or
equal to the given value.

[`func isTotallyOrdered(belowOrEqualTo: Self) -> Bool`](/documentation/Swift/Float/isTotallyOrdered(belowOrEqualTo:))

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

[`static func maximum(Self, Self) -> Self`](/documentation/Swift/Float/maximum(_:_:))

Returns the greater of the two given values.

[`static func maximumMagnitude(Self, Self) -> Self`](/documentation/Swift/Float/maximumMagnitude(_:_:))

Returns the value with greater magnitude.

[`static func minimum(Self, Self) -> Self`](/documentation/Swift/Float/minimum(_:_:))

Returns the lesser of the two given values.

[`static func minimumMagnitude(Self, Self) -> Self`](/documentation/Swift/Float/minimumMagnitude(_:_:))

Returns the value with lesser magnitude.

### Finding the Sign and Magnitude

[`var magnitude: Float`](/documentation/Swift/Float/magnitude-swift.property)

The magnitude of this value.

[`var sign: FloatingPointSign`](/documentation/Swift/Float/sign)

The sign of the floating-point value.

[`typealias Magnitude`](/documentation/Swift/Float/Magnitude-swift.typealias)

A type that can represent the absolute value of any possible value of the
conforming type.

### Querying a Float

[`var ulp: Float`](/documentation/Swift/Float/ulp)

The unit in the last place of this value.

[`var significand: Float`](/documentation/Swift/Float/significand)

The significand of the floating-point value.

[`var exponent: Int`](/documentation/Swift/Float/exponent-swift.property)

The exponent of the floating-point value.

[`var nextUp: Float`](/documentation/Swift/Float/nextUp)

The least representable value that compares greater than this value.

[`var nextDown: Self`](/documentation/Swift/Float/nextDown)

The greatest representable value that compares less than this value.

[`var binade: Float`](/documentation/Swift/Float/binade)

The floating-point value with the same sign and exponent as this value,
but with a significand of 1.0.

### Accessing Numeric Constants

[`static var pi: Float`](/documentation/Swift/Float/pi)

The mathematical constant pi (π), approximately equal to 3.14159.

[`static var infinity: Float`](/documentation/Swift/Float/infinity)

Positive infinity.

[`static var greatestFiniteMagnitude: Float`](/documentation/Swift/Float/greatestFiniteMagnitude)

The greatest finite number representable by this type.

[`static var nan: Float`](/documentation/Swift/Float/nan)

A quiet NaN (“not a number”).

[`static var signalingNaN: Float`](/documentation/Swift/Float/signalingNaN)

A signaling NaN (“not a number”).

[`static var ulpOfOne: Float`](/documentation/Swift/Float/ulpOfOne)

The unit in the last place of 1.0.

[`static var leastNormalMagnitude: Float`](/documentation/Swift/Float/leastNormalMagnitude)

The least positive normal number.

[`static var leastNonzeroMagnitude: Float`](/documentation/Swift/Float/leastNonzeroMagnitude)

The least positive number.

[`static var zero: Self`](/documentation/Swift/Float/zero)

The zero value.

### Working with Binary Representation

[`var bitPattern: UInt32`](/documentation/Swift/Float/bitPattern)

The bit pattern of the value’s encoding.

[`var significandBitPattern: UInt32`](/documentation/Swift/Float/significandBitPattern)

The raw encoding of the value’s significand field.

[`var significandWidth: Int`](/documentation/Swift/Float/significandWidth)

The number of bits required to represent the value’s significand.

[`var exponentBitPattern: UInt`](/documentation/Swift/Float/exponentBitPattern)

The raw encoding of the value’s exponent field.

[`static var significandBitCount: Int`](/documentation/Swift/Float/significandBitCount)

The available number of fractional significand bits.

[`static var exponentBitCount: Int`](/documentation/Swift/Float/exponentBitCount)

The number of bits used to represent the type’s exponent.

[`static var radix: Int`](/documentation/Swift/Float/radix)

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

[`init(bitPattern: UInt32)`](/documentation/Swift/Float/init(bitPattern:))

Creates a new value with the given bit pattern.

[`init(sign: FloatingPointSign, exponentBitPattern: UInt, significandBitPattern: UInt32)`](/documentation/Swift/Float/init(sign:exponentBitPattern:significandBitPattern:))

Creates a new instance from the specified sign and bit patterns.

[`init(nan: Float.RawSignificand, signaling: Bool)`](/documentation/Swift/Float/init(nan:signaling:))

Creates a NaN (“not a number”) value with the specified payload.

[`typealias Exponent`](/documentation/Swift/Float/Exponent-swift.typealias)

A type that can represent any written exponent.

[`typealias RawSignificand`](/documentation/Swift/Float/RawSignificand)

A type that represents the encoded significand of a value.

### Querying a Float’s State

[`var isZero: Bool`](/documentation/Swift/Float/isZero)

A Boolean value indicating whether the instance is equal to zero.

[`var isFinite: Bool`](/documentation/Swift/Float/isFinite)

A Boolean value indicating whether this instance is finite.

[`var isInfinite: Bool`](/documentation/Swift/Float/isInfinite)

A Boolean value indicating whether the instance is infinite.

[`var isNaN: Bool`](/documentation/Swift/Float/isNaN)

A Boolean value indicating whether the instance is NaN (“not a number”).

[`var isSignalingNaN: Bool`](/documentation/Swift/Float/isSignalingNaN)

A Boolean value indicating whether the instance is a signaling NaN.

[`var isNormal: Bool`](/documentation/Swift/Float/isNormal)

A Boolean value indicating whether this instance is normal.

[`var isSubnormal: Bool`](/documentation/Swift/Float/isSubnormal)

A Boolean value indicating whether the instance is subnormal.

[`var isCanonical: Bool`](/documentation/Swift/Float/isCanonical)

A Boolean value indicating whether the instance’s representation is in
its canonical form.

[`var floatingPointClass: FloatingPointClassification`](/documentation/Swift/Float/floatingPointClass)

The classification of this value.

### Encoding and Decoding Values

[`func encode(to: any Encoder) throws`](/documentation/Swift/Float/encode(to:))

Encodes this value into the given encoder.

[`init(from: any Decoder) throws`](/documentation/Swift/Float/init(from:))

Creates a new instance by decoding from the given decoder.

### Creating a Range

[`static func ... (Self, Self) -> ClosedRange<Self>`](/documentation/Swift/Float/...(_:_:))

Returns a closed range that contains both of its bounds.

### Describing a Float

[`func hash(into: inout Hasher)`](/documentation/Swift/Float/hash(into:))

Hashes the essential components of this value by feeding them into the
given hasher.

[`var description: String`](/documentation/Swift/Float/description)

A textual representation of the value.

[`var debugDescription: String`](/documentation/Swift/Float/debugDescription)

A textual representation of the value, suitable for debugging.

[`var customMirror: Mirror`](/documentation/Swift/Float/customMirror)

A mirror that reflects the `Float` instance.

[`var hashValue: Int`](/documentation/Swift/Float/hashValue)

The hash value.

### SIMD-Supporting Types

[`typealias SIMDMaskScalar`](/documentation/Swift/Float/SIMDMaskScalar)

[`struct SIMD2Storage`](/documentation/Swift/Float/SIMD2Storage)

Storage for a vector of two floating-point values.

[`struct SIMD4Storage`](/documentation/Swift/Float/SIMD4Storage)

Storage for a vector of four floating-point values.

[`struct SIMD8Storage`](/documentation/Swift/Float/SIMD8Storage)

Storage for a vector of eight floating-point values.

[`struct SIMD16Storage`](/documentation/Swift/Float/SIMD16Storage)

Storage for a vector of 16 floating-point values.

[`struct SIMD32Storage`](/documentation/Swift/Float/SIMD32Storage)

Storage for a vector of 32 floating-point values.

[`struct SIMD64Storage`](/documentation/Swift/Float/SIMD64Storage)

Storage for a vector of 64 floating-point values.

### Infrequently Used Functionality

[`init()`](/documentation/Swift/Float/init())

[`init(integerLiteral: Int64)`](/documentation/Swift/Float/init(integerLiteral:))

Creates an instance initialized to the specified integer value.

[`init(floatLiteral: Float)`](/documentation/Swift/Float/init(floatLiteral:))

Creates an instance initialized to the specified floating-point value.

[`init(integerLiteral: Self)`](/documentation/Swift/Float/init(integerLiteral:)-6hc7h)

[`func advanced(by: Float) -> Float`](/documentation/Swift/Float/advanced(by:))

Returns a value that is offset the specified distance from this value.

[`func distance(to: Float) -> Float`](/documentation/Swift/Float/distance(to:))

Returns the distance from this value to the given value, expressed as a
stride.

[`func write<Target>(to: inout Target)`](/documentation/Swift/Float/write(to:))

Writes a textual representation of this instance into the given output
stream.

### Deprecated

[`init(NSNumber)`](/documentation/Swift/Float/init(_:)-7dbrz)

[`var customPlaygroundQuickLook: _PlaygroundQuickLook`](/documentation/Swift/Float/customPlaygroundQuickLook)

A custom playground Quick Look for the `Float` instance.

### Type Properties

[`static var mlMultiArrayDataType: MLMultiArrayDataType`](/documentation/Swift/Float/mlMultiArrayDataType)

### Default Implementations

[AdditiveArithmetic Implementations](/documentation/Swift/Float/AdditiveArithmetic-Implementations)

[AtomicRepresentable Implementations](/documentation/Swift/Float/AtomicRepresentable-Implementations)

[BinaryFloatingPoint Implementations](/documentation/Swift/Float/BinaryFloatingPoint-Implementations)

[Comparable Implementations](/documentation/Swift/Float/Comparable-Implementations)

[CustomDebugStringConvertible Implementations](/documentation/Swift/Float/CustomDebugStringConvertible-Implementations)

[CustomReflectable Implementations](/documentation/Swift/Float/CustomReflectable-Implementations)

[CustomStringConvertible Implementations](/documentation/Swift/Float/CustomStringConvertible-Implementations)

[Decodable Implementations](/documentation/Swift/Float/Decodable-Implementations)

[Encodable Implementations](/documentation/Swift/Float/Encodable-Implementations)

[Equatable Implementations](/documentation/Swift/Float/Equatable-Implementations)

[ExpressibleByFloatLiteral Implementations](/documentation/Swift/Float/ExpressibleByFloatLiteral-Implementations)

[ExpressibleByIntegerLiteral Implementations](/documentation/Swift/Float/ExpressibleByIntegerLiteral-Implementations)

[FloatingPoint Implementations](/documentation/Swift/Float/FloatingPoint-Implementations)

[Hashable Implementations](/documentation/Swift/Float/Hashable-Implementations)

[LosslessStringConvertible Implementations](/documentation/Swift/Float/LosslessStringConvertible-Implementations)

[Numeric Implementations](/documentation/Swift/Float/Numeric-Implementations)

[OperationParameter Implementations](/documentation/Swift/Float/OperationParameter-Implementations)

[SIMDScalar Implementations](/documentation/Swift/Float/SIMDScalar-Implementations)

[SignedNumeric Implementations](/documentation/Swift/Float/SignedNumeric-Implementations)

[Strideable Implementations](/documentation/Swift/Float/Strideable-Implementations)

[TextOutputStreamable Implementations](/documentation/Swift/Float/TextOutputStreamable-Implementations)

## Relationships

### Conforms To

[`USDValueProtocol`](/documentation/USDKit/USDValueProtocol)

[`Plottable`](/documentation/Charts/Plottable)

[`BNNSScalar`](/documentation/Accelerate/BNNSScalar)

[`InstructionsRepresentable`](/documentation/FoundationModels/InstructionsRepresentable)

[`PromptRepresentable`](/documentation/FoundationModels/PromptRepresentable)

[`MLTensorScalar`](/documentation/CoreML/MLTensorScalar)

[`AdditiveArithmetic`](/documentation/Swift/AdditiveArithmetic)

[`CustomReflectable`](/documentation/Swift/CustomReflectable)

[`Strideable`](/documentation/Swift/Strideable)

[`vDSP_FloatingPointGeneratable`](/documentation/Accelerate/vDSP_FloatingPointGeneratable)

[`OperationParameter`](/documentation/Accelerate/BNNSGraph/Builder/OperationParameter)

[`PrimitivePlottableProtocol`](/documentation/Charts/PrimitivePlottableProtocol)

[`VectorArithmetic`](/documentation/SwiftUI/VectorArithmetic)

[`vDSP_FloatingPointDiscreteFourierTransformable`](/documentation/Accelerate/vDSP_FloatingPointDiscreteFourierTransformable)

[`BitwiseCopyable`](/documentation/Swift/BitwiseCopyable)

[`TextOutputStreamable`](/documentation/Swift/TextOutputStreamable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CKRecordValueProtocol`](/documentation/CloudKit/CKRecordValueProtocol)

[`BinaryFloatingPoint`](/documentation/Swift/BinaryFloatingPoint)

[`CVAttachmentValueRepresentable`](/documentation/CoreVideo/CVAttachmentValueRepresentable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Copyable`](/documentation/Swift/Copyable)

[`BindableData`](/documentation/RealityKit/BindableData)

[`ConvertibleFromGeneratedContent`](/documentation/FoundationModels/ConvertibleFromGeneratedContent)

[`Value`](/documentation/USDKit/USDPrim/Attribute/Value)

[`ConvertibleToGeneratedContent`](/documentation/FoundationModels/ConvertibleToGeneratedContent)

[`ConvertibleToBytes`](/documentation/Swift/ConvertibleToBytes)

[`MetadataValue`](/documentation/USDKit/USDStage/Object/MetadataValue)

[`LosslessStringConvertible`](/documentation/Swift/LosslessStringConvertible)

[`Numeric`](/documentation/Swift/Numeric)

[`MLShapedArrayScalar`](/documentation/CoreML/MLShapedArrayScalar)

[`EntityIdentifierConvertible`](/documentation/AppIntents/EntityIdentifierConvertible)

[`Comparable`](/documentation/Swift/Comparable)

[`vDSP_FloatingPointConvertable`](/documentation/Accelerate/vDSP_FloatingPointConvertable)

[`Hashable`](/documentation/Swift/Hashable)

[`ConvertibleFromBytes`](/documentation/Swift/ConvertibleFromBytes)

[`ExpressibleByIntegerLiteral`](/documentation/Swift/ExpressibleByIntegerLiteral)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Generable`](/documentation/FoundationModels/Generable)

[`vDSP_DiscreteFourierTransformable`](/documentation/Accelerate/vDSP_DiscreteFourierTransformable)

[`Escapable`](/documentation/Swift/Escapable)

[`AtomicRepresentable`](/documentation/Synchronization/AtomicRepresentable)

[`FloatingPoint`](/documentation/Swift/FloatingPoint)

[`Sendable`](/documentation/Swift/Sendable)

[`vDSP_FloatingPointBiquadFilterable`](/documentation/Accelerate/vDSP_FloatingPointBiquadFilterable)

[`Decodable`](/documentation/Swift/Decodable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Encodable`](/documentation/Swift/Encodable)

[`ExpressibleByFloatLiteral`](/documentation/Swift/ExpressibleByFloatLiteral)

[`AnimatableData`](/documentation/RealityKit/AnimatableData)

[`Equatable`](/documentation/Swift/Equatable)

[`SIMDScalar`](/documentation/Swift/SIMDScalar)

[`SignedNumeric`](/documentation/Swift/SignedNumeric)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)