<!--
{
  "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(_:)`](/documentation/Swift/Float/init(_:)-7e965)

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

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

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

### Converting Strings

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

Creates a new instance from the given string.

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

### Converting Floating-Point Values

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

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

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

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

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

Creates a new instance that approximates the given value.

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

Creates a new instance initialized to the given value.

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

Creates a new instance that approximates the given value.

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

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

Creates a new instance that approximates the given value.

[`init(signOf:magnitudeOf:)`](/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:exponent:significand:)`](/documentation/Swift/Float/init(sign:exponent:significand:))

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

[`init(truncating:)`](/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(exactly:)`](/documentation/Swift/Float/init(exactly:)-8esr8)

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

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

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

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

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

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

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

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

[`init(exactly:)`](/documentation/Swift/Float/init(exactly:)-1h1oe)

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

[`init(exactly:)`](/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

[`random(in:)`](/documentation/Swift/Float/random(in:)-6ided)

Returns a random value within the specified range.

[`random(in:using:)`](/documentation/Swift/Float/random(in:using:)-1m6gf)

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

[`random(in:)`](/documentation/Swift/Float/random(in:)-5o5h8)

Returns a random value within the specified range.

[`random(in:using:)`](/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>

[`addingProduct(_:_:)`](/documentation/Swift/Float/addingProduct(_:_:))

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

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

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

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

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

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

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

[`remainder(dividingBy:)`](/documentation/Swift/Float/remainder(dividingBy:))

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

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

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

[`truncatingRemainder(dividingBy:)`](/documentation/Swift/Float/truncatingRemainder(dividingBy:))

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

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

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

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

Replaces this value with its additive inverse.

### Rounding Values

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

[`rounded(_:)`](/documentation/Swift/Float/rounded(_:))

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

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

[`round(_:)`](/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>

[`isEqual(to:)`](/documentation/Swift/Float/isEqual(to:))

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

[`isLess(than:)`](/documentation/Swift/Float/isLess(than:))

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

[`isLessThanOrEqualTo(_:)`](/documentation/Swift/Float/isLessThanOrEqualTo(_:))

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

[`isTotallyOrdered(belowOrEqualTo:)`](/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.

[`maximum(_:_:)`](/documentation/Swift/Float/maximum(_:_:))

Returns the greater of the two given values.

[`maximumMagnitude(_:_:)`](/documentation/Swift/Float/maximumMagnitude(_:_:))

Returns the value with greater magnitude.

[`minimum(_:_:)`](/documentation/Swift/Float/minimum(_:_:))

Returns the lesser of the two given values.

[`minimumMagnitude(_:_:)`](/documentation/Swift/Float/minimumMagnitude(_:_:))

Returns the value with lesser magnitude.

### Finding the Sign and Magnitude

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

The magnitude of this value.

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

The sign of the floating-point value.

[`Float.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

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

The unit in the last place of this value.

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

The significand of the floating-point value.

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

The exponent of the floating-point value.

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

The least representable value that compares greater than this value.

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

The greatest representable value that compares less than this value.

[`binade`](/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

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

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

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

Positive infinity.

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

The greatest finite number representable by this type.

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

A quiet NaN (“not a number”).

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

A signaling NaN (“not a number”).

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

The unit in the last place of 1.0.

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

The least positive normal number.

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

The least positive number.

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

The zero value.

### Working with Binary Representation

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

The bit pattern of the value’s encoding.

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

The raw encoding of the value’s significand field.

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

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

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

The raw encoding of the value’s exponent field.

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

The available number of fractional significand bits.

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

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

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

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

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

Creates a new value with the given bit pattern.

[`init(sign:exponentBitPattern:significandBitPattern:)`](/documentation/Swift/Float/init(sign:exponentBitPattern:significandBitPattern:))

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

[`init(nan:signaling:)`](/documentation/Swift/Float/init(nan:signaling:))

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

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

A type that can represent any written exponent.

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

A type that represents the encoded significand of a value.

### Querying a Float’s State

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

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

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

A Boolean value indicating whether this instance is finite.

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

A Boolean value indicating whether the instance is infinite.

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

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

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

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

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

A Boolean value indicating whether this instance is normal.

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

A Boolean value indicating whether the instance is subnormal.

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

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

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

The classification of this value.

### Encoding and Decoding Values

[`encode(to:)`](/documentation/Swift/Float/encode(to:))

Encodes this value into the given encoder.

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

Creates a new instance by decoding from the given decoder.

### Creating a Range

[`...(_:_:)`](/documentation/Swift/Float/...(_:_:))

Returns a closed range that contains both of its bounds.

### Describing a Float

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

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

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

A textual representation of the value.

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

A textual representation of the value, suitable for debugging.

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

A mirror that reflects the `Float` instance.

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

The hash value.

### SIMD-Supporting Types

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

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

Storage for a vector of two floating-point values.

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

Storage for a vector of four floating-point values.

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

Storage for a vector of eight floating-point values.

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

Storage for a vector of 16 floating-point values.

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

Storage for a vector of 32 floating-point values.

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

Storage for a vector of 64 floating-point values.

### Infrequently Used Functionality

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

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

Creates an instance initialized to the specified integer value.

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

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

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

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

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

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

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

[`write(to:)`](/documentation/Swift/Float/write(to:))

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

### Deprecated

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

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

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



---

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)
