diff --git a/Package.swift b/Package.swift index 7f009ac..6120db0 100644 --- a/Package.swift +++ b/Package.swift @@ -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"]), diff --git a/Sources/ElementaryFunctions/ElementaryFunctions.swift b/Sources/ElementaryFunctions/ElementaryFunctions.swift index a60a3ad..3f90f73 100644 --- a/Sources/ElementaryFunctions/ElementaryFunctions.swift +++ b/Sources/ElementaryFunctions/ElementaryFunctions.swift @@ -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`. /// @@ -174,7 +174,7 @@ public protocol ElementaryFunctions { /// /// See also: /// - - /// - `log1p()` + /// - `logp1()` /// - `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 log1p(_ x: Self) -> Self + static func logp1(_ x: Self) -> Self /// The [inverse hyperbolic cosine][wiki] of `x`. /// ``` @@ -374,7 +374,7 @@ public protocol RealFunctions: ElementaryFunctions { /// - /// - `exp2()` /// - `log()` - /// - `log1p()` + /// - `logp1()` /// - `log10()` static func log2(_ x: Self) -> Self @@ -384,7 +384,7 @@ public protocol RealFunctions: ElementaryFunctions { /// - /// - `exp10()` /// - `log()` - /// - `log1p()` + /// - `logp1()` /// - `log2()` static func log10(_ x: Self) -> Self diff --git a/Sources/ElementaryFunctions/ScalarConformances.swift b/Sources/ElementaryFunctions/ScalarConformances.swift index 4bc3938..ebc0898 100644 --- a/Sources/ElementaryFunctions/ScalarConformances.swift +++ b/Sources/ElementaryFunctions/ScalarConformances.swift @@ -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) -> 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) -> 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) -> 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 diff --git a/Sources/NumericsShims/NumericsShims.c b/Sources/NumericsShims/NumericsShims.c deleted file mode 100644 index 11583f7..0000000 --- a/Sources/NumericsShims/NumericsShims.c +++ /dev/null @@ -1,20 +0,0 @@ -//===--- NumericsShims.c --------------------------------------*- swift -*-===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2019 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -// This file exists only to trigger the NumericShims module to build; without -// it swiftpm won't build anything, and then the shims are not available for -// the modules that need them. - -// If any shims are added that are not pure header inlines, whatever runtime -// support they require can be added to this file. - -#include "NumericsShims.h" diff --git a/Sources/NumericsShims/include/NumericsShims.h b/Sources/NumericsShims/include/NumericsShims.h deleted file mode 100644 index 4e0e3ed..0000000 --- a/Sources/NumericsShims/include/NumericsShims.h +++ /dev/null @@ -1,351 +0,0 @@ -//===--- NumericsShims.h --------------------------------------*- swift -*-===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2019 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -#define HEADER_SHIM static inline __attribute__((__always_inline__)) - -// MARK: - math functions for float - -HEADER_SHIM float swift_cosf(float x) { - return __builtin_cosf(x); -} - -HEADER_SHIM float swift_sinf(float x) { - return __builtin_sinf(x); -} - -HEADER_SHIM float swift_tanf(float x) { - return __builtin_tanf(x); -} - -HEADER_SHIM float swift_acosf(float x) { - return __builtin_acosf(x); -} - -HEADER_SHIM float swift_asinf(float x) { - return __builtin_asinf(x); -} - -HEADER_SHIM float swift_atanf(float x) { - return __builtin_atanf(x); -} - -HEADER_SHIM float swift_coshf(float x) { - return __builtin_coshf(x); -} - -HEADER_SHIM float swift_sinhf(float x) { - return __builtin_sinhf(x); -} - -HEADER_SHIM float swift_tanhf(float x) { - return __builtin_tanhf(x); -} - -HEADER_SHIM float swift_acoshf(float x) { - return __builtin_acoshf(x); -} - -HEADER_SHIM float swift_asinhf(float x) { - return __builtin_asinhf(x); -} - -HEADER_SHIM float swift_atanhf(float x) { - return __builtin_atanhf(x); -} - -HEADER_SHIM float swift_expf(float x) { - return __builtin_expf(x); -} - -HEADER_SHIM float swift_expm1f(float x) { - return __builtin_expm1f(x); -} - -HEADER_SHIM float swift_logf(float x) { - return __builtin_logf(x); -} - -HEADER_SHIM float swift_log1pf(float x) { - return __builtin_log1pf(x); -} - -HEADER_SHIM float swift_powf(float x, float y) { - return __builtin_powf(x, y); -} - -HEADER_SHIM float swift_atan2f(float y, float x) { - return __builtin_atan2f(y, x); -} - -HEADER_SHIM float swift_erff(float x) { - return __builtin_erff(x); -} - -HEADER_SHIM float swift_erfcf(float x) { - return __builtin_erfcf(x); -} - -HEADER_SHIM float swift_exp2f(float x) { - return __builtin_exp2f(x); -} - -HEADER_SHIM float swift_hypotf(float x, float y) { -#if defined(_WIN32) - extern float _hypotf(float, float); - return _hypotf(x, y); -#else - return __builtin_hypotf(x, y); -#endif -} - -HEADER_SHIM float swift_gammaf(float x) { - return __builtin_tgammaf(x); -} - -HEADER_SHIM float swift_log2f(float x) { - return __builtin_log2f(x); -} - -HEADER_SHIM float swift_log10f(float x) { - return __builtin_log10f(x); -} - -#if !defined _WIN32 -HEADER_SHIM float swift_lgammaf(float x) { -#if __APPLE__ - extern float lgammaf_r(float, int *); -#endif - int _; - return lgammaf_r(x, &_); -} -#endif - -// MARK: - math functions for double - -HEADER_SHIM double swift_cos(double x) { - return __builtin_cos(x); -} - -HEADER_SHIM double swift_sin(double x) { - return __builtin_sin(x); -} - -HEADER_SHIM double swift_tan(double x) { - return __builtin_tan(x); -} - -HEADER_SHIM double swift_acos(double x) { - return __builtin_acos(x); -} - -HEADER_SHIM double swift_asin(double x) { - return __builtin_asin(x); -} - -HEADER_SHIM double swift_atan(double x) { - return __builtin_atan(x); -} - -HEADER_SHIM double swift_cosh(double x) { - return __builtin_cosh(x); -} - -HEADER_SHIM double swift_sinh(double x) { - return __builtin_sinh(x); -} - -HEADER_SHIM double swift_tanh(double x) { - return __builtin_tanh(x); -} - -HEADER_SHIM double swift_acosh(double x) { - return __builtin_acosh(x); -} - -HEADER_SHIM double swift_asinh(double x) { - return __builtin_asinh(x); -} - -HEADER_SHIM double swift_atanh(double x) { - return __builtin_atanh(x); -} - -HEADER_SHIM double swift_exp(double x) { - return __builtin_exp(x); -} - -HEADER_SHIM double swift_expm1(double x) { - return __builtin_expm1(x); -} - -HEADER_SHIM double swift_log(double x) { - return __builtin_log(x); -} - -HEADER_SHIM double swift_log1p(double x) { - return __builtin_log1p(x); -} - -HEADER_SHIM double swift_pow(double x, double y) { - return __builtin_pow(x, y); -} - -HEADER_SHIM double swift_atan2(double y, double x) { - return __builtin_atan2(y, x); -} - -HEADER_SHIM double swift_erf(double x) { - return __builtin_erf(x); -} - -HEADER_SHIM double swift_erfc(double x) { - return __builtin_erfc(x); -} - -HEADER_SHIM double swift_exp2(double x) { - return __builtin_exp2(x); -} - -HEADER_SHIM double swift_hypot(double x, double y) { - return __builtin_hypot(x, y); -} - -HEADER_SHIM double swift_gamma(double x) { - return __builtin_tgamma(x); -} - -HEADER_SHIM double swift_log2(double x) { - return __builtin_log2(x); -} - -HEADER_SHIM double swift_log10(double x) { - return __builtin_log10(x); -} - -#if !defined _WIN32 -HEADER_SHIM double swift_lgamma(double x) { -#if __APPLE__ - extern double lgamma_r(double, int *); -#endif - int _; - return lgamma_r(x, &_); -} -#endif - -// MARK: - math functions for float80 -#if !defined _WIN32 && (defined __i386__ || defined __x86_64__) -HEADER_SHIM long double swift_cosl(long double x) { - return __builtin_cosl(x); -} - -HEADER_SHIM long double swift_sinl(long double x) { - return __builtin_sinl(x); -} - -HEADER_SHIM long double swift_tanl(long double x) { - return __builtin_tanl(x); -} - -HEADER_SHIM long double swift_acosl(long double x) { - return __builtin_acosl(x); -} - -HEADER_SHIM long double swift_asinl(long double x) { - return __builtin_asinl(x); -} - -HEADER_SHIM long double swift_atanl(long double x) { - return __builtin_atanl(x); -} - -HEADER_SHIM long double swift_coshl(long double x) { - return __builtin_coshl(x); -} - -HEADER_SHIM long double swift_sinhl(long double x) { - return __builtin_sinhl(x); -} - -HEADER_SHIM long double swift_tanhl(long double x) { - return __builtin_tanhl(x); -} - -HEADER_SHIM long double swift_acoshl(long double x) { - return __builtin_acoshl(x); -} - -HEADER_SHIM long double swift_asinhl(long double x) { - return __builtin_asinhl(x); -} - -HEADER_SHIM long double swift_atanhl(long double x) { - return __builtin_atanhl(x); -} - -HEADER_SHIM long double swift_expl(long double x) { - return __builtin_expl(x); -} - -HEADER_SHIM long double swift_expm1l(long double x) { - return __builtin_expm1l(x); -} - -HEADER_SHIM long double swift_logl(long double x) { - return __builtin_logl(x); -} - -HEADER_SHIM long double swift_log1pl(long double x) { - return __builtin_log1pl(x); -} - -HEADER_SHIM long double swift_powl(long double x, long double y) { - return __builtin_powl(x, y); -} - -HEADER_SHIM long double swift_atan2l(long double y, long double x) { - return __builtin_atan2l(y, x); -} - -HEADER_SHIM long double swift_erfl(long double x) { - return __builtin_erfl(x); -} - -HEADER_SHIM long double swift_erfcl(long double x) { - return __builtin_erfcl(x); -} - -HEADER_SHIM long double swift_exp2l(long double x) { - return __builtin_exp2l(x); -} - -HEADER_SHIM long double swift_hypotl(long double x, long double y) { - return __builtin_hypotl(x, y); -} - -HEADER_SHIM long double swift_gammal(long double x) { - return __builtin_tgammal(x); -} - -HEADER_SHIM long double swift_log2l(long double x) { - return __builtin_log2l(x); -} - -HEADER_SHIM long double swift_log10l(long double x) { - return __builtin_log10l(x); -} - -HEADER_SHIM long double swift_lgammal(long double x) { - extern long double lgammal_r(long double, int *); - int _; - return lgammal_r(x, &_); -} -#endif diff --git a/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift b/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift index 6ad4e15..d3e75b7 100644 --- a/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift +++ b/Tests/ElementaryFunctionTests/ElementaryFunctionTests.swift @@ -60,7 +60,7 @@ internal extension ElementaryFunctions where Self: BinaryFloatingPoint { sanityCheck(1.4549914146182013360537936919875185083, Self.exp(0.375)) sanityCheck(0.4549914146182013360537936919875185083, Self.expm1(0.375)) sanityCheck(-0.980829253011726236856451127452003999, Self.log(0.375)) - sanityCheck(0.3184537311185346158102472135905995955, Self.log1p(0.375)) + sanityCheck(0.3184537311185346158102472135905995955, Self.logp1(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))