2015-06-23 75 views
1

我必须在swift中使用大量数字(以实现RSA算法),所以我正在寻找与Java的BigInteger类相当的功能。在另一个主题中,我发现了这一个:https://github.com/kirsteins/BigInteger 所以我试图将这个添加到我的项目中,遵循以下步骤: - 我下载并添加BigInteger.xcodeproj到我的项目 在“Build Phases”中: - Add “BigInteger的”在“目标相关” - “从‘BigInteger的’IN‘的BigInteger’项目的目标BigInteger.framework”到“链接二进制与图书馆”添加 - 添加“BigInteger.framework”到“复制文件”Swift:添加BigInteger框架

当我构建项目时,它“构建失败”,但我不明白为什么有问题。我发现YouTube上的一个视频https://www.youtube.com/watch?v=NBmfGdbOrMs描述的步骤,我完全按照这些步骤,但问题仍然在这里...

你有同样的问题吗?你找到解决方案吗?

回答

0

我写了一个大整数和大的双快速实现,这不需要任何额外的库。只需将其复制到您的项目中。它支持大多数常用数学运算符(如加法,减法,乘法,取幂,模数和除法)的整数(BInt)和分数(BDouble)。一些优化的数学函数,如阶乘或gcd也被实现。

下面是一些代码示例:

// Create a new number: 
let num = BInt(232) 
print(num) // prints "232" 

// You can also use Strings to create a number: 
let veryBig = BInt("-827846184963421874362418746238453267452971345218746328715380000000000") 

// Every standard math operator works well, even with normal Integers 
// Visit the github page for more informations 
let v0 = (BInt(5) + BInt(4)) - BInt(3) 
let v1 = veryBig * 1000 
let v2 = vergBig^num 
let v3 = (veryBig^50000)/(BInt(2)^900) + 1 
let v4 = gcd(abs(veryBig), num) 

// BDouble is very similar, you can find a detailed description on Github 
let fraction = BDouble("27", over: "31") 
print(fraction) // prints "27/31" 

您可以自由使用它没有给我的信用,如果你想请贡献。

您可以在这里找到它:https://github.com/mkrd/Swift-Big-Integer