├── .github └── workflows │ ├── build.yml │ └── deploy.yml ├── .gitignore ├── LICENSE ├── Package.swift ├── README.md ├── Sources ├── Benchmarks │ ├── Benchmarks.swift │ └── main.swift ├── BigNumber │ ├── Info.plist │ └── Swift-Big-Number-Core.swift └── MGTools │ ├── Info.plist │ ├── MG Benchmark Tools.swift │ ├── MG Complex.swift │ ├── MG IO.swift │ ├── MG Math.swift │ ├── MG Matrix.swift │ ├── MG QueueDispatch.swift │ ├── MG Storage.swift │ └── MG SuperSwift.swift ├── Swift-BigInt.podspec ├── Swift-BigNumber.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ ├── xcbaselines │ └── F646295B1FF017EA0074A180.xcbaseline │ │ ├── 9D27035E-0C66-4C91-8299-009DD28C700B.plist │ │ └── Info.plist │ └── xcschemes │ ├── Benchmarks.xcscheme │ ├── BigNumber-iOS.xcscheme │ ├── BigNumber-macOS.xcscheme │ └── MGTools.xcscheme ├── Tests ├── BigNumberTests │ ├── BDoubleTests.swift │ ├── BIntTests.swift │ ├── Info.plist │ ├── Resources │ │ └── longNumbers.json │ ├── Test_Advanced_Math.swift │ ├── Test_BIntMath.swift │ ├── Test_Basic_Math.swift │ ├── Test_Initialization.swift │ └── Test_String_Conversions.swift └── MGToolsTests │ ├── Info.plist │ ├── MG Math Tests.swift │ └── MG Matrix Tests.swift ├── docs ├── Extensions.html ├── Extensions │ ├── Double.html │ └── Int.html ├── Functions.html ├── Structs.html ├── Structs │ ├── BDouble.html │ └── BInt.html ├── Typealiases.html ├── css │ ├── highlight.css │ └── jazzy.css ├── docsets │ ├── BigNumber.docset │ │ └── Contents │ │ │ ├── Info.plist │ │ │ └── Resources │ │ │ ├── Documents │ │ │ ├── Extensions.html │ │ │ ├── Extensions │ │ │ │ ├── Double.html │ │ │ │ └── Int.html │ │ │ ├── Functions.html │ │ │ ├── Structs.html │ │ │ ├── Structs │ │ │ │ ├── BDouble.html │ │ │ │ └── BInt.html │ │ │ ├── Typealiases.html │ │ │ ├── css │ │ │ │ ├── highlight.css │ │ │ │ └── jazzy.css │ │ │ ├── img │ │ │ │ ├── carat.png │ │ │ │ ├── dash.png │ │ │ │ ├── gh.png │ │ │ │ └── spinner.gif │ │ │ ├── index.html │ │ │ ├── js │ │ │ │ ├── jazzy.js │ │ │ │ ├── jazzy.search.js │ │ │ │ ├── jquery.min.js │ │ │ │ ├── lunr.min.js │ │ │ │ └── typeahead.jquery.js │ │ │ └── search.json │ │ │ └── docSet.dsidx │ ├── BigNumber.tgz │ └── BigNumber.xml ├── img │ ├── carat.png │ ├── dash.png │ ├── gh.png │ └── spinner.gif ├── index.html ├── js │ ├── jazzy.js │ ├── jazzy.search.js │ ├── jquery.min.js │ ├── lunr.min.js │ └── typeahead.jquery.js ├── search.json └── undocumented.json └── generate-docs.sh /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build & Tests 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | jobs: 8 | apple: 9 | runs-on: macOS-latest 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v3 13 | - name: Select Xcode 14 | run: sudo xcode-select -s /Applications/Xcode_15.0.app 15 | - name: Build and Test SPM 16 | run: swift test -v 17 | - name: Build and Test CocoaPods 18 | run: pod lib lint --allow-warnings --fail-fast 19 | linux: 20 | runs-on: ubuntu-latest 21 | container: 22 | image: swift:5.8.1 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@v3 26 | - name: Build and Test 27 | run: swift test -v 28 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Publish CocoaPods package 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | publish: 7 | runs-on: macOS-latest 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v3 11 | - name: Select Xcode 12 | run: sudo xcode-select -s /Applications/Xcode_14.0.app 13 | - name: Publish Pod 14 | run: | 15 | VERSION=$(echo "${VERSION_TAG}" | sed "s|^v\(.*\)$|\1|g") 16 | sed -i '' "s|[[:blank:]]*s\.version[[:blank:]].*|s.version = '${VERSION}'|g" Swift-BigInt.podspec 17 | pod trunk push --allow-warnings 18 | env: 19 | COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} 20 | VERSION_TAG: ${{ github.event.release.tag_name }} 21 | 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | .swiftpm 6 | 7 | ## Build generated 8 | build/ 9 | DerivedData 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | 22 | ## Other 23 | *.xccheckout 24 | *.moved-aside 25 | *.xcuserstate 26 | *.xcscmblueprint 27 | 28 | ## Obj-C/Swift specific 29 | *.hmap 30 | *.ipa 31 | 32 | ## Playgrounds 33 | timeline.xctimeline 34 | playground.xcworkspace 35 | 36 | # Swift Package Manager 37 | # 38 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 39 | # Packages/ 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 63 | 64 | fastlane/report.xml 65 | fastlane/screenshots 66 | 67 | .DS_Store 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 mkrd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.2 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "BigNumber", 6 | products: [ 7 | .library( 8 | name: "BigNumber", 9 | targets: ["BigNumber"]), 10 | ], 11 | dependencies: [], 12 | targets: [ 13 | .target( 14 | name: "BigNumber", 15 | dependencies: []), 16 | .target( 17 | name: "MGTools", 18 | dependencies: ["BigNumber"]), 19 | .testTarget( 20 | name: "MGToolsTests", 21 | dependencies: ["MGTools"]), 22 | .testTarget( 23 | name: "BigNumberTests", 24 | dependencies: ["BigNumber", "MGTools"]), 25 | .target( 26 | name: "Benchmarks", 27 | dependencies: ["BigNumber", "MGTools"]) 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swift-BigInt 2 | Swift-BigInt is a lightweight, and easy-to-use, arbitrary precision arithmetric library for Swift 5. 3 | 4 | It supports whole Numbers (BInt) and Fractions (BDouble) with most of the common math operators. Optimized mathematical functions like factorial or gcd are also implemented and are accessible through BIntMath. For more details, please continue reading. 5 | 6 | Some benchmarks are located in Benchmarks.swift, note that these are more than 10 times faster in the release mode, compared to the debug mode of Xcode. 7 | 8 | # Survey Time! 9 | 10 | [Survey Link](https://forms.gle/9ycR8eUEsCenvMUn7) 11 | 12 | We want to hear your opinion about Swift BigInt! If you have a few minutes, please help us with answering a few questions about how you use this project, and tell us your opinion about it. The survey is completely anonymous, and will be used to evaluate which features will be prioritized in the future. 13 | 14 | 15 | 16 | 17 | # Installation 18 | 19 | ## Drag and Drop 20 | One of the main goals of this library is to be lightweight and independent. 21 | 22 | Simply drag and drop `Swift-Big-Number-Core.swift` from the `sources` folder into your project! 23 | 24 | Yes, it's that easy :) 25 | 26 | 27 | ## Swift Package Manager 28 | 29 | You can use the [Swift Package Manager](https://swift.org/package-manager/) and specify the package dependency in your `Package.swift` file by adding this: 30 | ``` 31 | .package(url: "https://github.com/mkrd/Swift-BigInt.git", from: "2.0.0") 32 | ``` 33 | 34 | ``` 35 | import BigNumber 36 | ``` 37 | 38 | 39 | ## CocoaPods 40 | 41 | Put the following in your Podfile: 42 | ``` 43 | pod 'Swift-BigInt', '~> 2.0' 44 | ``` 45 | 46 | ``` 47 | import BigNumber 48 | ``` 49 | 50 | 51 | # Compatibility 52 | 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. 53 | 54 | 55 | # Getting Started 56 | Here is a small example, to showcase some functionalities of this library. If you want to learn more, please continue reading the Usage section below. 57 | 58 | ```swift 59 | let a = BInt(12) 60 | let b = BInt("-10000000000000000000000000000000000000000000000000000000000000000")! 61 | 62 | print(b) 63 | >>> -10000000000000000000000000000000000000000000000000000000000000000 64 | 65 | print(-a * b) 66 | >>> 120000000000000000000000000000000000000000000000000000000000000000 67 | 68 | print(BInt(200).factorial()) 69 | >>> 788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000 70 | ``` 71 | 72 | # Usage 73 | 74 | ## BInt 75 | 76 | ### Initialization 77 | You initialize BInt with `Int`, `UInt`, and `String`. If you use a `String`, the initialized `BInt` will be an optional type, which will be empty if the `String` does not contain an valid number. 78 | 79 | ``` 80 | BInt(Int) 81 | BInt(UInt) 82 | BInt(String)? 83 | BInt(String, radix: Int)? 84 | ``` 85 | 86 | ### Examples 87 | ```swift 88 | let a = BInt(12) 89 | print(a) 90 | >>> 12 91 | 92 | 93 | let b = BInt("-234324176583764598326758236587632649181349105368042856028465298620328782652623") 94 | print(b!) 95 | >>> -234324176583764598326758236587632649181349105368042856028465298620328782652623 96 | 97 | 98 | let invalid = BInt("I'm not a number") 99 | if let c = invalid { 100 | print(c) 101 | } else { 102 | print("Not a valid number!") 103 | } 104 | >>> Not a valid number! 105 | 106 | 107 | let d = BInt("fff", radix: 16) 108 | print(d) 109 | >>> 4095 110 | ``` 111 | 112 | ### BInt offers these struct methods 113 | ```swift 114 | let big = BInt("-143141341")! 115 | 116 | big.description // Returns "-143141341" 117 | => print(big) // prints "-143141341" 118 | 119 | big.toInt() // returns -143141341 (only works when Int.min <= big <= Int.max) 120 | 121 | big.isPositive() // Returns false 122 | big.isNegative() // Returns true 123 | big.isZero() // Returns false 124 | 125 | big.negate() // Returns noting, but negates the BInt (mutating func) 126 | 127 | big.rawData() // Returns internal structure 128 | ``` 129 | 130 | ## The following Operators work with BInt 131 | ```swift 132 | // Operating on Int and BInt result in a typecast to BInt 133 | 134 | // Addition 135 | BIntOrInt + BIntOrInt // Returns BInt 136 | BIntOrInt += BIntOrInt 137 | 138 | //Subtraction 139 | BIntOrInt - BIntOrInt // Returns BInt 140 | BIntOrInt -= BIntOrInt 141 | 142 | // Multiplication 143 | BIntOrInt * BIntOrInt // Returns BInt 144 | BIntOrInt *= BIntOrInt 145 | 146 | // Exponentiation 147 | BInt ** Int // Returns BInt to the power of Int 148 | 149 | // Modulo 150 | BIntOrInt % BIntOrInt // Returns BInt 151 | BInt %= BInt 152 | 153 | // Division 154 | BInt / BInt // Returns BInt 155 | BInt /= BInt 156 | 157 | 158 | // Comparing 159 | BInt == BInt 160 | BInt != BInt 161 | BInt < BInt 162 | BInt <= BInt 163 | BInt > BInt 164 | BInt >= BInt 165 | ``` 166 | 167 | ### Implemented BInt math functions 168 | ```swift 169 | fact(Int) // Returns factorial as BInt 170 | 171 | gcd(BInt, BInt) // Returns greatest common divisor as BInt 172 | 173 | lcm(BInt, BInt) // Returns lowest common multiple as BInt 174 | 175 | permutations(BInt, BInt) // Returns BInt 176 | 177 | combinations(BInt, BInt) // Returns BInt 178 | ``` 179 | 180 | ## BDouble 181 | 182 | ### BDouble allows these constructors 183 | ```swift 184 | BDouble(Int) 185 | BDouble(Double) 186 | BDouble(String)? 187 | BDouble(Int, over: Int) 188 | BDouble(String, over: String)? 189 | BDouble(String, radix: Int)? 190 | ``` 191 | 192 | ### Examples 193 | ```swift 194 | let integer = BDouble(221) 195 | let double = BDouble(1.192) 196 | let fraction = BDouble(3, over: 4) 197 | let stringFraction = BDouble("1" over: "3421342675925672365438867862653658268376582356831563158967")! 198 | ``` 199 | 200 | ### BDouble offers these struct methods 201 | ```swift 202 | let bigD = BDouble(-12.32) 203 | 204 | bigD.description // Returns "-308/25" 205 | => print(bigD) // prints "-308/25" 206 | 207 | 208 | bigD.minimize() // Divides numerator and denominator by their gcd for storage and operation efficiency, usually not necessary, because of automatic minimization 209 | 210 | bigD.rawData() // Returns internal structure 211 | ``` 212 | 213 | ## The following Operators work with BDouble 214 | ```swift 215 | // Needs more operators, interoperability with BInt 216 | 217 | // Addition 218 | BDouble + BDouble // Returns BDouble 219 | 220 | // Subtraction 221 | BDouble - BDouble // Returns BDouble 222 | 223 | // Multiplication 224 | BDouble * BDouble // Returns BDouble 225 | 226 | // Division 227 | BDouble / BDouble // Returns BDouble 228 | 229 | // Comparing 230 | BDouble < BDouble 231 | /* 232 | Important: 233 | a < b <==> b > a 234 | a <= b <==> b >= a 235 | but: 236 | a < b <==> !(a >= b) 237 | a <= b <==> !(a > b) 238 | */ 239 | 240 | // More will follow 241 | ``` 242 | 243 | 244 | 245 | # About performance 246 | BInt about twice as fast as mini-gmp, as of now (not counting the normal gmp, because it needs to be installed and is not portable). For example, BInt can add numbers about 2 times faster than GMP (272ms vs 530ms for fib(100,000)), and multiplication is more than twice as fast. When given the task of calculating and printing factorials successively, BInt performs significantly better than GMP. In addition, GMP is significantly harder to use, while BInt offers an intuitive interface. 247 | 248 | 249 | 250 | # Contributing 251 | 1. Fork it! 252 | 2. Create your feature branch: `git checkout -b my-new-feature` 253 | 3. Commit your changes: `git commit -am 'Add some feature'` 254 | 4. Push to the branch: `git push origin my-new-feature` 255 | 5. Submit a pull request :D 256 | -------------------------------------------------------------------------------- /Sources/Benchmarks/Benchmarks.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * Benchmarks.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 05.09.17. 6 | * Copyright © 2017 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | @testable import BigNumber 11 | @testable import MGTools 12 | 13 | public class Benchmarks 14 | { 15 | static func Matrix1() 16 | { 17 | let A = Matrix( 18 | [[2,5,-2], 19 | [3,5,6], 20 | [-55,4,3]] 21 | ) 22 | 23 | let G12 = Matrix([ 24 | [0.8, -0.6, 0.0], 25 | [0.6, 0.8, 0.0], 26 | [0.0, 0.0, 1.0] 27 | ]) 28 | 29 | 30 | let al = Matrix([4, -3, 1]) 31 | 32 | print(G12 * al) 33 | 34 | let (L, R, P, D) = LRDecompPivEquil(A) 35 | 36 | print(solveGauss(A, [2.0, -4.0, 15.0])) 37 | print(solveLR(A, [2.0, -4.0, 15.0])) 38 | print(solveLRPD(A, [2.0, -4.0, 15.0])) 39 | 40 | print("P L R") 41 | print(P) 42 | print(L) 43 | print(R) 44 | 45 | print("LR == PDA") 46 | print(L * R) 47 | print(P * D * A) 48 | 49 | 50 | benchmarkAndPrint(title: "Matix ^ 100") 51 | { 52 | var R = A 53 | for _ in 0...100 54 | { 55 | R = R * A 56 | } 57 | } 58 | } 59 | 60 | static func BDoubleConverging() 61 | { 62 | benchmarkAndPrint(title: "BDouble converging to 2") 63 | { 64 | // BDouble converging to 2 Debug Mode 65 | // 06.02.16: 3351ms 66 | 67 | var res: BDouble = 0 68 | var den: BInt = 1 69 | 70 | for _ in 0..<1000 71 | { 72 | res = res + BDouble(BInt(1), over: den) 73 | den *= 2 74 | } 75 | } 76 | } 77 | 78 | static func factorial() 79 | { 80 | let n = 25_000 81 | 82 | benchmarkAndPrint(title: "Factorial of 25000") 83 | { 84 | // Fkt 1000 Debug Mode 85 | // 27.01.16: 2548ms 86 | // 30.01.16: 1707ms 87 | // 01.02.16: 398ms 88 | 89 | // Fkt 2000 Debug Mode 90 | // 01.02.16: 2452ms 91 | // 04.02.16: 2708ms 92 | // 06.02.16: 328ms 93 | 94 | // Factorial 4000 Debug Mode 95 | // 06.02.16: 2669ms 96 | // 10.02.16: 571ms 97 | // 28.02.16: 550ms 98 | // 01.03.16: 56ms 99 | 100 | // Factorial 25000 Debug Mode 101 | // 01.03.16: 2871ms 102 | // 07.03.16: 2221ms 103 | // 16.08.16: 1759ms 104 | // 20.08.16: 1367ms 105 | // 23.08.19: 1075ms 106 | _ = BInt(n).factorial() 107 | } 108 | } 109 | 110 | static func exponentiation() 111 | { 112 | let n = 10 113 | let pow = 120_000 114 | 115 | benchmarkAndPrint(title: "10^120_000") 116 | { 117 | // 10^14000 Debug Mode 118 | // 06.02.16: 2668ms 119 | // 10.02.16: 372ms 120 | // 20.02.16: 320ms 121 | // 28.02.16: 209ms 122 | // 01.03.16: 39ms 123 | 124 | // 10^120_000 Debug Mode 125 | // 01.03.16: 2417ms 126 | // 07.03.16: 1626ms 127 | // 16.08.16: 1154ms 128 | // 20.08.16: 922ms 129 | // 23.08.19: 710ms 130 | 131 | _ = BInt(n) ** pow 132 | } 133 | } 134 | 135 | static func fibonacci() 136 | { 137 | let n = 100_000 138 | 139 | benchmarkAndPrint(title: "Fib \(n)") 140 | { 141 | // Fib 35.000 Debug Mode 142 | // 27.01.16: 2488ms 143 | // 30.01.16: 1458ms 144 | // 01.02.16: 357ms 145 | 146 | // Fib 100.000 Debug Mode 147 | // 01.02.16: 2733ms 148 | // 04.02.16: 2949ms 149 | // 10.02.16: 1919ms 150 | // 28.02.16: 1786ms 151 | // 07.03.16: 1716ms 152 | // 23.08.19: 1124ms 153 | 154 | _ = BIntMath.fib(n) 155 | } 156 | } 157 | 158 | static func mersennes() 159 | { 160 | let n = 256 161 | 162 | benchmarkAndPrint(title: "\nMersennes to 2^\(n)") 163 | { 164 | // Mersenne to exp 256 Debug Mode 165 | // 02.10.16: 1814ms 166 | 167 | for i in 1...n 168 | { 169 | if math.isPrime(i) && BIntMath.isMersenne(i) 170 | { 171 | print(i, terminator: ",") 172 | } 173 | } 174 | 175 | } 176 | } 177 | 178 | static func BIntToString() 179 | { 180 | let factorialBase = 15_000 181 | let n = BInt(factorialBase).factorial() 182 | benchmarkAndPrint(title: "Get \(factorialBase)! as String") 183 | { 184 | // Get 300! (615 decimal digits) as String Debug Mode 185 | // 30.01.16: 2635ms 186 | // 01.02.16: 3723ms 187 | // 04.02.16: 2492m 188 | // 06.02.16: 2326ms 189 | // 07.02.16: 53ms 190 | 191 | // Get 1000! (2568 decimal digits) as String Debug Mode 192 | // 07.02.16: 2386ms 193 | // 10.02.16: 343ms 194 | // 20.02.16: 338ms 195 | // 22.02.16: 159ms 196 | 197 | // Get 3000! (9131 decimal digits) as String Debug Mode 198 | // 22.02.16: 2061ms 199 | // 28.02.16: 1891ms 200 | // 01.03.16: 343ms 201 | 202 | // Get 7500! (25809 decimal digits) as String Debug Mode 203 | // 01.03.16: 2558ms 204 | // 07.03.16: 1604ms 205 | // 07.03.16: 1562ms 206 | // 16.08.16: 455ms 207 | 208 | // Get 15000! (56130 decimal digits) as String Debug Mode 209 | // 07.09.17: 2701ms 210 | 211 | _ = n.description 212 | } 213 | } 214 | 215 | static func StringToBInt() 216 | { 217 | let factorialBase = 16_000 218 | let asStr = BInt(factorialBase).factorial().description 219 | var res: BInt = 0 220 | 221 | benchmarkAndPrint(title: "BInt from String, \(asStr.count) digits (\(factorialBase)!)") 222 | { 223 | // BInt from String, 3026 digits (1151!) Debug Mode 224 | // 07.02.16: 2780ms 225 | // 10.02.16: 1135ms 226 | // 28.02.16: 1078ms 227 | // 01.03.16: 430ms 228 | 229 | // BInt from String, 9131 digits (3000!) Debug Mode 230 | // 01.03.16: 3469ms 231 | // 07.03.16: 2305ms 232 | // 07.03.16: 1972ms 233 | // 26.06.16: 644ms 234 | 235 | // BInt from String, 20066 digits (6000!) Debug Mode 236 | // 26.06.16: 3040ms 237 | // 16.08.16: 2684ms 238 | // 20.08.16: 2338ms 239 | 240 | // BInt from String, 60320 digits (16000!) Debug Mode 241 | // 07.09.17: 2857ms 242 | // 26.04.18: 1081ms 243 | 244 | res = BInt(asStr)! 245 | } 246 | 247 | assert(asStr == res.description) 248 | } 249 | 250 | static func permutationsAndCombinations() 251 | { 252 | benchmarkAndPrint(title: "Perm and Comb") 253 | { 254 | // Perm and Comb (2000, 1000) Debug Mode 255 | // 04.02.16: 2561ms 256 | // 06.02.16: 2098ms 257 | // 07.02.16: 1083ms 258 | // 10.02.16: 350ms 259 | // 28.02.16: 337ms 260 | // 01.03.16: 138ms 261 | 262 | // Perm and Comb (8000, 4000) Debug Mode 263 | // 07.03.16: 905ms 264 | // 07.03.16: 483ms 265 | 266 | _ = BIntMath.permutations(8000, 4000) 267 | _ = BIntMath.combinations(8000, 4000) 268 | } 269 | } 270 | 271 | static func multiplicationBalanced() 272 | { 273 | let b1 = BIntMath.randomBInt(bits: 270_000) 274 | let b2 = BIntMath.randomBInt(bits: 270_000) 275 | 276 | benchmarkAndPrint(title: "Multiply two random BInts with size of 270_000 and 270_000 bits") 277 | { 278 | // Multiply two random BInts with size of 270_000 and 270_000 bits 279 | // 26.04.18: 2427ms 280 | 281 | _ = b1 * b2 282 | } 283 | } 284 | 285 | static func multiplicationUnbalanced() 286 | { 287 | let b1 = BIntMath.randomBInt(bits: 70_000_000) 288 | let b2 = BIntMath.randomBInt(bits: 1_000) 289 | 290 | benchmarkAndPrint(title: "Multiply two random BInts with size of 70_000_000 and 1_000 bits") 291 | { 292 | // Multiply two random BInts with size of 70_000_000 and 1_000 bits 293 | // 26.04.18: 2467ms 294 | 295 | _ = b1 * b2 296 | } 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /Sources/Benchmarks/main.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // Run Benchmarks 4 | Benchmarks.BDoubleConverging() 5 | Benchmarks.exponentiation() 6 | Benchmarks.factorial() 7 | Benchmarks.fibonacci() 8 | Benchmarks.Matrix1() 9 | Benchmarks.mersennes() 10 | Benchmarks.BIntToString() 11 | Benchmarks.StringToBInt() 12 | //Benchmarks.permutationsAndCombinations() 13 | Benchmarks.multiplicationBalanced() 14 | Benchmarks.multiplicationUnbalanced() 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | //public struct PixelData { 27 | // var a:UInt8 = 255 28 | // var r:UInt8 29 | // var g:UInt8 30 | // var b:UInt8 31 | //} 32 | // 33 | //private let rgbColorSpace = CGColorSpaceCreateDeviceRGB() 34 | //private let bitmapInfo:CGBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue) 35 | // 36 | //public func imageFromARGB32Bitmap(pixels:[PixelData], width: Int, height: Int) -> CGImage { 37 | // let bitsPerComponent: Int = 8 38 | // let bitsPerPixel: Int = 32 39 | // 40 | // assert(pixels.count == Int(width * height)) 41 | // 42 | // var data = pixels // Copy to mutable [] 43 | // let providerRef = CGDataProvider( 44 | // data: NSData(bytes: &data, length: data.count * MemoryLayout.size) 45 | // ) 46 | // 47 | // let cgim = CGImage( 48 | // width: width, 49 | // height: height, 50 | // bitsPerComponent: bitsPerComponent, 51 | // bitsPerPixel: bitsPerPixel, 52 | // bytesPerRow: width * MemoryLayout.size, 53 | // space: rgbColorSpace, 54 | // bitmapInfo: bitmapInfo, 55 | // provider: providerRef!, 56 | // decode: nil, 57 | // shouldInterpolate: true, 58 | // intent: CGColorRenderingIntent.defaultIntent 59 | // ) 60 | // return cgim! 61 | //} 62 | // 63 | // 64 | //@discardableResult 65 | //func writeCGImage(_ image: CGImage, to destinationURL: URL) -> Bool { 66 | // guard let destination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypePNG, 1, nil) else { 67 | // print("ERR") 68 | // return false 69 | // 70 | // } 71 | // CGImageDestinationAddImage(destination, image, nil) 72 | // return CGImageDestinationFinalize(destination) 73 | //} 74 | // 75 | //func makeAndSave() 76 | //{ 77 | // let dimension = 4000 78 | // 79 | // 80 | // var pixels = [PixelData]() 81 | // 82 | // for i in 1...(dimension * dimension) 83 | // { 84 | // if math.isPrime(i) 85 | // { 86 | // pixels.append(PixelData(a: 255, r: 0, g: 0, b: 0)) 87 | // } 88 | // else 89 | // { 90 | // pixels.append(PixelData(a: 0, r: 255, g: 255, b: 255)) 91 | // } 92 | // } 93 | // 94 | // 95 | // let img = imageFromARGB32Bitmap(pixels: pixels, width: dimension, height: dimension) 96 | // 97 | // let writeURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first!.appendingPathComponent("name.png") 98 | // 99 | // writeCGImage(img, to: writeURL) 100 | //} 101 | // 102 | //benchmarkAndPrint(title: "") 103 | //{ 104 | // makeAndSave() 105 | //} 106 | 107 | -------------------------------------------------------------------------------- /Sources/BigNumber/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 2.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSHumanReadableCopyright 22 | Copyright © 2017 Marcel Kröker. All rights reserved. 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Sources/MGTools/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Sources/MGTools/MG Benchmark Tools.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Benchmark Tools.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 03.04.2015. 6 | * Copyright © 2015 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | #if os(Linux) 11 | import Glibc 12 | 13 | private func mach_absolute_time() -> UInt64 { 14 | var tv = timeval(); 15 | guard gettimeofday(&tv, nil) != -1 else { return 0 } 16 | 17 | let t = UInt64(tv.tv_usec) + UInt64(tv.tv_sec) * 1000000 18 | return t; 19 | } 20 | 21 | private struct mach_timebase_info_data_t { 22 | var numer: Int = 1000 23 | var denom: Int = 1 24 | } 25 | 26 | private func mach_timebase_info(_: inout mach_timebase_info_data_t) {} 27 | #endif 28 | 29 | /// Returns the time in nanoseconds it took to execute the call. 30 | private func durationNS(_ call: () -> ()) -> Int 31 | { 32 | var start = UInt64() 33 | var end = UInt64() 34 | 35 | start = mach_absolute_time() 36 | call() 37 | end = mach_absolute_time() 38 | 39 | var timeBaseInfo = mach_timebase_info_data_t() 40 | mach_timebase_info(&timeBaseInfo) 41 | 42 | return Int(end - start) * Int(timeBaseInfo.numer) / Int(timeBaseInfo.denom) 43 | } 44 | 45 | private func adjustPrecision(_ ns: Int, toPrecision: String) -> Int 46 | { 47 | switch toPrecision 48 | { 49 | case "ns": // nanoseconds 50 | return ns 51 | case "us": // microseconds 52 | return ns / 1_000 53 | case "ms": // milliseconds 54 | return ns / 1_000_000 55 | default: // seconds 56 | return ns / 1_000_000_000 57 | } 58 | } 59 | 60 | /** 61 | Measure execution time of trailing closure. 62 | 63 | - Parameter precision: Precision of measurement. Possible 64 | values: 65 | - "ns": nanoseconds 66 | - "us": microseconds 67 | - "ms" or omitted parameter: milliseconds 68 | - "s" or invalid input: seconds 69 | */ 70 | public func benchmark(_ precision: String = "ms", _ call: () -> ()) -> Int 71 | { 72 | // empty call duration to subtract 73 | let emptyCallElapsedNS = durationNS({}) 74 | let elapsedNS = durationNS(call) 75 | 76 | let elapsedCorrected = elapsedNS >= emptyCallElapsedNS 77 | ? elapsedNS - emptyCallElapsedNS 78 | : 0 79 | 80 | return adjustPrecision(elapsedCorrected, toPrecision: precision) 81 | } 82 | 83 | /** 84 | Measure execution time of trailing closure, and print result 85 | with description into the console. 86 | 87 | - Parameter precision: Precision of measurement. Possible 88 | values: 89 | - "ns": nanoseconds 90 | - "us": microseconds 91 | - "ms" or omitted parameter: milliseconds 92 | - "s" or invalid input: seconds 93 | 94 | - Parameter title: Description of benchmark. 95 | */ 96 | public func benchmarkAndPrint(_ precision: String = "ms", title: String, _ call: () -> ()) 97 | { 98 | print("=> \(title): \(benchmark(precision, call))\(precision)") 99 | } 100 | 101 | 102 | /** 103 | Measure the average execution time of trailing closure. 104 | 105 | - Parameter precision: Precision of measurement. Possible 106 | values: 107 | - "ns": nanoseconds 108 | - "us": microseconds 109 | - "ms" or omitted parameter: milliseconds 110 | - "s" or invalid input: seconds 111 | 112 | - Parameter title: Description of benchmark. 113 | 114 | - Parameter times: Amount of executions. 115 | Default when parameter is omitted: 100. 116 | 117 | - Returns: Minimum, Average and Maximum execution time of 118 | benchmarks as 3-tuple. 119 | */ 120 | public func benchmarkAvg( 121 | _ precision: String = "ms", 122 | times: Int = 10, 123 | _ call: () -> ()) 124 | -> (min: Int, avg: Int, max: Int) 125 | { 126 | let emptyCallsNS = durationNS({ 127 | for _ in 0.. max { max = duration } 141 | 142 | elapsedNSCombined += duration 143 | } 144 | 145 | let elapsedCorrected = elapsedNSCombined >= emptyCallsNS 146 | ? elapsedNSCombined - emptyCallsNS 147 | : 0 148 | 149 | return ( 150 | adjustPrecision(min, toPrecision: precision), 151 | adjustPrecision(elapsedCorrected / times, toPrecision: precision), 152 | adjustPrecision(max, toPrecision: precision) 153 | ) 154 | } 155 | 156 | public func benchmarkAvgPrint( 157 | _ precision: String = "ms", 158 | title: String, 159 | _ times: Int = 10, 160 | _ call: () -> ()) 161 | { 162 | let (min, avg, max) = benchmarkAvg(precision, times: times, call) 163 | 164 | let avgDur = "\(avg)" + precision + " average, " 165 | let minDur = "\(min)" + precision + " min, " 166 | let maxDur = "\(max)" + precision + " max" 167 | 168 | print("=> \(title): \(times) times, " + avgDur + minDur + maxDur) 169 | } 170 | -------------------------------------------------------------------------------- /Sources/MGTools/MG Complex.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Complex.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 06.11.16. 6 | * Copyright © 2016 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | public struct Complex 12 | { 13 | var (re, im): (Double, Double) 14 | 15 | init(re: Double, im: Double) 16 | { 17 | self.re = re 18 | self.im = im 19 | } 20 | 21 | var r: Double 22 | { 23 | get { return self.re } 24 | set { self.re = r } 25 | } 26 | 27 | var i: Double 28 | { 29 | get { return self.im } 30 | set { self.im = i } 31 | } 32 | } 33 | 34 | public func +(lhs: Complex, rhs: Complex) -> Complex 35 | { 36 | return Complex( 37 | re: lhs.re + rhs.re, 38 | im: lhs.im + rhs.im 39 | ) 40 | } 41 | 42 | public func -(lhs: Complex, rhs: Complex) -> Complex 43 | { 44 | return Complex( 45 | re: lhs.re + rhs.re, 46 | im: lhs.im + rhs.im 47 | ) 48 | } 49 | 50 | public func *(x: Complex, y: Complex) -> Complex 51 | { 52 | return Complex( 53 | re: x.re * y.re - x.im * y.im, 54 | im: x.im * y.re + x.re * y.im 55 | ) 56 | } 57 | 58 | public func /(x: Complex, y: Complex) -> Complex 59 | { 60 | let divisor = y.re * y.re + y.im * y.im 61 | return Complex( 62 | re: (x.re * y.re + x.im * y.im) / divisor, 63 | im: (x.im * y.re - x.re * y.im) / divisor 64 | ) 65 | } 66 | 67 | public func exp(_ x: Complex) -> Complex 68 | { 69 | let ea = Complex(re: pow(2.7, x.re), im: 0.0 ) 70 | let t = Complex(re: cos(x.im) , im: sin(x.im)) 71 | return ea * t 72 | } 73 | -------------------------------------------------------------------------------- /Sources/MGTools/MG IO.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG IO.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 27.05.16. 6 | * Copyright © 2016 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | /** 12 | Stop execution and log keyboard input. Returns input after enter was 13 | pressed. 14 | */ 15 | public func getKeyboardInput() -> String 16 | { 17 | let keyboard = FileHandle.standardInput 18 | 19 | let input = String( 20 | data: keyboard.availableData, 21 | encoding: String.Encoding.utf8 22 | )! 23 | 24 | return input.trimmingCharacters(in: CharacterSet(["\n"])) 25 | } 26 | 27 | /** 28 | Stop execution and log keyboard input. Returns input as Int after a vaild 29 | Integer was entered. Otherwise, it promts the user again until a vaild 30 | Integer was entered. 31 | */ 32 | public func getKeyboardInputAsInt() -> Int 33 | { 34 | while true 35 | { 36 | let input = getKeyboardInput() 37 | 38 | if let asInt = Int(input) { return asInt } 39 | 40 | print("Input must be an Integer but was: \"\(input)\"") 41 | print("Enter a vaild number:") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Sources/MGTools/MG Math.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Basic Math.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 03.04.2015. 6 | * Copyright © 2015 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | #if os(Linux) 10 | import Glibc 11 | #endif 12 | 13 | import Foundation 14 | import BigNumber 15 | 16 | //infix operator ** 17 | 18 | func **(lhs: Double, rhs: Double) -> Double { return pow(lhs, rhs) } 19 | func **(lhs: Int, rhs: Double) -> Double { return pow(Double(lhs), rhs) } 20 | func **(lhs: Double, rhs: Int) -> Double { return pow(lhs, Double(rhs)) } 21 | func **(lhs: Int, rhs: Int) -> Int 22 | { 23 | var res = 1 24 | for _ in 0.. Double { return lhs + Double(rhs) } 33 | func +(lhs: Int, rhs: Double) -> Double { return Double(lhs) + rhs } 34 | 35 | func -(lhs: Double, rhs: Int) -> Double { return lhs - Double(rhs) } 36 | func -(lhs: Int, rhs: Double) -> Double { return Double(lhs) - rhs } 37 | 38 | func *(lhs: Double, rhs: Int) -> Double { return lhs * Double(rhs) } 39 | func *(lhs: Int, rhs: Double) -> Double { return Double(lhs) * rhs } 40 | 41 | func /(lhs: Double, rhs: Int) -> Double { return lhs / Double(rhs) } 42 | func /(lhs: Int, rhs: Double) -> Double { return Double(lhs) / rhs } 43 | 44 | 45 | 46 | public class math 47 | { 48 | init() 49 | { 50 | fatalError("math is purely static, you can't make an instance of it.") 51 | } 52 | 53 | /// Returns the logarithm of n to the base of b. 54 | public static func lg(base b: Double, _ n: Double) -> Double 55 | { 56 | return log2(Double(n)) / log2(Double(b)) 57 | } 58 | 59 | /// Returns the logarithm of n to the base of b. 60 | public static func lg(base b: Int, _ n: Double) -> Double 61 | { 62 | return math.lg(base: Double(b), n) 63 | } 64 | 65 | /// Returns the logarithm of n to the base of b. 66 | public static func lg(base b: Double, _ n: Int) -> Double 67 | { 68 | return math.lg(base: b, Double(n)) 69 | } 70 | 71 | /// Returns the logarithm of n to the base of b. 72 | public static func lg(base b: Int, _ n: Int) -> Double 73 | { 74 | return math.lg(base: Double(b), Double(n)) 75 | } 76 | 77 | 78 | /// Returns the binomial coefficient of n and k. 79 | public static func binomial(_ n: Int, _ k: Int) -> Int 80 | { 81 | if k == 0 { return 1 } 82 | if n == 0 { return 0 } 83 | return math.binomial(n - 1, k) + math.binomial(n - 1, k - 1) 84 | } 85 | 86 | /// Returns the greatest common divisor of a and b. 87 | public static func gcd(_ a: Int, _ b: Int) -> Int 88 | { 89 | if b == 0 { return a } 90 | return math.gcd(b, a % b) 91 | } 92 | 93 | /// Returns the lest common multiple of a and b. 94 | public static func lcm(_ a: Int, _ b: Int) -> Int 95 | { 96 | return (a / math.gcd(a, b)) * b 97 | } 98 | 99 | /** 100 | * Returns the number of digits of the input in the specified base. 101 | * Positive and negative numbers are treated equally. 102 | */ 103 | public static func digitsCount(base b: Int, _ n: Int) -> Int 104 | { 105 | var n = abs(n) 106 | var count = 0 107 | 108 | while n != 0 109 | { 110 | n /= b 111 | count += 1 112 | } 113 | 114 | return count 115 | } 116 | 117 | // Returns true iff n is a prime number. 118 | public static func isPrime(_ n: Int) -> Bool 119 | { 120 | if n <= 3 { return n > 1 } 121 | 122 | if n % 2 == 0 || n % 3 == 0 { return false } 123 | 124 | var i = 5 125 | while i * i <= n 126 | { 127 | if n % i == 0 || n % (i + 2) == 0 128 | { 129 | return false 130 | } 131 | i += 6 132 | } 133 | return true 134 | } 135 | 136 | /// Returns the n-th prime number. The first one is 2, etc. 137 | public static func getPrime(_ n: Int) -> Int 138 | { 139 | precondition(n > 0, "There is no \(n)-th prime number") 140 | 141 | var (prime, primeCount) = (2, 1) 142 | 143 | while primeCount != n 144 | { 145 | prime += 1 146 | if math.isPrime(prime) { primeCount += 1 } 147 | } 148 | 149 | return prime 150 | } 151 | 152 | 153 | 154 | /// Returns all primes that are smaller or equal to n. Works with the Sieve of Eratosthenes. 155 | public static func primesThrough(_ n: Int) -> [Int] 156 | { 157 | if n < 2 { return [] } 158 | 159 | // represent numbers 3,5,... that are <= n 160 | var A = [Bool](repeating: true, count: n >> 1) 161 | 162 | var (i, j, c) = (3, 0, 0) 163 | while i * i <= n 164 | { 165 | if A[(i >> 1) - 1] 166 | { 167 | (c, j) = (1, i * i) 168 | while j <= n 169 | { 170 | if j % 2 != 0 { A[(j >> 1) - 1] = false } 171 | j = i * (i + c) 172 | c += 1 173 | } 174 | } 175 | i += 2 176 | } 177 | 178 | var res = [2] 179 | 180 | i = 3 181 | while i <= n 182 | { 183 | if A[(i >> 1) - 1] { res.append(i) } 184 | i += 2 185 | } 186 | 187 | return res 188 | } 189 | 190 | 191 | /// Increments the input parameter until it is the next bigger prime. 192 | public static func nextPrime( _ n: inout Int) 193 | { 194 | repeat { n += 1 } while !math.isPrime(n) 195 | } 196 | 197 | /// Returns a random integer within the specified range. The maximum range size is 2**32 - 1 198 | public static func random(_ range: Range) -> Int 199 | { 200 | return Int.random(in: range) 201 | } 202 | 203 | /// Returns a random integer within the specified closed range. 204 | public static func random(_ range: ClosedRange) -> Int 205 | { 206 | return math.random(Range(range)) 207 | } 208 | 209 | /// Returns an array filled with n random integers within the specified range. 210 | public static func random(_ range: Range, count: Int) -> [Int] 211 | { 212 | return [Int](repeating: 0, count: count).map{ _ in math.random(range) } 213 | } 214 | 215 | /// Returns an array filled with n random integers within the specified closed range. 216 | public static func random(_ range: ClosedRange, count: Int) -> [Int] 217 | { 218 | return math.random(Range(range), count: count) 219 | } 220 | 221 | /// Returns a random Double within the specified closed range. 222 | public static func random(_ range: ClosedRange) -> Double 223 | { 224 | return Double.random(in: range) 225 | } 226 | 227 | /// Returns an array filled with n random Doubles within the specified closed range. 228 | public static func random(_ range: ClosedRange, count: Int) -> [Double] 229 | { 230 | return [Double](repeating: 0, count: count).map{ _ in math.random(range) } 231 | } 232 | 233 | /// Calculate a random value from a standard normal distribution with mean 0 and variance 1. 234 | public static func randomStandardNormalDistributed() -> Double 235 | { 236 | var (x, y, l) = (0.0, 0.0, 0.0) 237 | 238 | while l >= 1.0 || l == 0.0 239 | { 240 | x = math.random(-1.0...1.0) 241 | y = math.random(-1.0...1.0) 242 | l = pow(x, 2.0) + pow(y, 2.0) 243 | } 244 | 245 | return y * sqrt((-2.0 * log(l)) / l) 246 | } 247 | 248 | 249 | /// Generate count many random values from a normal distribution with the given mean and variance. 250 | public static func randomFromNormalDist(_ mean: Double, _ variance: Double, _ count: Int) -> [Double] 251 | { 252 | let res = [Double](repeating: mean, count: count) 253 | 254 | return res.map{ $0 + (variance * math.randomStandardNormalDistributed()) 255 | } 256 | } 257 | 258 | /// Multiple cases to select the instance space of a random string. 259 | public enum LetterSet 260 | { 261 | case lowerCase 262 | case upperCase 263 | case numbers 264 | case specialSymbols 265 | case all 266 | } 267 | 268 | /** 269 | Creates a random String from one or multiple sets of 270 | letters. 271 | 272 | - Parameter length: Number of characters in random string. 273 | 274 | - Parameter letterSet: Specify desired letters as variadic 275 | parameters: 276 | - .All 277 | - .Numbers 278 | - .LowerCase 279 | - .UpperCase 280 | - .SpecialSymbols 281 | */ 282 | public static func randomString(_ length: Int, letterSet: LetterSet...) -> String 283 | { 284 | var letters = [String]() 285 | var ranges = [CountableClosedRange]() 286 | 287 | for ele in letterSet 288 | { 289 | switch ele 290 | { 291 | case .all: 292 | ranges.append(33...126) 293 | 294 | case .numbers: 295 | ranges.append(48...57) 296 | 297 | case .lowerCase: 298 | ranges.append(97...122) 299 | 300 | case .upperCase: 301 | ranges.append(65...90) 302 | 303 | case .specialSymbols: 304 | ranges += [33...47, 58...64, 91...96, 123...126] 305 | } 306 | } 307 | 308 | for range in ranges 309 | { 310 | for symbol in range 311 | { 312 | letters.append(String(describing: UnicodeScalar(symbol)!)) 313 | } 314 | } 315 | 316 | var res = "" 317 | 318 | for _ in 0.. [(factor: Int, count: Int)] 328 | { 329 | if math.isPrime(n) || n == 1 { return [(n, 1)] } 330 | 331 | var n = n 332 | var res = [(factor: Int, count: Int)]() 333 | var nthPrime = 1 334 | 335 | while true 336 | { 337 | math.nextPrime(&nthPrime) 338 | 339 | if n % nthPrime == 0 340 | { 341 | var times = 1 342 | n /= nthPrime 343 | 344 | while n % nthPrime == 0 345 | { 346 | times += 1 347 | n /= nthPrime 348 | } 349 | 350 | res.append((nthPrime, times)) 351 | 352 | if n == 1 { return res } 353 | 354 | if math.isPrime(n) 355 | { 356 | res.append((n, 1)) 357 | return res 358 | } 359 | } 360 | } 361 | } 362 | } 363 | -------------------------------------------------------------------------------- /Sources/MGTools/MG QueueDispatch.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG QueueDispatch.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 25.12.15. 6 | * Copyright © 2015 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | public struct QueueDispatch 12 | { 13 | static var coreCount: Int 14 | { 15 | return ProcessInfo.processInfo.activeProcessorCount 16 | } 17 | 18 | /** 19 | Run trailing closure after a given time in seconds in background queue. 20 | */ 21 | static public func runAfterDelay(_ seconds: Double, _ closure: @escaping () -> ()) 22 | { 23 | let queue = DispatchQueue.global() 24 | 25 | queue.asyncAfter(deadline: DispatchTime.now() + seconds, execute: closure) 26 | } 27 | 28 | /** 29 | Dispatches closures and optionally waits for them to finish their 30 | execution before the caller can continue executing his code. 31 | */ 32 | static public func parallel(waitUnitAllFinished wait: Bool, closures: [() -> ()]) 33 | { 34 | let queue = OperationQueue() 35 | 36 | queue.maxConcurrentOperationCount = QueueDispatch.coreCount - (wait ? 0 : 1) 37 | 38 | for closure in closures 39 | { 40 | queue.addOperation(closure) 41 | } 42 | 43 | if wait { queue.waitUntilAllOperationsAreFinished() } 44 | } 45 | } 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Sources/MGTools/MG Storage.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Storage.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 09.10.16. 6 | * Copyright © 2016 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import Foundation 10 | 11 | 12 | public struct Storage 13 | { 14 | static func readResource(_ key: String, inBundle: Bundle = Bundle.main) -> String 15 | { 16 | if let path = inBundle.path(forResource: "longNumbers", ofType: "json", inDirectory: "Resources") 17 | { 18 | let data = try! Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe) 19 | let jsonResult = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) 20 | if let jsonResult = jsonResult as? Dictionary 21 | { 22 | if let res = jsonResult[key] 23 | { 24 | return res 25 | } 26 | } 27 | } 28 | return "" 29 | } 30 | 31 | /// Write a datapoint to UserDefaults for the key "key". 32 | static func write(_ value: Any, forKey key: String) 33 | { 34 | UserDefaults.standard.set(value, forKey: key) 35 | UserDefaults.standard.synchronize() 36 | } 37 | 38 | /// Read a datapoint from UserDefaults with the key key. 39 | static func read(forkey key: String) -> Any? 40 | { 41 | return UserDefaults.standard.object(forKey: key) 42 | } 43 | 44 | /// Remove a datapoint from UserDefaults for the key key. 45 | static func remove(forKey key: String) 46 | { 47 | UserDefaults.standard.removeObject(forKey: key) 48 | } 49 | 50 | /// Print all data stored in the UserDefaults. 51 | static func printData() 52 | { 53 | print(UserDefaults.standard.dictionaryRepresentation()) 54 | } 55 | 56 | /// Load the contents of a txt file from a specified directory, like downloadsDirectory. 57 | /// 58 | /// loadFileContent(from: .downloadsDirectory, name: "kittens.txt") 59 | static func loadFileContent(from: FileManager.SearchPathDirectory, name: String) -> String 60 | { 61 | let dir = FileManager.default.urls(for: from, in: .userDomainMask).first! 62 | let path = dir.appendingPathComponent(name) 63 | let text = try? String(contentsOf: path, encoding: String.Encoding.utf8) 64 | return text ?? "" 65 | } 66 | 67 | /// Save the contents of a String to a txt file in a specified directory, like 68 | /// downloadsDirectory. 69 | /// 70 | /// loadFileContent(from: .downloadsDirectory, name: "kittens.txt") 71 | static func saveTxtFile(content: String, to: FileManager.SearchPathDirectory, name: String) 72 | { 73 | do 74 | { 75 | let dir = FileManager.default.urls(for: to, in: .userDomainMask).first! 76 | try content.write( 77 | to: dir.appendingPathComponent(name), 78 | atomically: false, 79 | encoding: String.Encoding.utf8 80 | ) 81 | } 82 | catch 83 | { 84 | print("Couldn't write to \(name) in \(to)") 85 | } 86 | } 87 | 88 | /// Save the contents of a String to a txt file in a specified directory, like 89 | /// downloadsDirectory. 90 | /// 91 | /// loadFileContent(from: .downloadsDirectory, name: "kittens.txt") 92 | static func appendToTxtFile(content: String, to: FileManager.SearchPathDirectory, name: String) 93 | { 94 | let dir = FileManager.default.urls(for: to, in: .userDomainMask).first! 95 | let path = dir.appendingPathComponent(name) 96 | 97 | if FileManager.default.fileExists(atPath: path.path) { 98 | if let fileHandle = try? FileHandle(forUpdating: path) { 99 | fileHandle.seekToEndOfFile() 100 | fileHandle.write(content.data(using: .utf8, allowLossyConversion: false)!) 101 | fileHandle.closeFile() 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Sources/MGTools/MG SuperSwift.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * SuperSwift.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * SuperSwift is a file that aims to improve the swift programming language. It 6 | * adds missing functionality and convenient syntax to make the language more 7 | * versatile. 8 | * ———————————————————————————————————————————————————————————————————————————— 9 | * Created by Marcel Kröker on 18.02.2017. 10 | * Copyright © 2017 Marcel Kröker. All rights reserved. 11 | */ 12 | 13 | import Foundation 14 | 15 | // 16 | //// 17 | ////// 18 | //MARK: - Snippets 19 | ////// 20 | //// 21 | // 22 | 23 | /* 24 | Some snippets are essential to use SuperSwift. It defines some operators that are not 25 | typeable (or too hard to find) on a normal keyboard, thus it is recommended to use snippets 26 | in your IDE or xcode to have easy access to those operators. 27 | */ 28 | 29 | // The cartesian product 30 | // Shortcut: $cp 31 | // Operator: >< 32 | 33 | // The dot product, or scalar product 34 | // Shortcut: $dot 35 | // Operator: • 36 | 37 | // The element operator (same functionality as X.contains(y)) 38 | // Shortcut: $in 39 | // Operator: ∈ 40 | 41 | // The not element operator (same functionality as !X.contains(y)) 42 | // Shortcut: $notin 43 | // Operator: ∉ 44 | 45 | // 46 | //// 47 | ////// 48 | //MARK: - Overview 49 | ////// 50 | //// 51 | // 52 | 53 | /* 54 | This is an overview of all functionality of SuperSwift. 55 | */ 56 | 57 | 58 | 59 | 60 | // 61 | //// 62 | ////// 63 | //MARK: - Extensions 64 | ////// 65 | //// 66 | // 67 | 68 | public extension String 69 | { 70 | /// Returns character at index i as String. 71 | subscript(i: Int) -> String 72 | { 73 | return String(self[index(startIndex, offsetBy: i)]) 74 | } 75 | 76 | /// Returns characters in range as string. 77 | subscript(r: Range) -> String 78 | { 79 | let start = index(startIndex, offsetBy: r.lowerBound) 80 | let end = index(start, offsetBy: r.upperBound - r.lowerBound) 81 | 82 | return String(self[start..) 87 | { 88 | let start = self.index(self.startIndex, offsetBy: bounds.lowerBound) 89 | let end = self.index(self.startIndex, offsetBy: bounds.upperBound) 90 | self.removeSubrange(start...end) 91 | } 92 | 93 | // Make this function work with normal ranges. 94 | mutating func removeSubrange(_ bounds: CountableRange) 95 | { 96 | let start = self.index(self.startIndex, offsetBy: bounds.lowerBound) 97 | let end = self.index(self.startIndex, offsetBy: bounds.upperBound) 98 | self.removeSubrange(start..< : CartesianProductPrecedence 117 | 118 | /** 119 | Calculate the cartesian product of two sequences. With a left precedence you can iterate 120 | over the product: 121 | 122 | // Will print all numbers from 0000 to 9999 123 | for (((i, j), k), l) in 0...9 >< 0...9 >< 0...9 >< 0...9 124 | { 125 | print("\(i)\(j)\(k)\(l)") 126 | } 127 | 128 | 129 | - Parameter lhs: An array. 130 | - Parameter rhs: An array. 131 | - returns: [(l, r)] where l ∈ lhs and r ∈ rhs. 132 | */ 133 | func ><(lhs: [T1], rhs: [T2]) -> [(T1, T2)] 134 | { 135 | var res = [(T1, T2)]() 136 | 137 | for l in lhs 138 | { 139 | for r in rhs 140 | { 141 | res.append((l, r)) 142 | } 143 | } 144 | 145 | return res 146 | } 147 | 148 | func ><(lhs: CountableRange, rhs: CountableRange) -> [(Int, Int)] 149 | { 150 | return lhs.map{$0} >< rhs.map{$0} 151 | } 152 | 153 | func ><(lhs: CountableRange, rhs: CountableClosedRange) -> [(Int, Int)] 154 | { 155 | return lhs.map{$0} >< rhs.map{$0} 156 | } 157 | 158 | func ><(lhs: CountableClosedRange, rhs: CountableRange) -> [(Int, Int)] 159 | { 160 | return lhs.map{$0} >< rhs.map{$0} 161 | } 162 | 163 | func ><(lhs: CountableClosedRange, rhs: CountableClosedRange) -> [(Int, Int)] 164 | { 165 | return lhs.map{$0} >< rhs.map{$0} 166 | } 167 | 168 | func ><(lhs: [T], rhs: CountableRange) -> [(T, Int)] 169 | { 170 | return lhs >< rhs.map{$0} 171 | } 172 | 173 | func ><(lhs: [T], rhs: CountableClosedRange) -> [(T, Int)] 174 | { 175 | return lhs >< rhs.map{$0} 176 | } 177 | 178 | 179 | // Better syntax for contains. Works for sets and arrays 180 | 181 | infix operator ∈ 182 | 183 | func ∈(lhs: T, rhs: Set) -> Bool 184 | { 185 | return rhs.contains(lhs) 186 | } 187 | 188 | func ∈(lhs: T, rhs: Array) -> Bool 189 | { 190 | return rhs.contains(lhs) 191 | } 192 | 193 | infix operator ∉ 194 | 195 | func ∉(lhs: T, rhs: Array) -> Bool 196 | { 197 | return !rhs.contains(lhs) 198 | } 199 | 200 | func ∉(lhs: T, rhs: Set) -> Bool 201 | { 202 | return !rhs.contains(lhs) 203 | } 204 | -------------------------------------------------------------------------------- /Swift-BigInt.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint BigNumber.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "Swift-BigInt" 19 | s.version = "999.99.9" 20 | s.summary = "A lightweight, high performance bignum library for Swift!" 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | s.description = <<-DESC 28 | A lightweight, high performance bignum library for Swift for both intergers and doubles! 29 | DESC 30 | 31 | s.homepage = "https://github.com/mkrd/Swift-BigInt" 32 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 33 | 34 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 35 | # 36 | # Licensing your code is important. See http://choosealicense.com for more info. 37 | # CocoaPods will detect a license file if there is a named LICENSE* 38 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 39 | # 40 | 41 | #s.license = "MIT (example)" 42 | s.license = { :type => "MIT", :file => "LICENSE" } 43 | 44 | 45 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 46 | # 47 | # Specify the authors of the library, with email addresses. Email addresses 48 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 49 | # accepts just a name if you'd rather not provide an email address. 50 | # 51 | # Specify a social_media_url where others can refer to, for example a twitter 52 | # profile URL. 53 | # 54 | 55 | s.author = "mkrd" 56 | # Or just: s.author = "twodayslate" 57 | # s.authors = { "twodayslate" => "zac@gorak.us" } 58 | # s.social_media_url = "http://twitter.com/twodayslate" 59 | 60 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 61 | # 62 | # If this Pod runs only on iOS or OS X, then specify the platform and 63 | # the deployment target. You can optionally include the target after the platform. 64 | # 65 | 66 | # s.platform = :ios 67 | # s.platform = :ios, "5.0" 68 | 69 | # When using multiple platforms 70 | s.ios.deployment_target = "11.0" 71 | s.osx.deployment_target = "10.11" 72 | s.watchos.deployment_target = "4.0" 73 | s.tvos.deployment_target = "11.0" 74 | 75 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 76 | # 77 | # Specify the location from where the source should be retrieved. 78 | # Supports git, hg, bzr, svn and HTTP. 79 | # 80 | 81 | s.source = { :git => "https://github.com/mkrd/Swift-BigInt.git", :tag => "v#{s.version}" } 82 | 83 | 84 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 85 | # 86 | # CocoaPods is smart about how it includes source code. For source files 87 | # giving a folder will include any swift, h, m, mm, c & cpp files. 88 | # For header files it will include any header in the folder. 89 | # Not including the public_header_files will make all headers public. 90 | # 91 | s.source_files = "Sources/BigNumber/*.swift" 92 | 93 | s.module_name = 'BigNumber' 94 | s.swift_version = '4.2' 95 | 96 | #s.source_files = "Classes", "Classes/**/*.{h,m}" 97 | #s.exclude_files = "Classes/Exclude" 98 | 99 | # s.public_header_files = "Classes/**/*.h" 100 | 101 | 102 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 103 | # 104 | # A list of resources included with the Pod. These are copied into the 105 | # target bundle with a build phase script. Anything else will be cleaned. 106 | # You can preserve files from being cleaned, please don't preserve 107 | # non-essential files like tests, examples and documentation. 108 | # 109 | 110 | # s.resource = "icon.png" 111 | # s.resources = "Resources/*.png" 112 | 113 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 114 | 115 | 116 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 117 | # 118 | # Link your library with frameworks, or libraries. Libraries do not include 119 | # the lib prefix of their name. 120 | # 121 | 122 | # s.framework = "SomeFramework" 123 | # s.frameworks = "SomeFramework", "AnotherFramework" 124 | 125 | # s.library = "iconv" 126 | # s.libraries = "iconv", "xml2" 127 | 128 | 129 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 130 | # 131 | # If your library depends on compiler flags you can set them in the xcconfig hash 132 | # where they will only apply to your library. If you depend on other Podspecs 133 | # you can include multiple dependencies to ensure it works. 134 | 135 | # s.requires_arc = true 136 | 137 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 138 | # s.dependency "JSONKit", "~> 1.4" 139 | 140 | s.test_spec "BigNumberTests" do |ts| 141 | ts.platforms = { :ios => "11.0", :osx => "10.11", :tvos => "11.0" } 142 | ts.source_files = "Sources/MGTools/*.swift", "Tests/BigNumberTests/*.swift", "Tests/MGToolsTests/*.swift" 143 | ts.resources = "Tests/BigNumberTests/Resources" 144 | end 145 | 146 | end 147 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcbaselines/F646295B1FF017EA0074A180.xcbaseline/9D27035E-0C66-4C91-8299-009DD28C700B.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | classNames 6 | 7 | BDoubleTests 8 | 9 | testPerformanceStringInit() 10 | 11 | com.apple.XCTPerformanceMetric_WallClockTime 12 | 13 | baselineAverage 14 | 0.52745 15 | baselineIntegrationDisplayName 16 | Local Baseline 17 | 18 | 19 | testPerformanceStringRadixInit() 20 | 21 | com.apple.XCTPerformanceMetric_WallClockTime 22 | 23 | baselineAverage 24 | 0.59005 25 | baselineIntegrationDisplayName 26 | Local Baseline 27 | 28 | 29 | 30 | BIntTests 31 | 32 | testPerformanceStringInit() 33 | 34 | com.apple.XCTPerformanceMetric_WallClockTime 35 | 36 | baselineAverage 37 | 0.28374 38 | baselineIntegrationDisplayName 39 | Local Baseline 40 | 41 | 42 | testPerformanceStringRadixInit() 43 | 44 | com.apple.XCTPerformanceMetric_WallClockTime 45 | 46 | baselineAverage 47 | 0.278 48 | baselineIntegrationDisplayName 49 | Local Baseline 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcbaselines/F646295B1FF017EA0074A180.xcbaseline/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | runDestinationsByUUID 6 | 7 | 9D27035E-0C66-4C91-8299-009DD28C700B 8 | 9 | localComputer 10 | 11 | busSpeedInMHz 12 | 100 13 | cpuCount 14 | 1 15 | cpuKind 16 | Intel Core i7 17 | cpuSpeedInMHz 18 | 2800 19 | logicalCPUCoresPerPackage 20 | 4 21 | modelCode 22 | MacBookPro11,1 23 | physicalCPUCoresPerPackage 24 | 2 25 | platformIdentifier 26 | com.apple.platform.macosx 27 | 28 | targetArchitecture 29 | x86_64 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcschemes/Benchmarks.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 44 | 46 | 52 | 53 | 54 | 55 | 61 | 63 | 69 | 70 | 71 | 72 | 74 | 75 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcschemes/BigNumber-iOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 63 | 69 | 70 | 71 | 72 | 78 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcschemes/BigNumber-macOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 63 | 69 | 70 | 71 | 72 | 78 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Swift-BigNumber.xcodeproj/xcshareddata/xcschemes/MGTools.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 34 | 40 | 41 | 42 | 43 | 44 | 54 | 55 | 61 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Tests/BigNumberTests/BIntTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BInt.swift 3 | // BigNumberTests 4 | // 5 | // Created by Zachary Gorak on 3/2/18. 6 | // Copyright © 2018 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | #if !COCOAPODS 11 | import MGTools 12 | #endif 13 | @testable import BigNumber 14 | 15 | class BIntTests: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | override func tearDown() { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | super.tearDown() 25 | } 26 | 27 | func testRadixInitializerAndGetter() 28 | { 29 | let chars: [Character] = [ 30 | "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", 31 | "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", 32 | "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", 33 | "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" 34 | ] 35 | 36 | // Randomly choose two bases and a number length, as well as a sign (+ or -) 37 | for _ in 0..<100 38 | { 39 | let fromBase = math.random(2...62) 40 | let toBase = math.random(2...62) 41 | let numLength = math.random(1...100) 42 | let sign = math.random(0...1) == 1 ? "-" : "" 43 | 44 | // First digit should not be a 0. 45 | var num = sign + String(chars[math.random(1.. 255.0) 76 | XCTAssert(BInt("f",radix:16)! < 255.0) 77 | XCTAssert(BInt("0",radix:16)! <= 1.0) 78 | XCTAssert(BInt("f", radix: 16)! >= 1.0) 79 | XCTAssert(BInt("rfff",radix:16) == nil) 80 | 81 | XCTAssert(BInt("ffff",radix:16) == 65535) 82 | XCTAssert(BInt("rfff",radix:16) == nil) 83 | XCTAssert(BInt("ff",radix:10) == nil) 84 | XCTAssert(BInt("255",radix:6) == 107) 85 | XCTAssert(BInt("999",radix:10) == 999) 86 | XCTAssert(BInt("ff",radix:16) == 255.0) 87 | XCTAssert(BInt("ff",radix:16) != 100.0) 88 | XCTAssert(BInt("ffff",radix:16)! > 255.0) 89 | XCTAssert(BInt("f",radix:16)! < 255.0) 90 | XCTAssert(BInt("0",radix:16)! <= 1.0) 91 | XCTAssert(BInt("f",radix:16)! >= 1.0) 92 | XCTAssert(BInt("44",radix:5) == 24) 93 | XCTAssert(BInt("44",radix:5) != 100.0) 94 | XCTAssert(BInt("321",radix:5)! == 86) 95 | XCTAssert(BInt("3",radix:5)! < 255.0) 96 | XCTAssert(BInt("0",radix:5)! <= 1.0) 97 | XCTAssert(BInt("4",radix:5)! >= 1.0) 98 | XCTAssert(BInt("923492349",radix:32)! == 9967689075849) 99 | } 100 | 101 | func testIntInit() { 102 | XCTAssert(BInt(UInt64.max) == UInt64.max) 103 | XCTAssert(BInt(Int64.max) == Int64.max) 104 | XCTAssert(BInt(Int64.min) == Int64.min) 105 | XCTAssert(BInt(UInt32.max) == UInt32.max) 106 | XCTAssert(BInt(Int32.max) == Int32.max) 107 | XCTAssert(BInt(Int32.min) == Int32.min) 108 | XCTAssert(BInt(UInt16.max) == UInt16.max) 109 | XCTAssert(BInt(Int16.max) == Int16.max) 110 | XCTAssert(BInt(Int16.min) == Int16.min) 111 | XCTAssert(BInt(UInt64.max) == UInt64.max) 112 | XCTAssert(BInt(Int8.max) == Int8.max) 113 | XCTAssert(BInt(Int8.min) == Int8.min) 114 | XCTAssert(BInt(UInt.max) == UInt.max) 115 | XCTAssert(BInt(Int.max) == Int.max) 116 | XCTAssert(BInt(Int.min) == Int.min) 117 | } 118 | 119 | func testNotEqual() { 120 | XCTAssert(BInt(Int64.max) != Int64.min) 121 | XCTAssert(BInt(Int64.max) != 0) 122 | XCTAssert(BInt(Int64.min) != Int64.max) 123 | XCTAssert(BInt(Int64.min) != 0) 124 | XCTAssert(BInt(Int32.max) != Int32.min) 125 | XCTAssert(BInt(Int32.max) != 0) 126 | XCTAssert(BInt(Int32.min) != Int32.max) 127 | XCTAssert(BInt(Int32.min) != 0) 128 | XCTAssert(BInt(Int16.max) != Int16.min) 129 | XCTAssert(BInt(Int16.max) != 0) 130 | XCTAssert(BInt(Int16.min) != Int16.max) 131 | XCTAssert(BInt(Int16.min) != 0) 132 | XCTAssert(BInt(Int8.max) != Int8.min) 133 | XCTAssert(BInt(Int8.max) != 0) 134 | XCTAssert(BInt(Int8.min) != Int8.max) 135 | XCTAssert(BInt(Int8.min) != 0) 136 | XCTAssert(BInt(Int.max) != Int.min) 137 | XCTAssert(BInt(Int.max) != 0) 138 | XCTAssert(BInt(Int.min) != Int.max) 139 | XCTAssert(BInt(Int.min) != 0) 140 | } 141 | 142 | func testPerformanceStringInit() { 143 | self.measure { 144 | for _ in (0...15000) { 145 | let _ = BInt(String(UInt32.random(in: 0.. 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Tests/BigNumberTests/Resources/longNumbers.json: -------------------------------------------------------------------------------- 1 | { 2 | "gcdTest1": "43875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583753489275632965239465894326503252306527465108761576016654310654156135610860276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694732645626564387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375348927563296523946589432650325230652746510876157601665431065415613561086027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369473264562656", 3 | "gcdTest2": "4387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369474387528053452306543657364752644734658375027660564376576374626234567890987654323456765454829654386452369432087620650236402340623464743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694745624625443875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694743875280534523065436573647526447346583750276605643765763746262345678909876543234567654548296543864523694320876206502364023406234647438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947438752805345230654365736475264473465837502766056437657637462623456789098765432345676545482965438645236947456246254" 4 | } 5 | -------------------------------------------------------------------------------- /Tests/BigNumberTests/Test_Advanced_Math.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_Advanced_Math.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import BigNumber 11 | 12 | class Test_Advanced_Math: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func test_Alternating_Series() 23 | { 24 | var b = BInt(0) 25 | for k in 0...100 26 | { 27 | b += (BInt(-1) ** k) * (BInt(5) ** k) 28 | } 29 | XCTAssert(b.rawValue.limbs == [0x28e3f37dc8c26cc9,0x9f59e568b211b961,0xd92c3dea0eea4010,0xf3d659f514]) 30 | XCTAssert(b.description == "6573840876841765045097738044023218580610053625908525039752324422200521") 31 | 32 | b = BInt(0) 33 | for k in 1...138 34 | { 35 | b += (BInt(k) ** k) - (BInt(137) ** k) 36 | } 37 | XCTAssert(b.rawValue.limbs == [17152098566286916563, 4974948639188066814, 4489317707884913023, 9306023348854241191, 458651883002965321, 3683521711743239055, 16851376351636449383, 741781077320468085, 800339803456222032, 13955889474532705287, 9986965365556055439, 6943506609237153382, 14193507606682829060, 2267111281450088010, 16370502465740827650, 1306853]) 38 | XCTAssert(b.description == "12735701500187047591959419733566858766853126946820718978070969024692885331213304930991162556374421032376469699828008508881075741782571348017377682034125474151722103219051041832160135737768757033144950631943320498343308408527570876037282172430879499586152728823468776739519354613957714873403358163") 39 | } 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Tests/BigNumberTests/Test_BIntMath.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_BIntMath.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | #if !COCOAPODS 11 | @testable import MGTools 12 | #endif 13 | @testable import BigNumber 14 | 15 | class Test_BIntMath: XCTestCase { 16 | 17 | override func setUp() { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | } 20 | 21 | override func tearDown() { 22 | // Put teardown code here. This method is called after the invocation of each test method in the class. 23 | } 24 | 25 | func test_gcd() 26 | { 27 | #if !SWIFT_PACKAGE 28 | for (a, b) in (0...50)><(0...50) 29 | { 30 | let steinGCD = BIntMath.gcd(BInt(a), BInt(b)) 31 | let euclidGCD = BIntMath.gcdEuclid(BInt(a), BInt(b)) 32 | XCTAssert(steinGCD == euclidGCD, "SteinGcd does not work") 33 | } 34 | let g1 = Storage.readResource("gcdTest1", inBundle: Bundle(for: type(of: self))) 35 | let g2 = Storage.readResource("gcdTest2", inBundle: Bundle(for: type(of: self))) 36 | XCTAssert(BIntMath.gcd(BInt(g1)!, BInt(g2)!) == 66) 37 | #endif 38 | 39 | for a in 0..<50 { 40 | for b in 0..<50 { 41 | let steinGCD = BIntMath.gcd(BInt(a), BInt(b)) 42 | let euclidGCD = BIntMath.gcdEuclid(BInt(a), BInt(b)) 43 | XCTAssertEqual(steinGCD, euclidGCD) 44 | } 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Tests/BigNumberTests/Test_Basic_Math.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Test_Basic_Math.swift 3 | // BigNumberTests 4 | // 5 | // Created by Marcel Kröker on 23.08.19. 6 | // Copyright © 2019 Marcel Kröker. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | #if !COCOAPODS 11 | @testable import MGTools 12 | #endif 13 | @testable import BigNumber 14 | 15 | class Test_Basic_Math: XCTestCase { 16 | 17 | override func setUp() { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | } 20 | 21 | override func tearDown() { 22 | // Put teardown code here. This method is called after the invocation of each test method in the class. 23 | } 24 | 25 | 26 | func test_Arithmetric_Operators_BInt() 27 | { 28 | // Ensure that BInt operators behave like swift operators. 29 | let iterations = 1_000 30 | // Get a appropriate maximum number magnitude 31 | let m = Int(sqrt(Double(iterations))) / 10 32 | 33 | let arithmetricInt: [(Int, Int ) -> Int ] = [(+), (-), (*), (/), (%)] 34 | let arithmetricBInt: [(BInt, BInt) -> BInt] = [(+), (-), (*), (/), (%)] 35 | 36 | for (_, i_op) in (0..<(0.. 2 && y == 0) { continue } 40 | let resInt = (arithmetricInt[i_op])(x, y) 41 | let resBInt = (arithmetricBInt[i_op])(BInt(x), BInt(y)) 42 | XCTAssert(resInt.description == resBInt.description) 43 | } 44 | } 45 | 46 | func test_Comparison_Operators_BInt() 47 | { 48 | // Ensure that BInt comparison operators behave like swift operators. 49 | let iterations = 1_000 50 | 51 | // Get a appropriate maximum number magnitude 52 | let m = Int(sqrt(Double(iterations))) / 10 53 | 54 | let compareInt: [(Int, Int) -> Bool] = [(<), (<=), (>), (>=), (==), (!=)] 55 | let compareBInt: [(BInt, BInt) -> Bool] = [(<), (<=), (>), (>=), (==), (!=)] 56 | 57 | for (_, i_op) in (0..<(0.. UInt64] = [(<<), (>>)] 72 | let shiftBInt: [(BInt, Int) -> BInt ] = [(<<), (>>)] 73 | 74 | for (_, i_op) in (0..<(0.. 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Tests/MGToolsTests/MG Math Tests.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * |||||||| MG Math Tests ||||||||||||||||||||||||||||||||||||||| 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 05.09.17. 6 | * Copyright © 2017 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import XCTest 10 | #if !COCOAPODS 11 | @testable import MGTools 12 | #endif 13 | 14 | class MG_Math_Tests: XCTestCase { 15 | func test_primesTo() { 16 | measure { 17 | for i in 2...200 18 | { 19 | let primes = math.primesThrough(i) 20 | 21 | for j in 2...i 22 | { 23 | if math.isPrime(j) 24 | { 25 | precondition(primes.contains(j), "\(j) is prime but not in \(primes), i = \(i)") 26 | } 27 | else 28 | { 29 | precondition(!primes.contains(j), "\(j) is not prime but in \(primes), i = \(i)") 30 | } 31 | } 32 | } 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Tests/MGToolsTests/MG Matrix Tests.swift: -------------------------------------------------------------------------------- 1 | /* 2 | * ———————————————————————————————————————————————————————————————————————————— 3 | * MG Matrix Tests.swift 4 | * ———————————————————————————————————————————————————————————————————————————— 5 | * Created by Marcel Kröker on 26.10.17. 6 | * Copyright © 2017 Marcel Kröker. All rights reserved. 7 | */ 8 | 9 | import XCTest 10 | #if !COCOAPODS 11 | @testable import MGTools 12 | #endif 13 | 14 | public class MG_Matrix_Tests: XCTestCase 15 | { 16 | func testSparseMatrix() 17 | { 18 | // Make a random sparse matrix 19 | 20 | var M = Matrix( 21 | repeating: 0, 22 | rows: math.random(1...500), 23 | cols: math.random(1...500) 24 | ) 25 | 26 | for (i, j) in M 27 | { 28 | if math.random(0.0...1.0) <= 0.01 { M[i, j] = math.random(1...99) } 29 | } 30 | 31 | // Now, convert it to a SparseMatrix 32 | let S = SparseMatrix(M) 33 | 34 | // print("Dimension: \(M.rows)x\(M.cols)") 35 | // print("Sparse kbit: \(S.bitWidth / 1000)") 36 | // print("Normal kbit: \(M.bitWidth / 1000)") 37 | // let ratio = String(format: "%.1f", Double(M.bitWidth) / Double(S.bitWidth)) 38 | // print("Matrix needs \(ratio)x more Memory than SparseMatrix") 39 | 40 | for (i, j) in M 41 | { 42 | precondition(M[i, j] == S[i, j], "Error: A[\(i), \(j)] != S[\(i), \(j)])") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/Extensions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Extensions Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Extensions

134 |

The following extensions are available globally.

135 | 136 |
137 |
138 | 139 |
140 |
141 |
142 |
    143 |
  • 144 |
    145 | 146 | 147 | 148 | Double 149 | 150 |
    151 |
    152 |
    153 |
    154 |
    155 |
    156 | 157 | See more 158 |
    159 |
    160 |

    Declaration

    161 |
    162 |

    Swift

    163 |
    @frozen
    164 | extension Double: NumericType
    165 | 166 |
    167 |
    168 |
    169 |
    170 |
  • 171 |
  • 172 |
    173 | 174 | 175 | 176 | Int 177 | 178 |
    179 |
    180 |
    181 |
    182 |
    183 |
    184 | 185 | See more 186 |
    187 |
    188 |

    Declaration

    189 |
    190 |

    Swift

    191 |
    @frozen
    192 | extension Int: NumericType
    193 | 194 |
    195 |
    196 |
    197 |
    198 |
  • 199 |
200 |
201 |
202 |
203 | 204 |
205 |
206 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /docs/Extensions/Double.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Double Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Double

134 |
135 |
136 |
@frozen
137 | extension Double: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(_:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    init<T>(_ n: T) where T : NumericType
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/Extensions/Int.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Int Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Int

134 |
135 |
136 |
@frozen
137 | extension Int: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(floatLiteral:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    public init(floatLiteral value: Double)
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/Typealiases.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Type Aliases Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Type Aliases

134 |

The following type aliases are available globally.

135 | 136 |
137 |
138 | 139 |
140 |
141 |
142 |
143 | 144 | 145 | 146 |

Typealiases

147 |
148 |
149 |
    150 |
  • 151 |
    152 | 153 | 154 | 155 | Limbs 156 | 157 |
    158 |
    159 |
    160 |
    161 |
    162 |
    163 |

    Undocumented

    164 | 165 |
    166 |
    167 |

    Declaration

    168 |
    169 |

    Swift

    170 |
    public typealias Limbs = [UInt64]
    171 | 172 |
    173 |
    174 |
    175 | Show on GitHub 176 |
    177 |
    178 |
    179 |
  • 180 |
  • 181 |
    182 | 183 | 184 | 185 | Limb 186 | 187 |
    188 |
    189 |
    190 |
    191 |
    192 |
    193 |

    Undocumented

    194 | 195 |
    196 |
    197 |

    Declaration

    198 |
    199 |

    Swift

    200 |
    public typealias Limb = UInt64
    201 | 202 |
    203 |
    204 |
    205 | Show on GitHub 206 |
    207 |
    208 |
    209 |
  • 210 |
  • 211 |
    212 | 213 | 214 | 215 | Digits 216 | 217 |
    218 |
    219 |
    220 |
    221 |
    222 |
    223 |

    Undocumented

    224 | 225 |
    226 |
    227 |

    Declaration

    228 |
    229 |

    Swift

    230 |
    public typealias Digits = [UInt64]
    231 | 232 |
    233 |
    234 |
    235 | Show on GitHub 236 |
    237 |
    238 |
    239 |
  • 240 |
  • 241 |
    242 | 243 | 244 | 245 | Digit 246 | 247 |
    248 |
    249 |
    250 |
    251 |
    252 |
    253 |

    Undocumented

    254 | 255 |
    256 |
    257 |

    Declaration

    258 |
    259 |

    Swift

    260 |
    public typealias Digit = UInt64
    261 | 262 |
    263 |
    264 |
    265 | Show on GitHub 266 |
    267 |
    268 |
    269 |
  • 270 |
271 |
272 |
273 |
274 | 275 |
276 |
277 | 281 | 282 | 283 | 284 | -------------------------------------------------------------------------------- /docs/css/highlight.css: -------------------------------------------------------------------------------- 1 | /* Credit to https://gist.github.com/wataru420/2048287 */ 2 | .highlight { 3 | /* Comment */ 4 | /* Error */ 5 | /* Keyword */ 6 | /* Operator */ 7 | /* Comment.Multiline */ 8 | /* Comment.Preproc */ 9 | /* Comment.Single */ 10 | /* Comment.Special */ 11 | /* Generic.Deleted */ 12 | /* Generic.Deleted.Specific */ 13 | /* Generic.Emph */ 14 | /* Generic.Error */ 15 | /* Generic.Heading */ 16 | /* Generic.Inserted */ 17 | /* Generic.Inserted.Specific */ 18 | /* Generic.Output */ 19 | /* Generic.Prompt */ 20 | /* Generic.Strong */ 21 | /* Generic.Subheading */ 22 | /* Generic.Traceback */ 23 | /* Keyword.Constant */ 24 | /* Keyword.Declaration */ 25 | /* Keyword.Pseudo */ 26 | /* Keyword.Reserved */ 27 | /* Keyword.Type */ 28 | /* Literal.Number */ 29 | /* Literal.String */ 30 | /* Name.Attribute */ 31 | /* Name.Builtin */ 32 | /* Name.Class */ 33 | /* Name.Constant */ 34 | /* Name.Entity */ 35 | /* Name.Exception */ 36 | /* Name.Function */ 37 | /* Name.Namespace */ 38 | /* Name.Tag */ 39 | /* Name.Variable */ 40 | /* Operator.Word */ 41 | /* Text.Whitespace */ 42 | /* Literal.Number.Float */ 43 | /* Literal.Number.Hex */ 44 | /* Literal.Number.Integer */ 45 | /* Literal.Number.Oct */ 46 | /* Literal.String.Backtick */ 47 | /* Literal.String.Char */ 48 | /* Literal.String.Doc */ 49 | /* Literal.String.Double */ 50 | /* Literal.String.Escape */ 51 | /* Literal.String.Heredoc */ 52 | /* Literal.String.Interpol */ 53 | /* Literal.String.Other */ 54 | /* Literal.String.Regex */ 55 | /* Literal.String.Single */ 56 | /* Literal.String.Symbol */ 57 | /* Name.Builtin.Pseudo */ 58 | /* Name.Variable.Class */ 59 | /* Name.Variable.Global */ 60 | /* Name.Variable.Instance */ 61 | /* Literal.Number.Integer.Long */ } 62 | .highlight .c { 63 | color: #999988; 64 | font-style: italic; } 65 | .highlight .err { 66 | color: #a61717; 67 | background-color: #e3d2d2; } 68 | .highlight .k { 69 | color: #000000; 70 | font-weight: bold; } 71 | .highlight .o { 72 | color: #000000; 73 | font-weight: bold; } 74 | .highlight .cm { 75 | color: #999988; 76 | font-style: italic; } 77 | .highlight .cp { 78 | color: #999999; 79 | font-weight: bold; } 80 | .highlight .c1 { 81 | color: #999988; 82 | font-style: italic; } 83 | .highlight .cs { 84 | color: #999999; 85 | font-weight: bold; 86 | font-style: italic; } 87 | .highlight .gd { 88 | color: #000000; 89 | background-color: #ffdddd; } 90 | .highlight .gd .x { 91 | color: #000000; 92 | background-color: #ffaaaa; } 93 | .highlight .ge { 94 | color: #000000; 95 | font-style: italic; } 96 | .highlight .gr { 97 | color: #aa0000; } 98 | .highlight .gh { 99 | color: #999999; } 100 | .highlight .gi { 101 | color: #000000; 102 | background-color: #ddffdd; } 103 | .highlight .gi .x { 104 | color: #000000; 105 | background-color: #aaffaa; } 106 | .highlight .go { 107 | color: #888888; } 108 | .highlight .gp { 109 | color: #555555; } 110 | .highlight .gs { 111 | font-weight: bold; } 112 | .highlight .gu { 113 | color: #aaaaaa; } 114 | .highlight .gt { 115 | color: #aa0000; } 116 | .highlight .kc { 117 | color: #000000; 118 | font-weight: bold; } 119 | .highlight .kd { 120 | color: #000000; 121 | font-weight: bold; } 122 | .highlight .kp { 123 | color: #000000; 124 | font-weight: bold; } 125 | .highlight .kr { 126 | color: #000000; 127 | font-weight: bold; } 128 | .highlight .kt { 129 | color: #445588; } 130 | .highlight .m { 131 | color: #009999; } 132 | .highlight .s { 133 | color: #d14; } 134 | .highlight .na { 135 | color: #008080; } 136 | .highlight .nb { 137 | color: #0086B3; } 138 | .highlight .nc { 139 | color: #445588; 140 | font-weight: bold; } 141 | .highlight .no { 142 | color: #008080; } 143 | .highlight .ni { 144 | color: #800080; } 145 | .highlight .ne { 146 | color: #990000; 147 | font-weight: bold; } 148 | .highlight .nf { 149 | color: #990000; } 150 | .highlight .nn { 151 | color: #555555; } 152 | .highlight .nt { 153 | color: #000080; } 154 | .highlight .nv { 155 | color: #008080; } 156 | .highlight .ow { 157 | color: #000000; 158 | font-weight: bold; } 159 | .highlight .w { 160 | color: #bbbbbb; } 161 | .highlight .mf { 162 | color: #009999; } 163 | .highlight .mh { 164 | color: #009999; } 165 | .highlight .mi { 166 | color: #009999; } 167 | .highlight .mo { 168 | color: #009999; } 169 | .highlight .sb { 170 | color: #d14; } 171 | .highlight .sc { 172 | color: #d14; } 173 | .highlight .sd { 174 | color: #d14; } 175 | .highlight .s2 { 176 | color: #d14; } 177 | .highlight .se { 178 | color: #d14; } 179 | .highlight .sh { 180 | color: #d14; } 181 | .highlight .si { 182 | color: #d14; } 183 | .highlight .sx { 184 | color: #d14; } 185 | .highlight .sr { 186 | color: #009926; } 187 | .highlight .s1 { 188 | color: #d14; } 189 | .highlight .ss { 190 | color: #990073; } 191 | .highlight .bp { 192 | color: #999999; } 193 | .highlight .vc { 194 | color: #008080; } 195 | .highlight .vg { 196 | color: #008080; } 197 | .highlight .vi { 198 | color: #008080; } 199 | .highlight .il { 200 | color: #009999; } 201 | -------------------------------------------------------------------------------- /docs/css/jazzy.css: -------------------------------------------------------------------------------- 1 | *, *:before, *:after { 2 | box-sizing: inherit; } 3 | 4 | body { 5 | margin: 0; 6 | background: #fff; 7 | color: #333; 8 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 9 | letter-spacing: .2px; 10 | -webkit-font-smoothing: antialiased; 11 | box-sizing: border-box; } 12 | 13 | h1 { 14 | font-size: 2rem; 15 | font-weight: 700; 16 | margin: 1.275em 0 0.6em; } 17 | 18 | h2 { 19 | font-size: 1.75rem; 20 | font-weight: 700; 21 | margin: 1.275em 0 0.3em; } 22 | 23 | h3 { 24 | font-size: 1.5rem; 25 | font-weight: 700; 26 | margin: 1em 0 0.3em; } 27 | 28 | h4 { 29 | font-size: 1.25rem; 30 | font-weight: 700; 31 | margin: 1.275em 0 0.85em; } 32 | 33 | h5 { 34 | font-size: 1rem; 35 | font-weight: 700; 36 | margin: 1.275em 0 0.85em; } 37 | 38 | h6 { 39 | font-size: 1rem; 40 | font-weight: 700; 41 | margin: 1.275em 0 0.85em; 42 | color: #777; } 43 | 44 | p { 45 | margin: 0 0 1em; } 46 | 47 | ul, ol { 48 | padding: 0 0 0 2em; 49 | margin: 0 0 0.85em; } 50 | 51 | blockquote { 52 | margin: 0 0 0.85em; 53 | padding: 0 15px; 54 | color: #858585; 55 | border-left: 4px solid #e5e5e5; } 56 | 57 | img { 58 | max-width: 100%; } 59 | 60 | a { 61 | color: #4183c4; 62 | text-decoration: none; } 63 | a:hover, a:focus { 64 | outline: 0; 65 | text-decoration: underline; } 66 | a.discouraged { 67 | text-decoration: line-through; } 68 | a.discouraged:hover, a.discouraged:focus { 69 | text-decoration: underline line-through; } 70 | 71 | table { 72 | background: #fff; 73 | width: 100%; 74 | border-collapse: collapse; 75 | border-spacing: 0; 76 | overflow: auto; 77 | margin: 0 0 0.85em; } 78 | 79 | tr:nth-child(2n) { 80 | background-color: #fbfbfb; } 81 | 82 | th, td { 83 | padding: 6px 13px; 84 | border: 1px solid #ddd; } 85 | 86 | pre { 87 | margin: 0 0 1.275em; 88 | padding: .85em 1em; 89 | overflow: auto; 90 | background: #f7f7f7; 91 | font-size: .85em; 92 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 93 | 94 | code { 95 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 96 | 97 | p > code, li > code { 98 | background: #f7f7f7; 99 | padding: .2em; } 100 | p > code:before, p > code:after, li > code:before, li > code:after { 101 | letter-spacing: -.2em; 102 | content: "\00a0"; } 103 | 104 | pre code { 105 | padding: 0; 106 | white-space: pre; } 107 | 108 | .content-wrapper { 109 | display: flex; 110 | flex-direction: column; } 111 | @media (min-width: 768px) { 112 | .content-wrapper { 113 | flex-direction: row; } } 114 | 115 | .header { 116 | display: flex; 117 | padding: 8px; 118 | font-size: 0.875em; 119 | background: #444; 120 | color: #999; } 121 | 122 | .header-col { 123 | margin: 0; 124 | padding: 0 8px; } 125 | 126 | .header-col--primary { 127 | flex: 1; } 128 | 129 | .header-link { 130 | color: #fff; } 131 | 132 | .header-icon { 133 | padding-right: 6px; 134 | vertical-align: -4px; 135 | height: 16px; } 136 | 137 | .breadcrumbs { 138 | font-size: 0.875em; 139 | padding: 8px 16px; 140 | margin: 0; 141 | background: #fbfbfb; 142 | border-bottom: 1px solid #ddd; } 143 | 144 | .carat { 145 | height: 10px; 146 | margin: 0 5px; } 147 | 148 | .navigation { 149 | order: 2; } 150 | @media (min-width: 768px) { 151 | .navigation { 152 | order: 1; 153 | width: 25%; 154 | max-width: 300px; 155 | padding-bottom: 64px; 156 | overflow: hidden; 157 | word-wrap: normal; 158 | background: #fbfbfb; 159 | border-right: 1px solid #ddd; } } 160 | 161 | .nav-groups { 162 | list-style-type: none; 163 | padding-left: 0; } 164 | 165 | .nav-group-name { 166 | border-bottom: 1px solid #ddd; 167 | padding: 8px 0 8px 16px; } 168 | 169 | .nav-group-name-link { 170 | color: #333; } 171 | 172 | .nav-group-tasks { 173 | margin: 8px 0; 174 | padding: 0 0 0 8px; } 175 | 176 | .nav-group-task { 177 | font-size: 1em; 178 | list-style-type: none; 179 | white-space: nowrap; } 180 | 181 | .nav-group-task-link { 182 | color: #808080; } 183 | 184 | .main-content { 185 | order: 1; } 186 | @media (min-width: 768px) { 187 | .main-content { 188 | order: 2; 189 | flex: 1; 190 | padding-bottom: 60px; } } 191 | 192 | .section { 193 | padding: 0 32px; 194 | border-bottom: 1px solid #ddd; } 195 | 196 | .section-content { 197 | max-width: 834px; 198 | margin: 0 auto; 199 | padding: 16px 0; } 200 | 201 | .section-name { 202 | color: #666; 203 | display: block; } 204 | 205 | .declaration .highlight { 206 | overflow-x: initial; 207 | padding: 8px 0; 208 | margin: 0; 209 | background-color: transparent; 210 | border: none; } 211 | 212 | .task-group-section { 213 | border-top: 1px solid #ddd; } 214 | 215 | .task-group { 216 | padding-top: 0px; } 217 | 218 | .task-name-container a[name]:before { 219 | content: ""; 220 | display: block; } 221 | 222 | .item-container { 223 | padding: 0; } 224 | 225 | .item { 226 | padding-top: 8px; 227 | width: 100%; 228 | list-style-type: none; } 229 | .item a[name]:before { 230 | content: ""; 231 | display: block; } 232 | .item .token, .item .direct-link { 233 | padding-left: 3px; 234 | margin-left: 0px; 235 | font-size: 1rem; } 236 | .item .declaration-note { 237 | font-size: .85em; 238 | color: #808080; 239 | font-style: italic; } 240 | 241 | .pointer-container { 242 | border-bottom: 1px solid #ddd; 243 | left: -23px; 244 | padding-bottom: 13px; 245 | position: relative; 246 | width: 110%; } 247 | 248 | .pointer { 249 | left: 21px; 250 | top: 7px; 251 | display: block; 252 | position: absolute; 253 | width: 12px; 254 | height: 12px; 255 | border-left: 1px solid #ddd; 256 | border-top: 1px solid #ddd; 257 | background: #fff; 258 | transform: rotate(45deg); } 259 | 260 | .height-container { 261 | display: none; 262 | position: relative; 263 | width: 100%; 264 | overflow: hidden; } 265 | .height-container .section { 266 | background: #fff; 267 | border: 1px solid #ddd; 268 | border-top-width: 0; 269 | padding-top: 10px; 270 | padding-bottom: 5px; 271 | padding: 8px 16px; } 272 | 273 | .aside, .language { 274 | padding: 6px 12px; 275 | margin: 12px 0; 276 | border-left: 5px solid #dddddd; 277 | overflow-y: hidden; } 278 | .aside .aside-title, .language .aside-title { 279 | font-size: 9px; 280 | letter-spacing: 2px; 281 | text-transform: uppercase; 282 | padding-bottom: 0; 283 | margin: 0; 284 | color: #aaa; 285 | -webkit-user-select: none; } 286 | .aside p:last-child, .language p:last-child { 287 | margin-bottom: 0; } 288 | 289 | .language { 290 | border-left: 5px solid #cde9f4; } 291 | .language .aside-title { 292 | color: #4183c4; } 293 | 294 | .aside-warning, .aside-deprecated, .aside-unavailable { 295 | border-left: 5px solid #ff6666; } 296 | .aside-warning .aside-title, .aside-deprecated .aside-title, .aside-unavailable .aside-title { 297 | color: #ff0000; } 298 | 299 | .graybox { 300 | border-collapse: collapse; 301 | width: 100%; } 302 | .graybox p { 303 | margin: 0; 304 | word-break: break-word; 305 | min-width: 50px; } 306 | .graybox td { 307 | border: 1px solid #ddd; 308 | padding: 5px 25px 5px 10px; 309 | vertical-align: middle; } 310 | .graybox tr td:first-of-type { 311 | text-align: right; 312 | padding: 7px; 313 | vertical-align: top; 314 | word-break: normal; 315 | width: 40px; } 316 | 317 | .slightly-smaller { 318 | font-size: 0.9em; } 319 | 320 | .footer { 321 | padding: 8px 16px; 322 | background: #444; 323 | color: #ddd; 324 | font-size: 0.8em; } 325 | .footer p { 326 | margin: 8px 0; } 327 | .footer a { 328 | color: #fff; } 329 | 330 | html.dash .header, html.dash .breadcrumbs, html.dash .navigation { 331 | display: none; } 332 | 333 | html.dash .height-container { 334 | display: block; } 335 | 336 | form[role=search] input { 337 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 338 | font-size: 14px; 339 | line-height: 24px; 340 | padding: 0 10px; 341 | margin: 0; 342 | border: none; 343 | border-radius: 1em; } 344 | .loading form[role=search] input { 345 | background: white url(../img/spinner.gif) center right 4px no-repeat; } 346 | 347 | form[role=search] .tt-menu { 348 | margin: 0; 349 | min-width: 300px; 350 | background: #fbfbfb; 351 | color: #333; 352 | border: 1px solid #ddd; } 353 | 354 | form[role=search] .tt-highlight { 355 | font-weight: bold; } 356 | 357 | form[role=search] .tt-suggestion { 358 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 359 | padding: 0 8px; } 360 | form[role=search] .tt-suggestion span { 361 | display: table-cell; 362 | white-space: nowrap; } 363 | form[role=search] .tt-suggestion .doc-parent-name { 364 | width: 100%; 365 | text-align: right; 366 | font-weight: normal; 367 | font-size: 0.9em; 368 | padding-left: 16px; } 369 | 370 | form[role=search] .tt-suggestion:hover, 371 | form[role=search] .tt-suggestion.tt-cursor { 372 | cursor: pointer; 373 | background-color: #4183c4; 374 | color: #fff; } 375 | 376 | form[role=search] .tt-suggestion:hover .doc-parent-name, 377 | form[role=search] .tt-suggestion.tt-cursor .doc-parent-name { 378 | color: #fff; } 379 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | com.jazzy.bignumber 7 | CFBundleName 8 | BigNumber 9 | DocSetPlatformFamily 10 | bignumber 11 | isDashDocset 12 | 13 | dashIndexFilePath 14 | index.html 15 | isJavaScriptEnabled 16 | 17 | DashDocSetFamily 18 | dashtoc 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/Extensions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Extensions Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Extensions

134 |

The following extensions are available globally.

135 | 136 |
137 |
138 | 139 |
140 |
141 |
142 |
    143 |
  • 144 |
    145 | 146 | 147 | 148 | Double 149 | 150 |
    151 |
    152 |
    153 |
    154 |
    155 |
    156 | 157 | See more 158 |
    159 |
    160 |

    Declaration

    161 |
    162 |

    Swift

    163 |
    @frozen
    164 | extension Double: NumericType
    165 | 166 |
    167 |
    168 |
    169 |
    170 |
  • 171 |
  • 172 |
    173 | 174 | 175 | 176 | Int 177 | 178 |
    179 |
    180 |
    181 |
    182 |
    183 |
    184 | 185 | See more 186 |
    187 |
    188 |

    Declaration

    189 |
    190 |

    Swift

    191 |
    @frozen
    192 | extension Int: NumericType
    193 | 194 |
    195 |
    196 |
    197 |
    198 |
  • 199 |
200 |
201 |
202 |
203 | 204 |
205 |
206 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/Extensions/Double.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Double Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Double

134 |
135 |
136 |
@frozen
137 | extension Double: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(_:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    init<T>(_ n: T) where T : NumericType
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/Extensions/Int.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Int Extension Reference 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |

23 | 24 | BigNumber 2.1.1 Docs 25 | 26 | 27 |

28 | 29 |

30 |

31 | 32 |
33 |

34 | 35 |

36 | 37 | 38 | View on GitHub 39 | 40 |

41 | 42 |

43 | 44 | 45 | Install in Dash 46 | 47 |

48 |
49 | 50 | 55 | 56 |
57 | 129 |
130 | 131 |
132 |
133 |

Int

134 |
135 |
136 |
@frozen
137 | extension Int: NumericType
138 | 139 |
140 |
141 | 142 |
143 |
144 | 145 |
146 |
147 |
148 |
    149 |
  • 150 |
    151 | 152 | 153 | 154 | init(floatLiteral:) 155 | 156 |
    157 |
    158 |
    159 |
    160 |
    161 |
    162 |

    Undocumented

    163 | 164 |
    165 |
    166 |

    Declaration

    167 |
    168 |

    Swift

    169 |
    public init(floatLiteral value: Double)
    170 | 171 |
    172 |
    173 |
    174 | Show on GitHub 175 |
    176 |
    177 |
    178 |
  • 179 |
180 |
181 |
182 |
183 | 184 |
185 |
186 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/css/highlight.css: -------------------------------------------------------------------------------- 1 | /* Credit to https://gist.github.com/wataru420/2048287 */ 2 | .highlight { 3 | /* Comment */ 4 | /* Error */ 5 | /* Keyword */ 6 | /* Operator */ 7 | /* Comment.Multiline */ 8 | /* Comment.Preproc */ 9 | /* Comment.Single */ 10 | /* Comment.Special */ 11 | /* Generic.Deleted */ 12 | /* Generic.Deleted.Specific */ 13 | /* Generic.Emph */ 14 | /* Generic.Error */ 15 | /* Generic.Heading */ 16 | /* Generic.Inserted */ 17 | /* Generic.Inserted.Specific */ 18 | /* Generic.Output */ 19 | /* Generic.Prompt */ 20 | /* Generic.Strong */ 21 | /* Generic.Subheading */ 22 | /* Generic.Traceback */ 23 | /* Keyword.Constant */ 24 | /* Keyword.Declaration */ 25 | /* Keyword.Pseudo */ 26 | /* Keyword.Reserved */ 27 | /* Keyword.Type */ 28 | /* Literal.Number */ 29 | /* Literal.String */ 30 | /* Name.Attribute */ 31 | /* Name.Builtin */ 32 | /* Name.Class */ 33 | /* Name.Constant */ 34 | /* Name.Entity */ 35 | /* Name.Exception */ 36 | /* Name.Function */ 37 | /* Name.Namespace */ 38 | /* Name.Tag */ 39 | /* Name.Variable */ 40 | /* Operator.Word */ 41 | /* Text.Whitespace */ 42 | /* Literal.Number.Float */ 43 | /* Literal.Number.Hex */ 44 | /* Literal.Number.Integer */ 45 | /* Literal.Number.Oct */ 46 | /* Literal.String.Backtick */ 47 | /* Literal.String.Char */ 48 | /* Literal.String.Doc */ 49 | /* Literal.String.Double */ 50 | /* Literal.String.Escape */ 51 | /* Literal.String.Heredoc */ 52 | /* Literal.String.Interpol */ 53 | /* Literal.String.Other */ 54 | /* Literal.String.Regex */ 55 | /* Literal.String.Single */ 56 | /* Literal.String.Symbol */ 57 | /* Name.Builtin.Pseudo */ 58 | /* Name.Variable.Class */ 59 | /* Name.Variable.Global */ 60 | /* Name.Variable.Instance */ 61 | /* Literal.Number.Integer.Long */ } 62 | .highlight .c { 63 | color: #999988; 64 | font-style: italic; } 65 | .highlight .err { 66 | color: #a61717; 67 | background-color: #e3d2d2; } 68 | .highlight .k { 69 | color: #000000; 70 | font-weight: bold; } 71 | .highlight .o { 72 | color: #000000; 73 | font-weight: bold; } 74 | .highlight .cm { 75 | color: #999988; 76 | font-style: italic; } 77 | .highlight .cp { 78 | color: #999999; 79 | font-weight: bold; } 80 | .highlight .c1 { 81 | color: #999988; 82 | font-style: italic; } 83 | .highlight .cs { 84 | color: #999999; 85 | font-weight: bold; 86 | font-style: italic; } 87 | .highlight .gd { 88 | color: #000000; 89 | background-color: #ffdddd; } 90 | .highlight .gd .x { 91 | color: #000000; 92 | background-color: #ffaaaa; } 93 | .highlight .ge { 94 | color: #000000; 95 | font-style: italic; } 96 | .highlight .gr { 97 | color: #aa0000; } 98 | .highlight .gh { 99 | color: #999999; } 100 | .highlight .gi { 101 | color: #000000; 102 | background-color: #ddffdd; } 103 | .highlight .gi .x { 104 | color: #000000; 105 | background-color: #aaffaa; } 106 | .highlight .go { 107 | color: #888888; } 108 | .highlight .gp { 109 | color: #555555; } 110 | .highlight .gs { 111 | font-weight: bold; } 112 | .highlight .gu { 113 | color: #aaaaaa; } 114 | .highlight .gt { 115 | color: #aa0000; } 116 | .highlight .kc { 117 | color: #000000; 118 | font-weight: bold; } 119 | .highlight .kd { 120 | color: #000000; 121 | font-weight: bold; } 122 | .highlight .kp { 123 | color: #000000; 124 | font-weight: bold; } 125 | .highlight .kr { 126 | color: #000000; 127 | font-weight: bold; } 128 | .highlight .kt { 129 | color: #445588; } 130 | .highlight .m { 131 | color: #009999; } 132 | .highlight .s { 133 | color: #d14; } 134 | .highlight .na { 135 | color: #008080; } 136 | .highlight .nb { 137 | color: #0086B3; } 138 | .highlight .nc { 139 | color: #445588; 140 | font-weight: bold; } 141 | .highlight .no { 142 | color: #008080; } 143 | .highlight .ni { 144 | color: #800080; } 145 | .highlight .ne { 146 | color: #990000; 147 | font-weight: bold; } 148 | .highlight .nf { 149 | color: #990000; } 150 | .highlight .nn { 151 | color: #555555; } 152 | .highlight .nt { 153 | color: #000080; } 154 | .highlight .nv { 155 | color: #008080; } 156 | .highlight .ow { 157 | color: #000000; 158 | font-weight: bold; } 159 | .highlight .w { 160 | color: #bbbbbb; } 161 | .highlight .mf { 162 | color: #009999; } 163 | .highlight .mh { 164 | color: #009999; } 165 | .highlight .mi { 166 | color: #009999; } 167 | .highlight .mo { 168 | color: #009999; } 169 | .highlight .sb { 170 | color: #d14; } 171 | .highlight .sc { 172 | color: #d14; } 173 | .highlight .sd { 174 | color: #d14; } 175 | .highlight .s2 { 176 | color: #d14; } 177 | .highlight .se { 178 | color: #d14; } 179 | .highlight .sh { 180 | color: #d14; } 181 | .highlight .si { 182 | color: #d14; } 183 | .highlight .sx { 184 | color: #d14; } 185 | .highlight .sr { 186 | color: #009926; } 187 | .highlight .s1 { 188 | color: #d14; } 189 | .highlight .ss { 190 | color: #990073; } 191 | .highlight .bp { 192 | color: #999999; } 193 | .highlight .vc { 194 | color: #008080; } 195 | .highlight .vg { 196 | color: #008080; } 197 | .highlight .vi { 198 | color: #008080; } 199 | .highlight .il { 200 | color: #009999; } 201 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/css/jazzy.css: -------------------------------------------------------------------------------- 1 | *, *:before, *:after { 2 | box-sizing: inherit; } 3 | 4 | body { 5 | margin: 0; 6 | background: #fff; 7 | color: #333; 8 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 9 | letter-spacing: .2px; 10 | -webkit-font-smoothing: antialiased; 11 | box-sizing: border-box; } 12 | 13 | h1 { 14 | font-size: 2rem; 15 | font-weight: 700; 16 | margin: 1.275em 0 0.6em; } 17 | 18 | h2 { 19 | font-size: 1.75rem; 20 | font-weight: 700; 21 | margin: 1.275em 0 0.3em; } 22 | 23 | h3 { 24 | font-size: 1.5rem; 25 | font-weight: 700; 26 | margin: 1em 0 0.3em; } 27 | 28 | h4 { 29 | font-size: 1.25rem; 30 | font-weight: 700; 31 | margin: 1.275em 0 0.85em; } 32 | 33 | h5 { 34 | font-size: 1rem; 35 | font-weight: 700; 36 | margin: 1.275em 0 0.85em; } 37 | 38 | h6 { 39 | font-size: 1rem; 40 | font-weight: 700; 41 | margin: 1.275em 0 0.85em; 42 | color: #777; } 43 | 44 | p { 45 | margin: 0 0 1em; } 46 | 47 | ul, ol { 48 | padding: 0 0 0 2em; 49 | margin: 0 0 0.85em; } 50 | 51 | blockquote { 52 | margin: 0 0 0.85em; 53 | padding: 0 15px; 54 | color: #858585; 55 | border-left: 4px solid #e5e5e5; } 56 | 57 | img { 58 | max-width: 100%; } 59 | 60 | a { 61 | color: #4183c4; 62 | text-decoration: none; } 63 | a:hover, a:focus { 64 | outline: 0; 65 | text-decoration: underline; } 66 | a.discouraged { 67 | text-decoration: line-through; } 68 | a.discouraged:hover, a.discouraged:focus { 69 | text-decoration: underline line-through; } 70 | 71 | table { 72 | background: #fff; 73 | width: 100%; 74 | border-collapse: collapse; 75 | border-spacing: 0; 76 | overflow: auto; 77 | margin: 0 0 0.85em; } 78 | 79 | tr:nth-child(2n) { 80 | background-color: #fbfbfb; } 81 | 82 | th, td { 83 | padding: 6px 13px; 84 | border: 1px solid #ddd; } 85 | 86 | pre { 87 | margin: 0 0 1.275em; 88 | padding: .85em 1em; 89 | overflow: auto; 90 | background: #f7f7f7; 91 | font-size: .85em; 92 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 93 | 94 | code { 95 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; } 96 | 97 | p > code, li > code { 98 | background: #f7f7f7; 99 | padding: .2em; } 100 | p > code:before, p > code:after, li > code:before, li > code:after { 101 | letter-spacing: -.2em; 102 | content: "\00a0"; } 103 | 104 | pre code { 105 | padding: 0; 106 | white-space: pre; } 107 | 108 | .content-wrapper { 109 | display: flex; 110 | flex-direction: column; } 111 | @media (min-width: 768px) { 112 | .content-wrapper { 113 | flex-direction: row; } } 114 | 115 | .header { 116 | display: flex; 117 | padding: 8px; 118 | font-size: 0.875em; 119 | background: #444; 120 | color: #999; } 121 | 122 | .header-col { 123 | margin: 0; 124 | padding: 0 8px; } 125 | 126 | .header-col--primary { 127 | flex: 1; } 128 | 129 | .header-link { 130 | color: #fff; } 131 | 132 | .header-icon { 133 | padding-right: 6px; 134 | vertical-align: -4px; 135 | height: 16px; } 136 | 137 | .breadcrumbs { 138 | font-size: 0.875em; 139 | padding: 8px 16px; 140 | margin: 0; 141 | background: #fbfbfb; 142 | border-bottom: 1px solid #ddd; } 143 | 144 | .carat { 145 | height: 10px; 146 | margin: 0 5px; } 147 | 148 | .navigation { 149 | order: 2; } 150 | @media (min-width: 768px) { 151 | .navigation { 152 | order: 1; 153 | width: 25%; 154 | max-width: 300px; 155 | padding-bottom: 64px; 156 | overflow: hidden; 157 | word-wrap: normal; 158 | background: #fbfbfb; 159 | border-right: 1px solid #ddd; } } 160 | 161 | .nav-groups { 162 | list-style-type: none; 163 | padding-left: 0; } 164 | 165 | .nav-group-name { 166 | border-bottom: 1px solid #ddd; 167 | padding: 8px 0 8px 16px; } 168 | 169 | .nav-group-name-link { 170 | color: #333; } 171 | 172 | .nav-group-tasks { 173 | margin: 8px 0; 174 | padding: 0 0 0 8px; } 175 | 176 | .nav-group-task { 177 | font-size: 1em; 178 | list-style-type: none; 179 | white-space: nowrap; } 180 | 181 | .nav-group-task-link { 182 | color: #808080; } 183 | 184 | .main-content { 185 | order: 1; } 186 | @media (min-width: 768px) { 187 | .main-content { 188 | order: 2; 189 | flex: 1; 190 | padding-bottom: 60px; } } 191 | 192 | .section { 193 | padding: 0 32px; 194 | border-bottom: 1px solid #ddd; } 195 | 196 | .section-content { 197 | max-width: 834px; 198 | margin: 0 auto; 199 | padding: 16px 0; } 200 | 201 | .section-name { 202 | color: #666; 203 | display: block; } 204 | 205 | .declaration .highlight { 206 | overflow-x: initial; 207 | padding: 8px 0; 208 | margin: 0; 209 | background-color: transparent; 210 | border: none; } 211 | 212 | .task-group-section { 213 | border-top: 1px solid #ddd; } 214 | 215 | .task-group { 216 | padding-top: 0px; } 217 | 218 | .task-name-container a[name]:before { 219 | content: ""; 220 | display: block; } 221 | 222 | .item-container { 223 | padding: 0; } 224 | 225 | .item { 226 | padding-top: 8px; 227 | width: 100%; 228 | list-style-type: none; } 229 | .item a[name]:before { 230 | content: ""; 231 | display: block; } 232 | .item .token, .item .direct-link { 233 | padding-left: 3px; 234 | margin-left: 0px; 235 | font-size: 1rem; } 236 | .item .declaration-note { 237 | font-size: .85em; 238 | color: #808080; 239 | font-style: italic; } 240 | 241 | .pointer-container { 242 | border-bottom: 1px solid #ddd; 243 | left: -23px; 244 | padding-bottom: 13px; 245 | position: relative; 246 | width: 110%; } 247 | 248 | .pointer { 249 | left: 21px; 250 | top: 7px; 251 | display: block; 252 | position: absolute; 253 | width: 12px; 254 | height: 12px; 255 | border-left: 1px solid #ddd; 256 | border-top: 1px solid #ddd; 257 | background: #fff; 258 | transform: rotate(45deg); } 259 | 260 | .height-container { 261 | display: none; 262 | position: relative; 263 | width: 100%; 264 | overflow: hidden; } 265 | .height-container .section { 266 | background: #fff; 267 | border: 1px solid #ddd; 268 | border-top-width: 0; 269 | padding-top: 10px; 270 | padding-bottom: 5px; 271 | padding: 8px 16px; } 272 | 273 | .aside, .language { 274 | padding: 6px 12px; 275 | margin: 12px 0; 276 | border-left: 5px solid #dddddd; 277 | overflow-y: hidden; } 278 | .aside .aside-title, .language .aside-title { 279 | font-size: 9px; 280 | letter-spacing: 2px; 281 | text-transform: uppercase; 282 | padding-bottom: 0; 283 | margin: 0; 284 | color: #aaa; 285 | -webkit-user-select: none; } 286 | .aside p:last-child, .language p:last-child { 287 | margin-bottom: 0; } 288 | 289 | .language { 290 | border-left: 5px solid #cde9f4; } 291 | .language .aside-title { 292 | color: #4183c4; } 293 | 294 | .aside-warning, .aside-deprecated, .aside-unavailable { 295 | border-left: 5px solid #ff6666; } 296 | .aside-warning .aside-title, .aside-deprecated .aside-title, .aside-unavailable .aside-title { 297 | color: #ff0000; } 298 | 299 | .graybox { 300 | border-collapse: collapse; 301 | width: 100%; } 302 | .graybox p { 303 | margin: 0; 304 | word-break: break-word; 305 | min-width: 50px; } 306 | .graybox td { 307 | border: 1px solid #ddd; 308 | padding: 5px 25px 5px 10px; 309 | vertical-align: middle; } 310 | .graybox tr td:first-of-type { 311 | text-align: right; 312 | padding: 7px; 313 | vertical-align: top; 314 | word-break: normal; 315 | width: 40px; } 316 | 317 | .slightly-smaller { 318 | font-size: 0.9em; } 319 | 320 | .footer { 321 | padding: 8px 16px; 322 | background: #444; 323 | color: #ddd; 324 | font-size: 0.8em; } 325 | .footer p { 326 | margin: 8px 0; } 327 | .footer a { 328 | color: #fff; } 329 | 330 | html.dash .header, html.dash .breadcrumbs, html.dash .navigation { 331 | display: none; } 332 | 333 | html.dash .height-container { 334 | display: block; } 335 | 336 | form[role=search] input { 337 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 338 | font-size: 14px; 339 | line-height: 24px; 340 | padding: 0 10px; 341 | margin: 0; 342 | border: none; 343 | border-radius: 1em; } 344 | .loading form[role=search] input { 345 | background: white url(../img/spinner.gif) center right 4px no-repeat; } 346 | 347 | form[role=search] .tt-menu { 348 | margin: 0; 349 | min-width: 300px; 350 | background: #fbfbfb; 351 | color: #333; 352 | border: 1px solid #ddd; } 353 | 354 | form[role=search] .tt-highlight { 355 | font-weight: bold; } 356 | 357 | form[role=search] .tt-suggestion { 358 | font: 16px/1.7 "Helvetica Neue", Helvetica, Arial, sans-serif; 359 | padding: 0 8px; } 360 | form[role=search] .tt-suggestion span { 361 | display: table-cell; 362 | white-space: nowrap; } 363 | form[role=search] .tt-suggestion .doc-parent-name { 364 | width: 100%; 365 | text-align: right; 366 | font-weight: normal; 367 | font-size: 0.9em; 368 | padding-left: 16px; } 369 | 370 | form[role=search] .tt-suggestion:hover, 371 | form[role=search] .tt-suggestion.tt-cursor { 372 | cursor: pointer; 373 | background-color: #4183c4; 374 | color: #fff; } 375 | 376 | form[role=search] .tt-suggestion:hover .doc-parent-name, 377 | form[role=search] .tt-suggestion.tt-cursor .doc-parent-name { 378 | color: #fff; } 379 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/carat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/carat.png -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/dash.png -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/gh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/gh.png -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/docsets/BigNumber.docset/Contents/Resources/Documents/img/spinner.gif -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/js/jazzy.js: -------------------------------------------------------------------------------- 1 | window.jazzy = {'docset': false} 2 | if (typeof window.dash != 'undefined') { 3 | document.documentElement.className += ' dash' 4 | window.jazzy.docset = true 5 | } 6 | if (navigator.userAgent.match(/xcode/i)) { 7 | document.documentElement.className += ' xcode' 8 | window.jazzy.docset = true 9 | } 10 | 11 | function toggleItem($link, $content) { 12 | var animationDuration = 300; 13 | $link.toggleClass('token-open'); 14 | $content.slideToggle(animationDuration); 15 | } 16 | 17 | function itemLinkToContent($link) { 18 | return $link.parent().parent().next(); 19 | } 20 | 21 | // On doc load + hash-change, open any targetted item 22 | function openCurrentItemIfClosed() { 23 | if (window.jazzy.docset) { 24 | return; 25 | } 26 | var $link = $(`.token[href="${location.hash}"]`); 27 | $content = itemLinkToContent($link); 28 | if ($content.is(':hidden')) { 29 | toggleItem($link, $content); 30 | } 31 | } 32 | 33 | $(openCurrentItemIfClosed); 34 | $(window).on('hashchange', openCurrentItemIfClosed); 35 | 36 | // On item link ('token') click, toggle its discussion 37 | $('.token').on('click', function(event) { 38 | if (window.jazzy.docset) { 39 | return; 40 | } 41 | var $link = $(this); 42 | toggleItem($link, itemLinkToContent($link)); 43 | 44 | // Keeps the document from jumping to the hash. 45 | var href = $link.attr('href'); 46 | if (history.pushState) { 47 | history.pushState({}, '', href); 48 | } else { 49 | location.hash = href; 50 | } 51 | event.preventDefault(); 52 | }); 53 | 54 | // Clicks on links to the current, closed, item need to open the item 55 | $("a:not('.token')").on('click', function() { 56 | if (location == this.href) { 57 | openCurrentItemIfClosed(); 58 | } 59 | }); 60 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/Documents/js/jazzy.search.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | var $typeahead = $('[data-typeahead]'); 3 | var $form = $typeahead.parents('form'); 4 | var searchURL = $form.attr('action'); 5 | 6 | function displayTemplate(result) { 7 | return result.name; 8 | } 9 | 10 | function suggestionTemplate(result) { 11 | var t = '
'; 12 | t += '' + result.name + ''; 13 | if (result.parent_name) { 14 | t += '' + result.parent_name + ''; 15 | } 16 | t += '
'; 17 | return t; 18 | } 19 | 20 | $typeahead.one('focus', function() { 21 | $form.addClass('loading'); 22 | 23 | $.getJSON(searchURL).then(function(searchData) { 24 | const searchIndex = lunr(function() { 25 | this.ref('url'); 26 | this.field('name'); 27 | this.field('abstract'); 28 | for (const [url, doc] of Object.entries(searchData)) { 29 | this.add({url: url, name: doc.name, abstract: doc.abstract}); 30 | } 31 | }); 32 | 33 | $typeahead.typeahead( 34 | { 35 | highlight: true, 36 | minLength: 3, 37 | autoselect: true 38 | }, 39 | { 40 | limit: 10, 41 | display: displayTemplate, 42 | templates: { suggestion: suggestionTemplate }, 43 | source: function(query, sync) { 44 | const lcSearch = query.toLowerCase(); 45 | const results = searchIndex.query(function(q) { 46 | q.term(lcSearch, { boost: 100 }); 47 | q.term(lcSearch, { 48 | boost: 10, 49 | wildcard: lunr.Query.wildcard.TRAILING 50 | }); 51 | }).map(function(result) { 52 | var doc = searchData[result.ref]; 53 | doc.url = result.ref; 54 | return doc; 55 | }); 56 | sync(results); 57 | } 58 | } 59 | ); 60 | $form.removeClass('loading'); 61 | $typeahead.trigger('focus'); 62 | }); 63 | }); 64 | 65 | var baseURL = searchURL.slice(0, -"search.json".length); 66 | 67 | $typeahead.on('typeahead:select', function(e, result) { 68 | window.location = baseURL + result.url; 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /docs/docsets/BigNumber.docset/Contents/Resources/docSet.dsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/docsets/BigNumber.docset/Contents/Resources/docSet.dsidx -------------------------------------------------------------------------------- /docs/docsets/BigNumber.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/docsets/BigNumber.tgz -------------------------------------------------------------------------------- /docs/docsets/BigNumber.xml: -------------------------------------------------------------------------------- 1 | 2.1.1https://mkrd.github.io/BigNumber/reference/docsets/BigNumber.tgz 2 | -------------------------------------------------------------------------------- /docs/img/carat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/img/carat.png -------------------------------------------------------------------------------- /docs/img/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/img/dash.png -------------------------------------------------------------------------------- /docs/img/gh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/img/gh.png -------------------------------------------------------------------------------- /docs/img/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkrd/Swift-BigInt/d09d98b6819e2860160d4f0a909ce7f4925d8926/docs/img/spinner.gif -------------------------------------------------------------------------------- /docs/js/jazzy.js: -------------------------------------------------------------------------------- 1 | window.jazzy = {'docset': false} 2 | if (typeof window.dash != 'undefined') { 3 | document.documentElement.className += ' dash' 4 | window.jazzy.docset = true 5 | } 6 | if (navigator.userAgent.match(/xcode/i)) { 7 | document.documentElement.className += ' xcode' 8 | window.jazzy.docset = true 9 | } 10 | 11 | function toggleItem($link, $content) { 12 | var animationDuration = 300; 13 | $link.toggleClass('token-open'); 14 | $content.slideToggle(animationDuration); 15 | } 16 | 17 | function itemLinkToContent($link) { 18 | return $link.parent().parent().next(); 19 | } 20 | 21 | // On doc load + hash-change, open any targetted item 22 | function openCurrentItemIfClosed() { 23 | if (window.jazzy.docset) { 24 | return; 25 | } 26 | var $link = $(`.token[href="${location.hash}"]`); 27 | $content = itemLinkToContent($link); 28 | if ($content.is(':hidden')) { 29 | toggleItem($link, $content); 30 | } 31 | } 32 | 33 | $(openCurrentItemIfClosed); 34 | $(window).on('hashchange', openCurrentItemIfClosed); 35 | 36 | // On item link ('token') click, toggle its discussion 37 | $('.token').on('click', function(event) { 38 | if (window.jazzy.docset) { 39 | return; 40 | } 41 | var $link = $(this); 42 | toggleItem($link, itemLinkToContent($link)); 43 | 44 | // Keeps the document from jumping to the hash. 45 | var href = $link.attr('href'); 46 | if (history.pushState) { 47 | history.pushState({}, '', href); 48 | } else { 49 | location.hash = href; 50 | } 51 | event.preventDefault(); 52 | }); 53 | 54 | // Clicks on links to the current, closed, item need to open the item 55 | $("a:not('.token')").on('click', function() { 56 | if (location == this.href) { 57 | openCurrentItemIfClosed(); 58 | } 59 | }); 60 | -------------------------------------------------------------------------------- /docs/js/jazzy.search.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | var $typeahead = $('[data-typeahead]'); 3 | var $form = $typeahead.parents('form'); 4 | var searchURL = $form.attr('action'); 5 | 6 | function displayTemplate(result) { 7 | return result.name; 8 | } 9 | 10 | function suggestionTemplate(result) { 11 | var t = '
'; 12 | t += '' + result.name + ''; 13 | if (result.parent_name) { 14 | t += '' + result.parent_name + ''; 15 | } 16 | t += '
'; 17 | return t; 18 | } 19 | 20 | $typeahead.one('focus', function() { 21 | $form.addClass('loading'); 22 | 23 | $.getJSON(searchURL).then(function(searchData) { 24 | const searchIndex = lunr(function() { 25 | this.ref('url'); 26 | this.field('name'); 27 | this.field('abstract'); 28 | for (const [url, doc] of Object.entries(searchData)) { 29 | this.add({url: url, name: doc.name, abstract: doc.abstract}); 30 | } 31 | }); 32 | 33 | $typeahead.typeahead( 34 | { 35 | highlight: true, 36 | minLength: 3, 37 | autoselect: true 38 | }, 39 | { 40 | limit: 10, 41 | display: displayTemplate, 42 | templates: { suggestion: suggestionTemplate }, 43 | source: function(query, sync) { 44 | const lcSearch = query.toLowerCase(); 45 | const results = searchIndex.query(function(q) { 46 | q.term(lcSearch, { boost: 100 }); 47 | q.term(lcSearch, { 48 | boost: 10, 49 | wildcard: lunr.Query.wildcard.TRAILING 50 | }); 51 | }).map(function(result) { 52 | var doc = searchData[result.ref]; 53 | doc.url = result.ref; 54 | return doc; 55 | }); 56 | sync(results); 57 | } 58 | } 59 | ); 60 | $form.removeClass('loading'); 61 | $typeahead.trigger('focus'); 62 | }); 63 | }); 64 | 65 | var baseURL = searchURL.slice(0, -"search.json".length); 66 | 67 | $typeahead.on('typeahead:select', function(e, result) { 68 | window.location = baseURL + result.url; 69 | }); 70 | }); 71 | -------------------------------------------------------------------------------- /generate-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | command -v jazzy 4 | 5 | if [ $? != 0 ]; then 6 | echo "jazzy not found. Install jazzy:" 7 | echo "\t[sudo] gem install jazzy" 8 | exit 1 9 | fi 10 | 11 | set -e # don't print 12 | 13 | module="BigNumber" 14 | github="mkrd/Swift-BigInt" 15 | project="Swift-BigNumber.xcodeproj" 16 | scheme="BigNumber-macOS" 17 | 18 | # get version number from podspec 19 | version="$(egrep "^\s*s.version\s*" BigNumber.podspec | awk '{ gsub("\"", "", $3); print $3 }')" 20 | today="$(date '+%Y-%m-%d')" 21 | 22 | if git rev-parse "v$version" >/dev/null 2>&1; then 23 | # Use the tagged commit when we have one 24 | ref="v$version" 25 | else 26 | # Otherwise, use the current commit. 27 | ref="$(git rev-parse HEAD)" 28 | fi 29 | 30 | # since tagging releases doesn't happen very much - let's just use head 31 | ref="master" 32 | 33 | jazzy \ 34 | --clean \ 35 | --github_url "https://github.com/$github" \ 36 | --github-file-prefix "https://github.com/$github/tree/$ref" \ 37 | --module-version "$version" \ 38 | --xcodebuild-arguments "-project,$project,-scheme,$scheme" \ 39 | --module "$module" \ 40 | --root-url "https://mkrd.github.io/$module/reference/" \ 41 | --theme fullwidth \ 42 | --output docs \ 43 | --min-acl public\ 44 | --hide-documentation-coverage\ 45 | --copyright "[© 2018 BigNumber](https://github.com/mkrd/Swift-Big-Integer/blob/master/LICENSE). (Last updated: $today)" \ 46 | --author "mkrd" \ 47 | --author_url "https://github.com/mkrd" \ 48 | --------------------------------------------------------------------------------