Skip to content

Commit

Permalink
Merge pull request #18 from twodayslate/cocoapods
Browse files Browse the repository at this point in the history
CocoaPods support
  • Loading branch information
mkrd authored Dec 18, 2017
2 parents e4074da + 3f5155e commit 7ee5001
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 13 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0
139 changes: 139 additions & 0 deletions BigNumber.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
# 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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down
29 changes: 17 additions & 12 deletions Sources/SMP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ————————————————————————————————————————————————————————————————————————————————————————————
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 != [],
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7ee5001

Please sign in to comment.