Swift Tutorial Swift Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Swift - scalbln() Function



The Swift scalbln() function returns the result of multiplying the significand (x) by FLT_RADIX raised to the power of the exponent (n). On most platforms, FLT_RADIX is 2. Mathematically, it can be expressed as:

scalbln(x,n) = x * FLT_RADIXn

Syntax

In Foundation framework, it is defined as follows:

public func scalbln(_ __x: Double, _ __n: Int) -> Double

Parameters

x Specify the value representing the significand.
n Specify the value of the exponent.

Return Value

Returns x * FLT_RADIXn.

Example:

The example below shows the usage of scalbln() function.

import Foundation

print("scalbln(0.8, 2) = \(scalbln(0.8, 2))")
print("scalbln(5, 2) = \(scalbln(5, 2))")
print("scalbln(2.0, 3) = \(scalbln(2.0, 3))")
print("scalbln(3.0, 4) = \(scalbln(3.0, 4))")

The output of the above code will be:

scalbln(0.8, 2) = 3.2
scalbln(5, 2) = 20.0
scalbln(2.0, 3) = 16.0
scalbln(3.0, 4) = 48.0

❮ Swift Math Functions

5