Swift Tutorial Swift References

Swift - cbrt() Function

The Swift cbrt() function returns the cube root of the given number.


In Foundation framework, it is defined as follows:

public func cbrt(_ x: CGFloat) -> CGFloat
public func cbrt(_ x: Float) -> Float
public func cbrt(_ x: Float80) -> Float80
public func cbrt(_ __x: Double) -> Double


x Specify a number.

Return Value

Returns the cube root of the specified number.


In the example below, cbrt() function is used to find out the cube root of the given number.

import Foundation

print("cbrt(-64.0) = \(cbrt(-64.0))")
print("cbrt(8.0) = \(cbrt(8.0))")
print("cbrt(125.0) = \(cbrt(125.0))")
print("cbrt(500.0) = \(cbrt(500.0))")

The output of the above code will be:

cbrt(-64.0) = -4.0
cbrt(8.0) = 2.0
cbrt(125.0) = 5.0
cbrt(500.0) = 7.937005259840998

❮ Swift Math Functions