Floating-point types are used to hold fractional numbers. The main floating-point types in the standard library are Float
and Double
. The Swift team created a FloatingPoint
protocol to hold common math operations, making it easier for you to create functions that support all of the floating-point types available. In this section, we will cover additions to the FloatingPoint
protocol and rounding functions.
The current FloatingPoint
protocol doesn't provide a full set of features to really conform to an IEEE 754 https://en.wikipedia.org/wiki/IEEE_floating_point#CITEREFIEEE_7542008 type. The changes to the FloatingPoint
protocol are meant to expand coverage of the operations that most would expect to be included. A second protocol BinaryFloatingPoint
(conforms to FloatingPoint
) has also been added to Swift and will be useful for generic programming.
The FloatingPoint
protocol now contains most of the IEEE 754 basic operations...