diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..5186d07 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +4.0 diff --git a/BigNumber.podspec b/BigNumber.podspec new file mode 100644 index 0000000..c77c850 --- /dev/null +++ b/BigNumber.podspec @@ -0,0 +1,139 @@ +# +# Be sure to run `pod spec lint BigNumber.podspec' to ensure this is a +# valid spec and to remove all comments including this before submitting the spec. +# +# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html +# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ +# + +Pod::Spec.new do |s| + + # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # These will help people to find your library, and whilst it + # can feel like a chore to fill in it's definitely to your advantage. The + # summary should be tweet-length, and the description more in depth. + # + + s.name = "BigNumber" + s.version = "2.0" + s.summary = "A lightweight, high performance bignum library for Swift!" + + # This description is used to generate tags and improve search results. + # * Think: What does it do? Why did you write it? What is the focus? + # * Try to keep it short, snappy and to the point. + # * Write the description between the DESC delimiters below. + # * Finally, don't worry about the indent, CocoaPods strips it! + s.description = <<-DESC +A lightweight, high performance bignum library for Swift for both intergers and doubles! + DESC + + s.homepage = "https://github.com/mkrd/Swift-Big-Integer" + # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" + + + # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Licensing your code is important. See http://choosealicense.com for more info. + # CocoaPods will detect a license file if there is a named LICENSE* + # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. + # + + #s.license = "MIT (example)" + s.license = { :type => "MIT", :file => "LICENSE" } + + + # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Specify the authors of the library, with email addresses. Email addresses + # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also + # accepts just a name if you'd rather not provide an email address. + # + # Specify a social_media_url where others can refer to, for example a twitter + # profile URL. + # + + s.author = "mkrd" + # Or just: s.author = "twodayslate" + # s.authors = { "twodayslate" => "zac@gorak.us" } + # s.social_media_url = "http://twitter.com/twodayslate" + + # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If this Pod runs only on iOS or OS X, then specify the platform and + # the deployment target. You can optionally include the target after the platform. + # + + # s.platform = :ios + # s.platform = :ios, "5.0" + + # When using multiple platforms + s.ios.deployment_target = "8.0" + s.osx.deployment_target = "10.9" + s.watchos.deployment_target = "2.0" + s.tvos.deployment_target = "9.0" + + + # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Specify the location from where the source should be retrieved. + # Supports git, hg, bzr, svn and HTTP. + # + + s.source = { :git => "https://github.com/mkrd/Swift-Big-Integer.git", :tag => "v#{s.version}" } + + + # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # CocoaPods is smart about how it includes source code. For source files + # giving a folder will include any swift, h, m, mm, c & cpp files. + # For header files it will include any header in the folder. + # Not including the public_header_files will make all headers public. + # + s.source_files = "Sources/*.swift" + + #s.source_files = "Classes", "Classes/**/*.{h,m}" + #s.exclude_files = "Classes/Exclude" + + # s.public_header_files = "Classes/**/*.h" + + + # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # A list of resources included with the Pod. These are copied into the + # target bundle with a build phase script. Anything else will be cleaned. + # You can preserve files from being cleaned, please don't preserve + # non-essential files like tests, examples and documentation. + # + + # s.resource = "icon.png" + # s.resources = "Resources/*.png" + + # s.preserve_paths = "FilesToSave", "MoreFilesToSave" + + + # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # Link your library with frameworks, or libraries. Libraries do not include + # the lib prefix of their name. + # + + # s.framework = "SomeFramework" + # s.frameworks = "SomeFramework", "AnotherFramework" + + # s.library = "iconv" + # s.libraries = "iconv", "xml2" + + + # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + # + # If your library depends on compiler flags you can set them in the xcconfig hash + # where they will only apply to your library. If you depend on other Podspecs + # you can include multiple dependencies to ensure it works. + + # s.requires_arc = true + + # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } + # s.dependency "JSONKit", "~> 1.4" + +end diff --git a/README.md b/README.md index b0f1de5..c682a25 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,13 @@ You can use the [Swift Package Manager](https://swift.org/package-manager/) and .Package(url: "https://github.com/mkrd/Swift-Big-Integer.git", majorVersion: 1) ``` +### CocoaPods: + +Put the following in your Podfile: +``` +pod 'BigNumber', '~> 2.0' +``` + ## Compatibility It is recommended to use Xcode 9+ and Swift 4+. Issues have been reported with older versions, so you might want to use an older version of this library if you can't update. @@ -165,7 +172,7 @@ bigD.description // Returns "-308/25" bigD.minimize() // Divides numerator and denominator by their gcd for storage and operation efficiency, usually not neccesary, because of automatic minimization -big.rawData() // Returns internal structure +bigD.rawData() // Returns internal structure ``` ### The following Operators work with BDouble: diff --git a/Sources/SMP.swift b/Sources/SMP.swift index 6cb304d..c3a9a0d 100644 --- a/Sources/SMP.swift +++ b/Sources/SMP.swift @@ -113,15 +113,15 @@ import Foundation // Limbs are basically single Digits in base 2^64. Each slot in an Limbs array stores one // Digit of the number. The least significant digit is stored at index 0, the most significant // digit is stored at the last index. -typealias Limbs = [UInt64] -typealias Limb = UInt64 +public typealias Limbs = [UInt64] +public typealias Limb = UInt64 // A digit is a number in base 10^18. This is the biggest possible base that // fits into an unsigned 64 bit number while maintaining the propery that the square root of // the base is a whole number and a power of ten . Digits are required for printing BInt // numbers. Limbs are converted into Digits first, and then printed. -typealias Digits = [UInt64] -typealias Digit = UInt64 +public typealias Digits = [UInt64] +public typealias Digit = UInt64 // MARK: - Imports // ———————————————————————————————————————————————————————————————————————————————————————————— @@ -233,7 +233,7 @@ public struct BInt: } /// Create an instance initialized to an integer value. - init(_ z: Int) + public init(_ z: Int) { // Since abs(Int.min) > Int.max, it is necessary to handle // z == Int.min as a special case. @@ -249,13 +249,13 @@ public struct BInt: } /// Create an instance initialized to an unsigned integer value. - init(_ n: UInt) + public init(_ n: UInt) { self.init(limbs: [Limb(n)]) } /// Create an instance initialized to a string value. - init(_ str: String) + public init(_ str: String) { var str = str var sign = false @@ -2218,7 +2218,7 @@ public struct BDouble: Returns: A new BDouble */ - init(sign: Bool, numerator: Limbs, denominator: Limbs) + public init(sign: Bool, numerator: Limbs, denominator: Limbs) { precondition( !denominator.equalTo(0) && denominator != [] && numerator != [], @@ -2232,7 +2232,7 @@ public struct BDouble: self.minimize() } - init(_ numerator: BInt, over denominator: BInt) + public init(_ numerator: BInt, over denominator: BInt) { self.init( sign: numerator.sign != denominator.sign, @@ -2241,7 +2241,7 @@ public struct BDouble: ) } - init(_ numerator: Int, over denominator: Int) + public init(_ numerator: Int, over denominator: Int) { self.init( sign: (numerator < 0) != (denominator < 0), @@ -2250,11 +2250,16 @@ public struct BDouble: ) } - init(_ numerator: String, over denominator: String) + public init(_ numerator: String, over denominator: String) { self.init(BInt(numerator), over: BInt(denominator)) } + public init(_ number: String) + { + self.init(BInt(number), over: BInt(1)) + } + public init(_ z: Int) { self.init(z, over: 1) @@ -2463,7 +2468,7 @@ public func *(lhs: BDouble, rhs: BDouble) -> BDouble return res } -func /(lhs: BDouble, rhs: BDouble) -> BDouble +public func /(lhs: BDouble, rhs: BDouble) -> BDouble { var res = BDouble( sign: lhs.sign != rhs.sign,