diff --git a/Sources/ElementaryFunctions/ElementaryFunctions.swift b/Sources/ElementaryFunctions/ElementaryFunctions.swift index 3f90f73..4653a0f 100644 --- a/Sources/ElementaryFunctions/ElementaryFunctions.swift +++ b/Sources/ElementaryFunctions/ElementaryFunctions.swift @@ -27,9 +27,9 @@ /// /// There are three broad families of functions defined by `ElementaryFunctions`: /// - Exponential, trigonometric, and hyperbolic functions: -/// `exp`, `expm1`, `cos`, `sin`, `tan`, `cosh`, `sinh`, and `tanh`. +/// `exp`, `expMinusOne`, `cos`, `sin`, `tan`, `cosh`, `sinh`, and `tanh`. /// - Logarithmic, inverse trigonometric, and inverse hyperbolic functions: -/// `log`, `logp1`, `acos`, `asin`, `atan`, `acosh`, `asinh`, and `atanh`. +/// `log`, `log(onePlus:)`, `acos`, `asin`, `atan`, `acosh`, `asinh`, and `atanh`. /// - Power and root functions: /// `pow`, `sqrt`, and `root`. /// @@ -47,7 +47,7 @@ public protocol ElementaryFunctions { /// /// See also: /// - - /// - `expm1()` + /// - `expMinusOne()` /// - `exp2()` (for types conforming to `RealFunctions`) /// - `exp10()` (for types conforming to `RealFunctions`) /// @@ -57,15 +57,15 @@ public protocol ElementaryFunctions { /// exp(x) - 1, computed in such a way as to maintain accuracy for small x. /// /// When `x` is close to zero, the expression `.exp(x) - 1` suffers from catastrophic - /// cancellation and the result will not have full accuracy. The `.expm1(x)` function gives + /// cancellation and the result will not have full accuracy. The `.expMinusOne(x)` function gives /// you a means to address this problem. /// /// As an example, consider the expression `(x + 1)*exp(x) - 1`. When `x` is smaller /// than `.ulpOfOne`, this expression evaluates to `0.0`, when it should actually round to /// `2*x`. We can get a full-accuracy result by using the following instead: /// ``` - /// let expm1x = .expm1(x) - /// return x*(expm1x + 1) + expm1x + /// let t = .expMinusOne(x) + /// return x*(t+1) + t // x*exp(x) + (exp(x)-1) = (x+1)*exp(x) - 1 /// ``` /// This re-written expression delivers an accurate result for all values of `x`, not just for /// small values. @@ -75,7 +75,7 @@ public protocol ElementaryFunctions { /// - `exp()` /// - `exp2()` (for types conforming to `RealFunctions`) /// - `exp10()` (for types conforming to `RealFunctions`) - static func expm1(_ x: Self) -> Self + static func expMinusOne(_ x: Self) -> Self /// The [hyperbolic cosine][wiki] of `x`. /// ``` @@ -174,7 +174,7 @@ public protocol ElementaryFunctions { /// /// See also: /// - - /// - `logp1()` + /// - `log(onePlus:)` /// - `log2()` (for types conforming to `RealFunctions`) /// - `log10()` (for types conforming to `RealFunctions`) /// @@ -188,7 +188,7 @@ public protocol ElementaryFunctions { /// - `log()` /// - `log2()` (for types conforming to `RealFunctions`) /// - `log10()` (for types conforming to `RealFunctions`) - static func logp1(_ x: Self) -> Self + static func log(onePlus x: Self) -> Self /// The [inverse hyperbolic cosine][wiki] of `x`. /// ``` @@ -340,7 +340,7 @@ public protocol RealFunctions: ElementaryFunctions { /// See also: /// - /// - `exp()` - /// - `expm1()` + /// - `expMinusOne()` /// - `exp10()` /// - `log2()` /// - `pow()` @@ -351,7 +351,7 @@ public protocol RealFunctions: ElementaryFunctions { /// See also: /// - /// - `exp()` - /// - `expm1()` + /// - `expMinusOne()` /// - `exp2()` /// - `log10()` /// - `pow()` @@ -374,7 +374,7 @@ public protocol RealFunctions: ElementaryFunctions { /// - /// - `exp2()` /// - `log()` - /// - `logp1()` + /// - `log(onePlus:)` /// - `log10()` static func log2(_ x: Self) -> Self @@ -384,7 +384,7 @@ public protocol RealFunctions: ElementaryFunctions { /// - /// - `exp10()` /// - `log()` - /// - `logp1()` + /// - `log(onePlus:)` /// - `log2()` static func log10(_ x: Self) -> Self diff --git a/Sources/ElementaryFunctions/ScalarConformances.swift b/Sources/ElementaryFunctions/ScalarConformances.swift index ebc0898..eef5319 100644 --- a/Sources/ElementaryFunctions/ScalarConformances.swift +++ b/Sources/ElementaryFunctions/ScalarConformances.swift @@ -24,9 +24,9 @@ extension Float: Real { @_silgen_name("asinhf") public static func asinh(_ x: Float) -> Float @_silgen_name("atanhf") public static func atanh(_ x: Float) -> Float @_silgen_name("expf") public static func exp(_ x: Float) -> Float - @_silgen_name("expm1f") public static func expm1(_ x: Float) -> Float + @_silgen_name("expMinusOnef") public static func expMinusOne(_ x: Float) -> Float @_silgen_name("logf") public static func log(_ x: Float) -> Float - @_silgen_name("log1pf") public static func logp1(_ x: Float) -> Float + @_silgen_name("log1pf") public static func log(onePlus x: Float) -> Float @_silgen_name("erff") public static func erf(_ x: Float) -> Float @_silgen_name("erfcf") public static func erfc(_ x: Float) -> Float @_silgen_name("exp2f") public static func exp2(_ x: Float) -> Float @@ -86,9 +86,9 @@ extension Double: Real { @_silgen_name("asinh") public static func asinh(_ x: Double) -> Double @_silgen_name("atanh") public static func atanh(_ x: Double) -> Double @_silgen_name("exp") public static func exp(_ x: Double) -> Double - @_silgen_name("expm1") public static func expm1(_ x: Double) -> Double + @_silgen_name("expMinusOne") public static func expMinusOne(_ x: Double) -> Double @_silgen_name("log") public static func log(_ x: Double) -> Double - @_silgen_name("log1p") public static func logp1(_ x: Double) -> Double + @_silgen_name("log1p") public static func log(onePlus x: Double) -> Double @_silgen_name("erf") public static func erf(_ x: Double) -> Double @_silgen_name("erfc") public static func erfc(_ x: Double) -> Double @_silgen_name("exp2") public static func exp2(_ x: Double) -> Double @@ -149,9 +149,9 @@ extension Float80: Real { @_silgen_name("asinhl") public static func asinh(_ x: Float80) -> Float80 @_silgen_name("atanhl") public static func atanh(_ x: Float80) -> Float80 @_silgen_name("expl") public static func exp(_ x: Float80) -> Float80 - @_silgen_name("expm1l") public static func expm1(_ x: Float80) -> Float80 + @_silgen_name("expMinusOnel") public static func expMinusOne(_ x: Float80) -> Float80 @_silgen_name("logl") public static func log(_ x: Float80) -> Float80 - @_silgen_name("log1pl") public static func logp1(_ x: Float80) -> Float80 + @_silgen_name("log1pl") public static func log(onePlus x: Float80) -> Float80 @_silgen_name("erfl") public static func erf(_ x: Float80) -> Float80 @_silgen_name("erfcl") public static func erfc(_ x: Float80) -> Float80 @_silgen_name("exp2l") public static func exp2(_ x: Float80) -> Float80 diff --git a/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift b/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift index d3e75b7..1023bba 100644 --- a/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift +++ b/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift @@ -58,9 +58,9 @@ internal extension ElementaryFunctions where Self: BinaryFloatingPoint { sanityCheck(0.3838510679136145687542956764205024589, Self.sinh(0.375)) sanityCheck(0.3583573983507859463193602315531580424, Self.tanh(0.375)) sanityCheck(1.4549914146182013360537936919875185083, Self.exp(0.375)) - sanityCheck(0.4549914146182013360537936919875185083, Self.expm1(0.375)) + sanityCheck(0.4549914146182013360537936919875185083, Self.expMinusOne(0.375)) sanityCheck(-0.980829253011726236856451127452003999, Self.log(0.375)) - sanityCheck(0.3184537311185346158102472135905995955, Self.logp1(0.375)) + sanityCheck(0.3184537311185346158102472135905995955, Self.log(onePlus: 0.375)) sanityCheck(-0.7211247851537041911608191553900547941, Self.root(-0.375, 3)) sanityCheck(0.6123724356957945245493210186764728479, Self.sqrt(0.375)) sanityCheck(0.54171335479545025876069682133938570, Self.pow(0.375, 0.625))