ElementaryFunctions

A type that has elementary functions available.

ElementaryFunctions.swift:55
protocol ElementaryFunctions : AdditiveArithmetic
Browse conforming types

An “elementary function” is a function built up from powers, roots, exponentials, logarithms, trigonometric functions (sin, cos, tan) and their inverses, and the hyperbolic functions (sinh, cosh, tanh) and their inverses.

Conformance to this protocol means that all of these building blocks are available as static functions on the type.

let x: Float = 1
let y = Float.sin(x) // 0.84147096

There are three broad families of functions defined by ElementaryFunctions:

  • Exponential, trigonometric, and hyperbolic functions: exp, expMinusOne, cos, sin, tan, cosh, sinh, and tanh.

  • Logarithmic, inverse trigonometric, and inverse hyperbolic functions: log, log(onePlus:), acos, asin, atan, acosh, asinh, and atanh.

  • Power and root functions: pow, sqrt, and root.

ElementaryFunctions conformance implies AdditiveArithmetic, so addition and subtraction and the .zero property are also available.

There are two other protocols that you are more likely to want to use directly:

RealFunctions refines ElementaryFunctions and includes additional functions specific to real number types.

Real conforms to RealFunctions and FloatingPoint, and is the protocol that you will want to use most often for generic code.

See Also:

  • RealFunctions

  • Real