Real

A type that models the real numbers.

Real.swift:31
protocol Real : AlgebraicField, RealFunctions, FloatingPoint
Browse conforming types

Types conforming to this protocol provide the arithmetic and utility operations defined by the FloatingPoint protocol, and provide all of the math functions defined by the ElementaryFunctions and RealFunctions protocols. This protocol does not add any additional conformances itself, but is very useful as a protocol against which to write generic code. For example, we can naturally write a generic implementation of a sigmoid function:

func sigmoid<T: Real>(_ x: T) -> T {
  return 1/(1 + .exp(-x))
}

See Also:

  • ElementaryFunctions

  • RealFunctions

  • AlgebraicField