diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/mikeg.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/mikeg.xcuserdatad/UserInterfaceState.xcuserstate index 0a7619c..e95ec20 100644 Binary files a/.swiftpm/xcode/package.xcworkspace/xcuserdata/mikeg.xcuserdatad/UserInterfaceState.xcuserstate and b/.swiftpm/xcode/package.xcworkspace/xcuserdata/mikeg.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Package.swift b/Package.swift index 6169916..832e762 100644 --- a/Package.swift +++ b/Package.swift @@ -5,10 +5,10 @@ import PackageDescription let package = Package( name: "BigDecimal", -// platforms: [ -// .macOS("13.3"), .iOS("16.4"), .macCatalyst("13.3"), .tvOS("16.4"), -// .watchOS("9.4") -// ], + platforms: [ + .macOS("13.3"), .iOS("16.4"), .macCatalyst("13.3"), .tvOS("16.4"), + .watchOS("9.4") + ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( diff --git a/README.md b/README.md index f923db0..1194ce3 100755 --- a/README.md +++ b/README.md @@ -35,17 +35,17 @@ Its functionality falls in the following categories: latter having a `signaling` option. ## Dependencies -BigDecimal requires Swift from macOS 15.0+, iOS 18.0+, macCatalyst 15.0+, -tvOS 18.0+, or watchOS 11.0+. It also requires that the `Int` type be a 64-bit +BigDecimal requires Swift from macOS 15.0+, iOS 13.3+, macCatalyst 13.3+, +tvOS 16.4+, or watchOS 9.4+. It also requires that the `Int` type be a 64-bit type. -The BigDecimal package depends on the BigInt and swift-numerics packages. -It also uses the built-in UInt128 which is part of the new OS releases. +The BigDecimal package depends on the BigInt, UInt128, and swift-numerics packages. ``` dependencies: [ .package(url: "https://github.com/mgriebling/BigInt.git", from: "2.2.0") - .package(url: "https://github.com/apple/swift-numerics", from: "1.0.0") + .package(url: "https://github.com/apple/swift-numerics", from: "1.0.0"), + .package(url: "https://github.com/mgriebling/UInt128.git", from: "3.1.5") ] ``` @@ -54,7 +54,7 @@ In your project's Package.swift file add a dependency like ``` dependencies: [ - .package(url: "https://github.com/mgriebling/BigDecimal.git", from: "2.2.0"), + .package(url: "https://github.com/mgriebling/BigDecimal.git", from: "3.0.2"), ] ``` diff --git a/Sources/BigDecimal/DecimalMath/DecimalMath-Simple.swift b/Sources/BigDecimal/DecimalMath/DecimalMath-Simple.swift index bccc3da..290a6b6 100644 --- a/Sources/BigDecimal/DecimalMath/DecimalMath-Simple.swift +++ b/Sources/BigDecimal/DecimalMath/DecimalMath-Simple.swift @@ -5,11 +5,9 @@ // Created by Mike Griebling on 10.07.2023. // -// import RealModule - temporarily removed due to playground incompatibility - /// `Real` number protocol compliance using a simplified interface with /// a fixed precision given by a global rounding context: `BigDecimal.mc`. -extension BigDecimal { // : Real { +extension BigDecimal { @inlinable public static func atan2(y: BigDecimal, x: BigDecimal) -> BigDecimal { diff --git a/Tests/BigDecimalTests/TestCompare.swift b/Tests/BigDecimalTests/TestCompare.swift index a4482f8..02d705e 100644 --- a/Tests/BigDecimalTests/TestCompare.swift +++ b/Tests/BigDecimalTests/TestCompare.swift @@ -266,4 +266,31 @@ class TestCompare: XCTestCase { XCTAssertTrue(-x > -y) XCTAssertTrue(-x >= -y) } + + func test8() throws { + let x = BigDecimal("1") + let y = BigDecimal("2") + XCTAssertFalse(x.isEqual(to: y)) + XCTAssertTrue(x.isLess(than: y)) + XCTAssertTrue(x.isLessThanOrEqualTo(y)) + + XCTAssertFalse((-x).isEqual(to: y)) + XCTAssertTrue((-x).isLess(than: y)) + XCTAssertTrue((-x).isLessThanOrEqualTo(y)) + + XCTAssertFalse(x.isEqual(to: -y)) + XCTAssertFalse(x.isLess(than: -y)) + XCTAssertFalse(x.isLessThanOrEqualTo(-y)) + + XCTAssertFalse((-x).isEqual(to: -y)) + XCTAssertFalse((-x).isLess(than: -y)) + XCTAssertFalse((-x).isLessThanOrEqualTo(-y)) + + XCTAssertFalse(x.isNaN) + XCTAssertFalse(x.isZero) + XCTAssertTrue(x.isPositive) + XCTAssertTrue(x.isFinite) + XCTAssertTrue(x.isNormal) + XCTAssertTrue(x.isCanonical) + } } diff --git a/Tests/BigDecimalTests/TestHyperbolic.swift b/Tests/BigDecimalTests/TestHyperbolic.swift new file mode 100644 index 0000000..95623e8 --- /dev/null +++ b/Tests/BigDecimalTests/TestHyperbolic.swift @@ -0,0 +1,37 @@ +// +// TestHyperbolic.swift +// BigDecimal +// +// Created by Mike Griebling on 11.10.2024. +// + +import XCTest +@testable import BigDecimal + +final class TestHyperbolic: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + XCTAssertEqual(BigDecimal.sinh(.one).asString(), "1.175201193643801456882381850595601") + XCTAssertEqual(BigDecimal.cosh(.one).asString(), "1.543080634815243778477905620757062") + XCTAssertEqual(BigDecimal.tanh(.one).asString(), "0.7615941559557648881194582826047937") + XCTAssertEqual(BigDecimal.asinh(BigDecimal.sinh(.one)).asString(), "1.000000000000000000000000000000000") + XCTAssertEqual(BigDecimal.acosh(BigDecimal.cosh(.one)).asString(), "1.000000000000000000000000000000000") + XCTAssertEqual(BigDecimal.atanh(BigDecimal.tanh(.one)).asString(), "1.000000000000000000000000000000000") + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/Tests/BigDecimalTests/TestLogarit.swift b/Tests/BigDecimalTests/TestLogarithm.swift similarity index 73% rename from Tests/BigDecimalTests/TestLogarit.swift rename to Tests/BigDecimalTests/TestLogarithm.swift index 4bd2b49..8fb5258 100644 --- a/Tests/BigDecimalTests/TestLogarit.swift +++ b/Tests/BigDecimalTests/TestLogarithm.swift @@ -8,7 +8,7 @@ import XCTest import BigDecimal -final class TestLogarit: XCTestCase { +final class TestLogarithm: XCTestCase { override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. @@ -23,6 +23,11 @@ final class TestLogarit: XCTestCase { XCTAssertEqual(result1.round(.decimal32).asString(), "1.000434") let result2 = BigDecimal.log(BigDecimal(10.01)) XCTAssertEqual(result2.round(.decimal32).asString(), "2.303585") + + let result3 = BigDecimal.log(onePlus: BigDecimal(10.01)) + XCTAssertEqual(result3.round(.decimal64).asString(), "2.398803950734589") + let result4 = BigDecimal.log2(BigDecimal(10.01)) + XCTAssertEqual(result4.round(.decimal64).asString(), "3.323370069061269") } func testPerformanceExample() throws { diff --git a/Tests/BigDecimalTests/TestOperations.swift b/Tests/BigDecimalTests/TestOperations.swift index 725c89e..26b4048 100644 --- a/Tests/BigDecimalTests/TestOperations.swift +++ b/Tests/BigDecimalTests/TestOperations.swift @@ -70,12 +70,15 @@ class TestOperations: XCTestCase { let sqrt10000 = BigDecimal.sqrt(10000, decimal128) XCTAssertEqual(sqrt10000, BigDecimal(100)) - let cbrt = BigDecimal.root(2, 3, decimal138) + let cbrt = BigDecimal.root(2, 3, decimal128) XCTAssertEqual(cbrt.round(decimal128).description, "1.259921049894873164767210607278228") let cubed = BigDecimal.pow(cbrt, 3, decimal128) - XCTAssertEqual(cubed.description, "2.000000000000000000000000000000000") + XCTAssertEqual(cubed.description, "1.999999999999999999999999999999998") + + let bernie = BigDecimal.bernoulli(20, decimal128) + XCTAssertEqual(bernie.asString(), "-529.1242424242424242424242424242424") let power = BigDecimal.pow(BigDecimal("1.2"), BigDecimal("1000.5"), decimal128) XCTAssertEqual(power.description, @@ -90,6 +93,9 @@ class TestOperations: XCTestCase { let fact1000limited = BigDecimal.factorial(1000, decimal128) XCTAssertEqual(fact1000limited.description, "4.023872600770937735437024339230040E+2567") + + let fact = BigDecimal.factorial(BigDecimal(1000), decimal128) + XCTAssertEqual(fact.description, "4.023872600770937735437024339230040E+2567") let gammaHalf = BigDecimal.gamma(BigDecimal("0.5"), decimal128) XCTAssertEqual(gammaHalf.description, diff --git a/Tests/BigDecimalTests/TestPow.swift b/Tests/BigDecimalTests/TestPow.swift index 58d0893..ecb24fc 100644 --- a/Tests/BigDecimalTests/TestPow.swift +++ b/Tests/BigDecimalTests/TestPow.swift @@ -10,12 +10,20 @@ import XCTest @testable import BigDecimal class TestPow: XCTestCase { - func testPow() throws { - XCTAssertEqual(BigDecimal("5.5").pow(-3, .decimal128).asString(), "0.006010518407212622088655146506386176") - XCTAssertEqual(BigDecimal(5.5).pow(-3, .decimal128).round(.decimal32).asString(), "0.006010518") - XCTAssertEqual(BigDecimal.pow(BigDecimal("5.5"), BigDecimal("-3")).asString(), "0.006010518407212622088655146506386176") - XCTAssertEqual(BigDecimal("5.5").pow(3).asString(), "166.375") - XCTAssertEqual(BigDecimal.pow(BigDecimal("5.5"), BigDecimal("3.2")).asString(), "233.9702323679928009901371156854989") - XCTAssertEqual(BigDecimal.pow(BigDecimal("2"), BigDecimal("-4")).asString(), "0.0625") - } + let a55 = BigDecimal("5.5") + + func testPow() throws { + XCTAssertEqual(a55.pow(-3, .decimal128).asString(), "0.006010518407212622088655146506386176") + XCTAssertEqual(BigDecimal(5.5).pow(-3, .decimal128).round(.decimal32).asString(), "0.006010518") + XCTAssertEqual(BigDecimal.pow(a55, BigDecimal("-3")).asString(), "0.006010518407212622088655146506386176") + XCTAssertEqual(a55.pow(3).asString(), "166.375") + XCTAssertEqual(BigDecimal.pow(a55, BigDecimal("3.2")).asString(), "233.9702323679928009901371156854989") + XCTAssertEqual(BigDecimal.pow(BigDecimal("2"), BigDecimal("-4")).asString(), "0.0625") + } + + func testExp() throws { + XCTAssertEqual(BigDecimal.exp(a55).asString(), "244.6919322642203879151889495118394") + XCTAssertEqual(BigDecimal.expMinusOne(a55).asString(), "243.6919322642203879151889495118394") + XCTAssertEqual(BigDecimal.exp2(a55).asString(), "45.25483399593904156165403917471034") + } } diff --git a/Tests/BigDecimalTests/TestTrig.swift b/Tests/BigDecimalTests/TestTrig.swift new file mode 100644 index 0000000..f300a8e --- /dev/null +++ b/Tests/BigDecimalTests/TestTrig.swift @@ -0,0 +1,39 @@ +// +// TestTrig.swift +// BigDecimal +// +// Created by Mike Griebling on 11.10.2024. +// + +import XCTest +@testable import BigDecimal + +final class TestTrig: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testTrig() throws { + let pi2 = BigDecimal.pi / 2 + XCTAssertEqual(BigDecimal.sin(pi2).asString(), "0.8414709848078965066525023216302990") + XCTAssertEqual(BigDecimal.cos(pi2).asString(), "0.5403023058681397174009366074429766") + XCTAssertEqual(BigDecimal.tan(pi2).asString(), "1.557407724654902230506974807458360") + XCTAssertEqual(BigDecimal.asin(BigDecimal.sin(pi2)).asString(), "1.000000000000000000000000000000000") + XCTAssertEqual(BigDecimal.acos(BigDecimal.cos(pi2)).asString(), "1.000000000000000000000000000000000") + XCTAssertEqual(BigDecimal.atan(BigDecimal.tan(pi2)).asString(), "0.9999999999999999999999999999999999") + XCTAssertEqual(BigDecimal.atan2(y: .one, x: .ten).asString(), "0.09966865249116202737844611987802059") + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +}