Skip to content

Commit

Permalink
Remove NumericShims module; we don't need it thanks to silgen_name.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentyrone committed Jul 19, 2019
1 parent 8aab7a9 commit fa9422e
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 468 deletions.
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ let package = Package(
],
targets: [
.target(name: "Complex", dependencies: ["ElementaryFunctions"]),
.target(name: "ElementaryFunctions", dependencies: ["NumericsShims"]),
.target(name: "NumericsShims", dependencies: []),
.target(name: "ElementaryFunctions", dependencies: []),

.testTarget(name: "ComplexTests", dependencies: ["Complex"]),
.testTarget(name: "ElementaryFunctionTests", dependencies: ["ElementaryFunctions"]),
Expand Down
10 changes: 5 additions & 5 deletions Sources/ElementaryFunctions/ElementaryFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// - Exponential, trigonometric, and hyperbolic functions:
/// `exp`, `expm1`, `cos`, `sin`, `tan`, `cosh`, `sinh`, and `tanh`.
/// - Logarithmic, inverse trigonometric, and inverse hyperbolic functions:
/// `log`, `log1p`, `acos`, `asin`, `atan`, `acosh`, `asinh`, and `atanh`.
/// `log`, `logp1`, `acos`, `asin`, `atan`, `acosh`, `asinh`, and `atanh`.
/// - Power and root functions:
/// `pow`, `sqrt`, and `root`.
///
Expand Down Expand Up @@ -174,7 +174,7 @@ public protocol ElementaryFunctions {
///
/// See also:
/// -
/// - `log1p()`
/// - `logp1()`
/// - `log2()` (for types conforming to `RealFunctions`)
/// - `log10()` (for types conforming to `RealFunctions`)
///
Expand All @@ -188,7 +188,7 @@ public protocol ElementaryFunctions {
/// - `log()`
/// - `log2()` (for types conforming to `RealFunctions`)
/// - `log10()` (for types conforming to `RealFunctions`)
static func log1p(_ x: Self) -> Self
static func logp1(_ x: Self) -> Self

/// The [inverse hyperbolic cosine][wiki] of `x`.
/// ```
Expand Down Expand Up @@ -374,7 +374,7 @@ public protocol RealFunctions: ElementaryFunctions {
/// -
/// - `exp2()`
/// - `log()`
/// - `log1p()`
/// - `logp1()`
/// - `log10()`
static func log2(_ x: Self) -> Self

Expand All @@ -384,7 +384,7 @@ public protocol RealFunctions: ElementaryFunctions {
/// -
/// - `exp10()`
/// - `log()`
/// - `log1p()`
/// - `logp1()`
/// - `log2()`
static func log10(_ x: Self) -> Self

Expand Down
230 changes: 141 additions & 89 deletions Sources/ElementaryFunctions/ScalarConformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,129 +10,181 @@
//
//===----------------------------------------------------------------------===//

import NumericsShims

extension Float: Real {
@_transparent public static func cos(_ x: Float) -> Float { return swift_cosf(x) }
@_transparent public static func sin(_ x: Float) -> Float { return swift_sinf(x) }
@_transparent public static func tan(_ x: Float) -> Float { return swift_tanf(x) }
@_transparent public static func acos(_ x: Float) -> Float { return swift_acosf(x) }
@_transparent public static func asin(_ x: Float) -> Float { return swift_asinf(x) }
@_transparent public static func atan(_ x: Float) -> Float { return swift_atanf(x) }
@_transparent public static func cosh(_ x: Float) -> Float { return swift_coshf(x) }
@_transparent public static func sinh(_ x: Float) -> Float { return swift_sinhf(x) }
@_transparent public static func tanh(_ x: Float) -> Float { return swift_tanhf(x) }
@_transparent public static func acosh(_ x: Float) -> Float { return swift_acoshf(x) }
@_transparent public static func asinh(_ x: Float) -> Float { return swift_asinhf(x) }
@_transparent public static func atanh(_ x: Float) -> Float { return swift_atanhf(x) }
@_transparent public static func exp(_ x: Float) -> Float { return swift_expf(x) }
@_transparent public static func expm1(_ x: Float) -> Float { return swift_expm1f(x) }
@_transparent public static func log(_ x: Float) -> Float { return swift_logf(x) }
@_transparent public static func log1p(_ x: Float) -> Float { return swift_log1pf(x) }
@_silgen_name("cosf") public static func cos(_ x: Float) -> Float
@_silgen_name("sinf") public static func sin(_ x: Float) -> Float
@_silgen_name("tanf") public static func tan(_ x: Float) -> Float
@_silgen_name("acosf") public static func acos(_ x: Float) -> Float
@_silgen_name("asinf") public static func asin(_ x: Float) -> Float
@_silgen_name("atanf") public static func atan(_ x: Float) -> Float
@_silgen_name("coshf") public static func cosh(_ x: Float) -> Float
@_silgen_name("sinhf") public static func sinh(_ x: Float) -> Float
@_silgen_name("tanhf") public static func tanh(_ x: Float) -> Float
@_silgen_name("acoshf") public static func acosh(_ x: Float) -> Float
@_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("logf") public static func log(_ x: Float) -> Float
@_silgen_name("log1pf") public static func logp1(_ 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
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@_silgen_name("__exp10f") public static func exp10(_ x: Float) -> Float
#endif
@_silgen_name("hypotf") public static func hypot(_ x: Float, _ y: Float) -> Float
@_silgen_name("tgammaf") public static func gamma(_ x: Float) -> Float
@_silgen_name("log2f") public static func log2(_ x: Float) -> Float
@_silgen_name("log10f") public static func log10(_ x: Float) -> Float

@usableFromInline @_silgen_name("powf")
internal static func libm_pow(_ x: Float, _ y: Float) -> Float

@_transparent public static func pow(_ x: Float, _ y: Float) -> Float {
guard x >= 0 else { return .nan }
return swift_powf(x, y)
return libm_pow(x, y)
}

@_transparent public static func pow(_ x: Float, _ n: Int) -> Float {
// TODO: this implementation is not quite correct, because n may be
// rounded in conversion to Float. This only effects very extreme cases,
// so we'll leave it alone for now; however, it gets the sign wrong if
// it rounds an odd number to an even number, so we should fix it soon.
return swift_powf(x, Float(n))
return libm_pow(x, Float(n))
}
@_transparent public static func atan2(y: Float, x: Float) -> Float { return swift_atan2f(y, x) }
@_transparent public static func erf(_ x: Float) -> Float { return swift_erff(x) }
@_transparent public static func erfc(_ x: Float) -> Float { return swift_erfcf(x) }
@_transparent public static func exp2(_ x: Float) -> Float { return swift_exp2f(x) }
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@_silgen_name("__exp10f") public static func exp10(_ x: Float) -> Float
#endif
@_transparent public static func hypot(_ x: Float, _ y: Float) -> Float { return swift_hypotf(x, y) }
@_transparent public static func gamma(_ x: Float) -> Float { return swift_gammaf(x) }
@_transparent public static func log2(_ x: Float) -> Float { return swift_log2f(x) }
@_transparent public static func log10(_ x: Float) -> Float { return swift_log10f(x) }

@usableFromInline @_silgen_name("atan2f")
internal static func libm_atan2(_ y: Float, _ x: Float) -> Float

@_transparent public static func atan2(y: Float, x: Float) -> Float {
return libm_atan2(y, x)
}

#if !os(Windows)
@_transparent public static func logGamma(_ x: Float) -> Float { return swift_lgammaf(x) }
@usableFromInline @_silgen_name("lgammaf_r")
internal static func libm_lgamma(_ x: Float, _ signgam: UnsafeMutablePointer<Int32>) -> Float

@_transparent public static func logGamma(_ x: Float) -> Float {
var dontCare: Int32 = 0
return libm_lgamma(x, &dontCare)
}
#endif
}

extension Double: Real {
@_transparent public static func cos(_ x: Double) -> Double { return swift_cos(x) }
@_transparent public static func sin(_ x: Double) -> Double { return swift_sin(x) }
@_transparent public static func tan(_ x: Double) -> Double { return swift_tan(x) }
@_transparent public static func acos(_ x: Double) -> Double { return swift_acos(x) }
@_transparent public static func asin(_ x: Double) -> Double { return swift_asin(x) }
@_transparent public static func atan(_ x: Double) -> Double { return swift_atan(x) }
@_transparent public static func cosh(_ x: Double) -> Double { return swift_cosh(x) }
@_transparent public static func sinh(_ x: Double) -> Double { return swift_sinh(x) }
@_transparent public static func tanh(_ x: Double) -> Double { return swift_tanh(x) }
@_transparent public static func acosh(_ x: Double) -> Double { return swift_acosh(x) }
@_transparent public static func asinh(_ x: Double) -> Double { return swift_asinh(x) }
@_transparent public static func atanh(_ x: Double) -> Double { return swift_atanh(x) }
@_transparent public static func exp(_ x: Double) -> Double { return swift_exp(x) }
@_transparent public static func expm1(_ x: Double) -> Double { return swift_expm1(x) }
@_transparent public static func log(_ x: Double) -> Double { return swift_log(x) }
@_transparent public static func log1p(_ x: Double) -> Double { return swift_log1p(x) }
@_silgen_name("cos") public static func cos(_ x: Double) -> Double
@_silgen_name("sin") public static func sin(_ x: Double) -> Double
@_silgen_name("tan") public static func tan(_ x: Double) -> Double
@_silgen_name("acos") public static func acos(_ x: Double) -> Double
@_silgen_name("asin") public static func asin(_ x: Double) -> Double
@_silgen_name("atan") public static func atan(_ x: Double) -> Double
@_silgen_name("cosh") public static func cosh(_ x: Double) -> Double
@_silgen_name("sinh") public static func sinh(_ x: Double) -> Double
@_silgen_name("tanh") public static func tanh(_ x: Double) -> Double
@_silgen_name("acosh") public static func acosh(_ x: Double) -> Double
@_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("log") public static func log(_ x: Double) -> Double
@_silgen_name("log1p") public static func logp1(_ 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
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@_silgen_name("__exp10") public static func exp10(_ x: Double) -> Double
#endif
@_silgen_name("hypot") public static func hypot(_ x: Double, _ y: Double) -> Double
@_silgen_name("tgamma") public static func gamma(_ x: Double) -> Double
@_silgen_name("log2") public static func log2(_ x: Double) -> Double
@_silgen_name("log10") public static func log10(_ x: Double) -> Double

@usableFromInline @_silgen_name("pow")
internal static func libm_pow(_ x: Double, _ y: Double) -> Double

@_transparent public static func pow(_ x: Double, _ y: Double) -> Double {
guard x >= 0 else { return .nan }
return swift_pow(x, y)
return libm_pow(x, y)
}

@_transparent public static func pow(_ x: Double, _ n: Int) -> Double {
// TODO: this implementation is not quite correct, because n may be
// rounded in conversion to Double. This only effects very extreme cases,
// so we'll leave it alone for now; however, it gets the sign wrong if
// it rounds an odd number to an even number, so we should fix it soon.
return swift_pow(x, Double(n))
return libm_pow(x, Double(n))
}
@_transparent public static func atan2(y: Double, x: Double) -> Double { return swift_atan2(y, x) }
@_transparent public static func erf(_ x: Double) -> Double { return swift_erf(x) }
@_transparent public static func erfc(_ x: Double) -> Double { return swift_erfc(x) }
@_transparent public static func exp2(_ x: Double) -> Double { return swift_exp2(x) }
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@_silgen_name("__exp10") public static func exp10(_ x: Double) -> Double
#endif
@_transparent public static func hypot(_ x: Double, _ y: Double) -> Double { return swift_hypot(x, y) }
@_transparent public static func gamma(_ x: Double) -> Double { return swift_gamma(x) }
@_transparent public static func log2(_ x: Double) -> Double { return swift_log2(x) }
@_transparent public static func log10(_ x: Double) -> Double { return swift_log10(x) }

@usableFromInline @_silgen_name("atan2")
internal static func libm_atan2(_ y: Double, _ x: Double) -> Double

@_transparent public static func atan2(y: Double, x: Double) -> Double {
return libm_atan2(y, x)
}

#if !os(Windows)
@_transparent public static func logGamma(_ x: Double) -> Double { return swift_lgamma(x) }
@usableFromInline @_silgen_name("lgamma_r")
internal static func libm_lgamma_r(_ x: Double, _ signgam: UnsafeMutablePointer<Int32>) -> Double

@_transparent public static func logGamma(_ x: Double) -> Double {
var dontCare: Int32 = 0
return libm_lgamma_r(x, &dontCare)
}
#endif
}

#if (arch(i386) || arch(x86_64)) && !os(Windows) && !os(Android)
extension Float80: Real {
@_transparent public static func cos(_ x: Float80) -> Float80 { return swift_cosl(x) }
@_transparent public static func sin(_ x: Float80) -> Float80 { return swift_sinl(x) }
@_transparent public static func tan(_ x: Float80) -> Float80 { return swift_tanl(x) }
@_transparent public static func acos(_ x: Float80) -> Float80 { return swift_acosl(x) }
@_transparent public static func asin(_ x: Float80) -> Float80 { return swift_asinl(x) }
@_transparent public static func atan(_ x: Float80) -> Float80 { return swift_atanl(x) }
@_transparent public static func cosh(_ x: Float80) -> Float80 { return swift_coshl(x) }
@_transparent public static func sinh(_ x: Float80) -> Float80 { return swift_sinhl(x) }
@_transparent public static func tanh(_ x: Float80) -> Float80 { return swift_tanhl(x) }
@_transparent public static func acosh(_ x: Float80) -> Float80 { return swift_acoshl(x) }
@_transparent public static func asinh(_ x: Float80) -> Float80 { return swift_asinhl(x) }
@_transparent public static func atanh(_ x: Float80) -> Float80 { return swift_atanhl(x) }
@_transparent public static func exp(_ x: Float80) -> Float80 { return swift_expl(x) }
@_transparent public static func expm1(_ x: Float80) -> Float80 { return swift_expm1l(x) }
@_transparent public static func log(_ x: Float80) -> Float80 { return swift_logl(x) }
@_transparent public static func log1p(_ x: Float80) -> Float80 { return swift_log1pl(x) }
@_silgen_name("cosl") public static func cos(_ x: Float80) -> Float80
@_silgen_name("sinl") public static func sin(_ x: Float80) -> Float80
@_silgen_name("tanl") public static func tan(_ x: Float80) -> Float80
@_silgen_name("acosl") public static func acos(_ x: Float80) -> Float80
@_silgen_name("asinl") public static func asin(_ x: Float80) -> Float80
@_silgen_name("atanl") public static func atan(_ x: Float80) -> Float80
@_silgen_name("coshl") public static func cosh(_ x: Float80) -> Float80
@_silgen_name("sinhl") public static func sinh(_ x: Float80) -> Float80
@_silgen_name("tanhl") public static func tanh(_ x: Float80) -> Float80
@_silgen_name("acoshl") public static func acosh(_ x: Float80) -> Float80
@_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("logl") public static func log(_ x: Float80) -> Float80
@_silgen_name("log1pl") public static func logp1(_ 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
@_silgen_name("hypotl") public static func hypot(_ x: Float80, _ y: Float80) -> Float80
@_silgen_name("tgammal") public static func gamma(_ x: Float80) -> Float80
@_silgen_name("log2l") public static func log2(_ x: Float80) -> Float80
@_silgen_name("log10l") public static func log10(_ x: Float80) -> Float80

@usableFromInline @_silgen_name("powl")
internal static func libm_pow(_ x: Float80, _ y: Float80) -> Float80

@_transparent public static func pow(_ x: Float80, _ y: Float80) -> Float80 {
guard x >= 0 else { return .nan }
return swift_powl(x, y)
return libm_pow(x, y)
}

@_transparent public static func pow(_ x: Float80, _ n: Int) -> Float80 {
return swift_powl(x, Float80(n))
return libm_pow(x, Float80(n))
}

@usableFromInline @_silgen_name("atan2l")
internal static func libm_atan2(_ y: Float80, _ x: Float80) -> Float80

@_transparent public static func atan2(y: Float80, x: Float80) -> Float80 {
return libm_atan2(y, x)
}

@usableFromInline @_silgen_name("lgammal_r")
internal static func libm_lgamma_r(_ x: Float80, _ signgam: UnsafeMutablePointer<Int32>) -> Float80

@_transparent public static func logGamma(_ x: Float80) -> Float80 {
var dontCare: Int32 = 0
return libm_lgamma_r(x, &dontCare)
}
@_transparent public static func atan2(y: Float80, x: Float80) -> Float80 { return swift_atan2l(y, x) }
@_transparent public static func erf(_ x: Float80) -> Float80 { return swift_erfl(x) }
@_transparent public static func erfc(_ x: Float80) -> Float80 { return swift_erfcl(x) }
@_transparent public static func exp2(_ x: Float80) -> Float80 { return swift_exp2l(x) }
@_transparent public static func hypot(_ x: Float80, _ y: Float80) -> Float80 { return swift_hypotl(x, y) }
@_transparent public static func gamma(_ x: Float80) -> Float80 { return swift_gammal(x) }
@_transparent public static func log2(_ x: Float80) -> Float80 { return swift_log2l(x) }
@_transparent public static func log10(_ x: Float80) -> Float80 { return swift_log10l(x) }
@_transparent public static func logGamma(_ x: Float80) -> Float80 { return swift_lgammal(x) }
}
#endif
20 changes: 0 additions & 20 deletions Sources/NumericsShims/NumericsShims.c

This file was deleted.

Loading

0 comments on commit fa9422e

Please sign in to comment.