diff --git a/Sources/ComplexModule/ElementaryFunctions.swift b/Sources/ComplexModule/ElementaryFunctions.swift index 94a3f4c..921f928 100644 --- a/Sources/ComplexModule/ElementaryFunctions.swift +++ b/Sources/ComplexModule/ElementaryFunctions.swift @@ -28,11 +28,15 @@ // project. // 6. Give the best performance we can. We should care about performance, // but with lower precedence than the other considerations. +// +// Except where derivations are given, the expressions used here are all +// adapted from Kahan's 1986 paper "Branch Cuts for Complex Elementary +// Functions; or: Much Ado About Nothing's Sign Bit". import RealModule // TODO: uncomment conformance once all implementations are provided. -extension Complex /*: ElementaryFunctions */ { +extension Complex: ElementaryFunctions { // MARK: - exp-like functions @@ -47,7 +51,6 @@ extension Complex /*: ElementaryFunctions */ { /// Note that naive evaluation of this expression in floating-point would be prone to premature /// overflow, since `cos` and `sin` both have magnitude less than 1 for most inputs (i.e. /// `exp(x)` may be infinity when `exp(x) cos(y)` would not be. - @inlinable public static func exp(_ z: Complex) -> Complex { guard z.isFinite else { return z } // If x < log(greatestFiniteMagnitude), then exp(x) does not overflow. @@ -62,7 +65,6 @@ extension Complex /*: ElementaryFunctions */ { return Complex(.cos(z.y), .sin(z.y)).multiplied(by: .exp(z.x)) } - @inlinable public static func expMinusOne(_ z: Complex) -> Complex { // exp(x + iy) - 1 = (exp(x) cos(y) - 1) + i exp(x) sin(y) // -------- u -------- @@ -132,7 +134,6 @@ extension Complex /*: ElementaryFunctions */ { // This function and sinh should stay in sync; if you make a // modification here, you should almost surely make a parallel // modification to sinh below. - @inlinable @inline(__always) public static func cosh(_ z: Complex) -> Complex { guard z.isFinite else { return z } guard z.x.magnitude < -RealType.log(.ulpOfOne) else { @@ -162,7 +163,6 @@ extension Complex /*: ElementaryFunctions */ { // sinh(x + iy) = sinh(x) cos(y) + i cosh(x) sinh(y) // // See cosh above for algorithm details. - @inlinable @inline(__always) public static func sinh(_ z: Complex) -> Complex { guard z.isFinite else { return z } guard z.x.magnitude < -RealType.log(.ulpOfOne) else { @@ -178,7 +178,6 @@ extension Complex /*: ElementaryFunctions */ { } // tanh(z) = sinh(z) / cosh(z) - @inlinable public static func tanh(_ z: Complex) -> Complex { guard z.isFinite else { return z } // Note that when |x| is larger than -log(.ulpOfOne), @@ -219,7 +218,6 @@ extension Complex /*: ElementaryFunctions */ { } // MARK: - log-like functions - @inlinable public static func log(_ z: Complex) -> Complex { // If z is zero or infinite, the phase is undefined, so the result is // the single exceptional value. @@ -319,7 +317,6 @@ extension Complex /*: ElementaryFunctions */ { return Complex(.log(onePlus: s)/2, θ) } - @inlinable public static func log(onePlus z: Complex) -> Complex { // If either |x| or |y| is bounded away from the origin, we don't need // any extra precision, and can just literally compute log(1+z). Note @@ -330,7 +327,7 @@ extension Complex /*: ElementaryFunctions */ { guard 2*z.x.magnitude < 1 && z.y.magnitude < 1 else { return log(1+z) } // z is in (±0.5, ±1), so we need to evaluate more carefully. // The imaginary part is straightforward: - let θ = z.phase + let θ = (1+z).phase // For the real part, we _could_ use the same approach that we do for // log( ), but we'd need an extra-precise (1+x)², which can potentially // be quite painful to calculate. Instead, we can use an approach that @@ -352,13 +349,17 @@ extension Complex /*: ElementaryFunctions */ { } public static func acos(_ z: Complex) -> Complex { - fatalError() + Complex( + 2*RealType.atan2(y: sqrt(1-z).real, x: sqrt(1+z).real), + RealType.asinh((sqrt(1+z).conjugate * sqrt(1-z)).imaginary) + ) } - // asin(z) = -i*asinh(iz) public static func asin(_ z: Complex) -> Complex { - let w = asinh(Complex(-z.y, z.x)) - return Complex(w.y, -w.x) + Complex( + RealType.atan2(y: z.x, x: (sqrt(1-z) * sqrt(1+z)).real), + RealType.asinh((sqrt(1-z).conjugate * sqrt(1+z)).imaginary) + ) } // atan(z) = -i*atanh(iz) @@ -368,15 +369,29 @@ extension Complex /*: ElementaryFunctions */ { } public static func acosh(_ z: Complex) -> Complex { - fatalError() + Complex( + RealType.asinh((sqrt(z-1).conjugate * sqrt(z+1)).real), + 2*RealType.atan2(y: sqrt(z-1).imaginary, x: sqrt(z+1).real) + ) } + // asinh(z) = -i*asin(iz) public static func asinh(_ z: Complex) -> Complex { - fatalError() + let w = asin(Complex(-z.y, z.x)) + return Complex(w.y, -w.x) } public static func atanh(_ z: Complex) -> Complex { - fatalError() + // TODO: Kahan uses a much more complicated expression here; possibly + // simply because he didn't have a complex log(1+z) with good + // characteristics. Investigate tradeoffs further. + // + // Further TODO: decide policy for point at infinity / NaN. Unlike most + // of these functions, atanh doesn't have a pole at infinity; convention + // in C-family languages is use one value in the upper half plane, and + // another in the lower. Requires some thought about the most appropriate + // way to handle this case in Swift. + (log(onePlus: z) - log(onePlus:-z))/2 } // MARK: - pow-like functions diff --git a/Sources/_NumericsShims/include/_NumericsShims.h b/Sources/_NumericsShims/include/_NumericsShims.h index 91b2358..58b1279 100644 --- a/Sources/_NumericsShims/include/_NumericsShims.h +++ b/Sources/_NumericsShims/include/_NumericsShims.h @@ -417,4 +417,10 @@ HEADER_SHIM CComplex libm_cmul(CComplex z, CComplex w) { double _Complex c = a*b; return (CComplex){ __real__ c, __imag__ c }; } + +HEADER_SHIM CComplex libm_catanh(CComplex z) { + double _Complex a = { z.real, z.imag }; + double _Complex w = __builtin_catanh(a); + return (CComplex){ __real__ w, __imag__ w }; +} #endif // !defined _WIN32 diff --git a/Tests/ComplexTests/ElementaryFunctionTests.swift b/Tests/ComplexTests/ElementaryFunctionTests.swift index 7d5c9fd..bf3f15b 100644 --- a/Tests/ComplexTests/ElementaryFunctionTests.swift +++ b/Tests/ComplexTests/ElementaryFunctionTests.swift @@ -112,6 +112,45 @@ final class ElementaryFunctionTests: XCTestCase { } } + func testLogOnePlus(_ type: T.Type) { + // log(onePlus: 0) = 0 + XCTAssertEqual(0, Complex.log(onePlus: Complex( 0, 0))) + XCTAssertEqual(0, Complex.log(onePlus: Complex(-0, 0))) + XCTAssertEqual(0, Complex.log(onePlus: Complex(-0,-0))) + XCTAssertEqual(0, Complex.log(onePlus: Complex( 0,-0))) + // log(onePlus:) is the identity at infinity. + XCTAssertFalse(Complex.log(onePlus: Complex( .infinity, 0)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( .infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( 0, .infinity)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex(-.infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex(-.infinity, 0)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex(-.infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( 0,-.infinity)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( .infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( .nan, .nan)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( .infinity, .nan)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( .nan, .infinity)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex(-.infinity, .nan)).isFinite) + XCTAssertFalse(Complex.log(onePlus: Complex( .nan,-.infinity)).isFinite) + // For randomly-chosen well-scaled finite values, we expect to have + // log(onePlus: expMinusOne(z)) ≈ z + var g = SystemRandomNumberGenerator() + let values: [Complex] = (0..<1000).map { _ in + Complex(T.random(in: -2 ... 2, using: &g), + T.random(in: -2 ... 2, using: &g)) + } + for z in values { + let w = Complex.expMinusOne(z) + let u = Complex.log(onePlus: w) + if !u.isApproximatelyEqual(to: z) { + print("log(onePlus: expMinusOne()) was not close to identity at z = \(z).") + print("expMinusOne(\(z)) = \(w).") + print("long(onePlus: \(w)) = \(u).") + XCTFail() + } + } + } + func testCosh(_ type: T.Type) { // cosh(0) = 1 XCTAssertEqual(1, Complex.cosh(Complex( 0, 0))) @@ -144,23 +183,261 @@ final class ElementaryFunctionTests: XCTestCase { XCTAssert(huge.imaginary.isApproximatelyEqual(to: mag)) } + func testSinh(_ type: T.Type) { + // sinh(0) = 0 + XCTAssertEqual(0, Complex.sinh(Complex( 0, 0))) + XCTAssertEqual(0, Complex.sinh(Complex(-0, 0))) + XCTAssertEqual(0, Complex.sinh(Complex(-0,-0))) + XCTAssertEqual(0, Complex.sinh(Complex( 0,-0))) + // sinh is the identity at infinity. + XCTAssertFalse(Complex.sinh(Complex( .infinity, 0)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( .infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( 0, .infinity)).isFinite) + XCTAssertFalse(Complex.sinh(Complex(-.infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.sinh(Complex(-.infinity, 0)).isFinite) + XCTAssertFalse(Complex.sinh(Complex(-.infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( 0,-.infinity)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( .infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( .nan, .nan)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( .infinity, .nan)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( .nan, .infinity)).isFinite) + XCTAssertFalse(Complex.sinh(Complex(-.infinity, .nan)).isFinite) + XCTAssertFalse(Complex.sinh(Complex( .nan,-.infinity)).isFinite) + // Near-overflow test, same as exp() above, but it happens later, because + // for large x, sinh(x + iy) ~ ±exp(x + iy)/2. + let x = T.log(.greatestFiniteMagnitude) + T.log(18/8) + let mag = T.greatestFiniteMagnitude/T.sqrt(2) * (9/8) + var huge = Complex.sinh(Complex(x, .pi/4)) + XCTAssert(huge.real.isApproximatelyEqual(to: mag)) + XCTAssert(huge.imaginary.isApproximatelyEqual(to: mag)) + huge = Complex.sinh(Complex(-x, .pi/4)) + XCTAssert(huge.real.isApproximatelyEqual(to: -mag)) + XCTAssert(huge.imaginary.isApproximatelyEqual(to: -mag)) + // For randomly-chosen well-scaled finite values, we expect to have + // cosh² - sinh² ≈ 1. Note that this test would break down due to + // catastrophic cancellation as we get further away from the origin. + var g = SystemRandomNumberGenerator() + let values: [Complex] = (0..<1000).map { _ in + Complex(T.random(in: -2 ... 2, using: &g), + T.random(in: -2 ... 2, using: &g)) + } + for z in values { + let c = Complex.cosh(z) + let s = Complex.sinh(z) + XCTAssert((c*c - s*s).isApproximatelyEqual(to: 1)) + } + } + + func testAcos(_ type: T.Type) { + // acos(1) = 0 + XCTAssertEqual(0, Complex.acos(1)) + // acos(0) = π/2 + XCTAssert(Complex.acos(0).real.isApproximatelyEqual(to: .pi/2)) + XCTAssertEqual(Complex.acos(0).imaginary, 0) + // acos(-1) = π + XCTAssert(Complex.acos(-1).real.isApproximatelyEqual(to: .pi)) + XCTAssertEqual(Complex.acos(-1).imaginary, 0) + // acos is the identity at infinity. + XCTAssertFalse(Complex.acos(Complex( .infinity, 0)).isFinite) + XCTAssertFalse(Complex.acos(Complex( .infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.acos(Complex( 0, .infinity)).isFinite) + XCTAssertFalse(Complex.acos(Complex(-.infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.acos(Complex(-.infinity, 0)).isFinite) + XCTAssertFalse(Complex.acos(Complex(-.infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.acos(Complex( 0,-.infinity)).isFinite) + XCTAssertFalse(Complex.acos(Complex( .infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.acos(Complex( .nan, .nan)).isFinite) + XCTAssertFalse(Complex.acos(Complex( .infinity, .nan)).isFinite) + XCTAssertFalse(Complex.acos(Complex( .nan, .infinity)).isFinite) + XCTAssertFalse(Complex.acos(Complex(-.infinity, .nan)).isFinite) + XCTAssertFalse(Complex.acos(Complex( .nan,-.infinity)).isFinite) + // For randomly-chosen well-scaled finite values, we expect to have + // cos(acos(z)) ≈ z and acos(z) ≈ π - acos(-z) + var g = SystemRandomNumberGenerator() + let values: [Complex] = (0..<1000).map { _ in + Complex(T.random(in: -2 ... 2, using: &g), + T.random(in: -2 ... 2, using: &g)) + } + for z in values { + let w = Complex.acos(z) + XCTAssert(Complex.cos(w).isApproximatelyEqual(to: z)) + XCTAssert(w.isApproximatelyEqual(to: Complex(.pi) - .acos(-z))) + } + } + + func testAsin(_ type: T.Type) { + // asin(1) = π/2 + XCTAssert(Complex.asin(1).real.isApproximatelyEqual(to: .pi/2)) + XCTAssertEqual(Complex.asin(1).imaginary, 0) + // asin(0) = 0 + XCTAssertEqual(0, Complex.asin(0)) + // asin(-1) = -π/2 + XCTAssert(Complex.asin(-1).real.isApproximatelyEqual(to: -.pi/2)) + XCTAssertEqual(Complex.asin(-1).imaginary, 0) + // asin is the identity at infinity. + XCTAssertFalse(Complex.asin(Complex( .infinity, 0)).isFinite) + XCTAssertFalse(Complex.asin(Complex( .infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.asin(Complex( 0, .infinity)).isFinite) + XCTAssertFalse(Complex.asin(Complex(-.infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.asin(Complex(-.infinity, 0)).isFinite) + XCTAssertFalse(Complex.asin(Complex(-.infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.asin(Complex( 0,-.infinity)).isFinite) + XCTAssertFalse(Complex.asin(Complex( .infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.asin(Complex( .nan, .nan)).isFinite) + XCTAssertFalse(Complex.asin(Complex( .infinity, .nan)).isFinite) + XCTAssertFalse(Complex.asin(Complex( .nan, .infinity)).isFinite) + XCTAssertFalse(Complex.asin(Complex(-.infinity, .nan)).isFinite) + XCTAssertFalse(Complex.asin(Complex( .nan,-.infinity)).isFinite) + // For randomly-chosen well-scaled finite values, we expect to have + // sin(asin(z)) ≈ z and asin(z) ≈ -asin(-z) + var g = SystemRandomNumberGenerator() + let values: [Complex] = (0..<1000).map { _ in + Complex(T.random(in: -2 ... 2, using: &g), + T.random(in: -2 ... 2, using: &g)) + } + for z in values { + let w = Complex.asin(z) + XCTAssert(Complex.sin(w).isApproximatelyEqual(to: z)) + XCTAssert(w.isApproximatelyEqual(to: -.asin(-z))) + } + } + + func testAcosh(_ type: T.Type) { + // acosh(1) = 0 + XCTAssertEqual(0, Complex.acosh(1)) + // acosh(0) = iπ/2 + XCTAssert(Complex.acosh(0).imaginary.isApproximatelyEqual(to: .pi/2)) + XCTAssertEqual(Complex.acosh(0).real, 0) + // acosh(-1) = iπ + XCTAssert(Complex.acosh(-1).imaginary.isApproximatelyEqual(to: .pi)) + XCTAssertEqual(Complex.acosh(-1).real, 0) + // acosh is the identity at infinity. + XCTAssertFalse(Complex.acosh(Complex( .infinity, 0)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( .infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( 0, .infinity)).isFinite) + XCTAssertFalse(Complex.acosh(Complex(-.infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.acosh(Complex(-.infinity, 0)).isFinite) + XCTAssertFalse(Complex.acosh(Complex(-.infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( 0,-.infinity)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( .infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( .nan, .nan)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( .infinity, .nan)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( .nan, .infinity)).isFinite) + XCTAssertFalse(Complex.acosh(Complex(-.infinity, .nan)).isFinite) + XCTAssertFalse(Complex.acosh(Complex( .nan,-.infinity)).isFinite) + // For randomly-chosen well-scaled finite values, we expect to have + // cosh(acosh(z)) ≈ z + var g = SystemRandomNumberGenerator() + let values: [Complex] = (0..<1000).map { _ in + Complex(T.random(in: -2 ... 2, using: &g), + T.random(in: -2 ... 2, using: &g)) + } + for z in values { + let w = Complex.acosh(z) + XCTAssert(Complex.cosh(w).isApproximatelyEqual(to: z)) + } + } + + func testAsinh(_ type: T.Type) { + // asinh(1) = π/2 + XCTAssert(Complex.asin(1).real.isApproximatelyEqual(to: .pi/2)) + XCTAssertEqual(Complex.asin(1).imaginary, 0) + // asinh(0) = 0 + XCTAssertEqual(0, Complex.asin(0)) + // asinh(-1) = -π/2 + XCTAssert(Complex.asin(-1).real.isApproximatelyEqual(to: -.pi/2)) + XCTAssertEqual(Complex.asin(-1).imaginary, 0) + // asinh is the identity at infinity. + XCTAssertFalse(Complex.asinh(Complex( .infinity, 0)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( .infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( 0, .infinity)).isFinite) + XCTAssertFalse(Complex.asinh(Complex(-.infinity, .infinity)).isFinite) + XCTAssertFalse(Complex.asinh(Complex(-.infinity, 0)).isFinite) + XCTAssertFalse(Complex.asinh(Complex(-.infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( 0,-.infinity)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( .infinity,-.infinity)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( .nan, .nan)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( .infinity, .nan)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( .nan, .infinity)).isFinite) + XCTAssertFalse(Complex.asinh(Complex(-.infinity, .nan)).isFinite) + XCTAssertFalse(Complex.asinh(Complex( .nan,-.infinity)).isFinite) + // For randomly-chosen well-scaled finite values, we expect to have + // sinh(asinh(z)) ≈ z + var g = SystemRandomNumberGenerator() + let values: [Complex] = (0..<1000).map { _ in + Complex(T.random(in: -2 ... 2, using: &g), + T.random(in: -2 ... 2, using: &g)) + } + for z in values { + let w = Complex.asinh(z) + let u = Complex.sinh(w) + if !u.isApproximatelyEqual(to: z) { + print("sinh(asinh()) was not close to identity at z = \(z).") + print("asinh(\(z)) = \(w).") + print("sinh(\(w)) = \(u).") + XCTFail() + } + } + } + + func testAtanh(_ type: T.Type) { + // For randomly-chosen well-scaled finite values, we expect to have + // atanh(tanh(z)) ≈ z + var g = SystemRandomNumberGenerator() + let values: [Complex] = (0..<1000).map { _ in + Complex(T.random(in: -2 ... 2, using: &g), + T.random(in: -2 ... 2, using: &g)) + } + for z in values { + let w = Complex.atanh(z) + let u = Complex.tanh(w) + if !u.isApproximatelyEqual(to: z) { + print("tanh(atanh()) was not close to identity at z = \(z).") + print("atanh(\(z)) = \(w).") + print("tanh(\(w)) = \(u).") + XCTFail() + } + } + } + func testFloat() { testExp(Float.self) testExpMinusOne(Float.self) + testLogOnePlus(Float.self) testCosh(Float.self) + testSinh(Float.self) + testAcos(Float.self) + testAsin(Float.self) + testAcosh(Float.self) + testAsinh(Float.self) + testAtanh(Float.self) } func testDouble() { testExp(Double.self) testExpMinusOne(Double.self) + testLogOnePlus(Float.self) testCosh(Double.self) + testSinh(Double.self) + testAcos(Double.self) + testAsin(Double.self) + testAcosh(Double.self) + testAsinh(Double.self) + testAtanh(Double.self) } #if (arch(i386) || arch(x86_64)) && !os(Windows) && !os(Android) func testFloat80() { testExp(Float80.self) testExpMinusOne(Float80.self) + testLogOnePlus(Float.self) testCosh(Float80.self) + testSinh(Float80.self) + testAcos(Float80.self) + testAsin(Float80.self) + testAcosh(Float80.self) + testAsinh(Float80.self) + testAtanh(Float80.self) } #endif } diff --git a/Tests/Executable/ComplexLog/main.swift b/Tests/Executable/ComplexLog/main.swift index c188033..d70a5c3 100644 --- a/Tests/Executable/ComplexLog/main.swift +++ b/Tests/Executable/ComplexLog/main.swift @@ -15,7 +15,7 @@ import _TestSupport #if DEBUG fatalError("Run this test in Release configuration") -#endif +#else var componentError = Double(Float.ulpOfOne/2) var complexError = Double(Float.ulpOfOne/2) @@ -105,3 +105,4 @@ print("For input \(componentMaxInput).") print("Reference result: \(Complex.log(Complex(componentMaxInput)))") print(" Observed result: \(Complex.log(componentMaxInput))") +#endif diff --git a/Tests/Executable/ComplexLog1p/main.swift b/Tests/Executable/ComplexLog1p/main.swift index b59981c..a06e14e 100644 --- a/Tests/Executable/ComplexLog1p/main.swift +++ b/Tests/Executable/ComplexLog1p/main.swift @@ -15,7 +15,7 @@ import _TestSupport #if DEBUG fatalError("Run this test in Release configuration") -#endif +#else var componentError = Double(Float.ulpOfOne/2) var complexError = Double(Float.ulpOfOne/2) @@ -105,3 +105,4 @@ print("For input \(componentMaxInput).") print("Reference result: \(Complex.log(onePlus: Complex(componentMaxInput)))") print(" Observed result: \(Complex.log(onePlus: componentMaxInput))") +#endif