JKBigInteger2 0.0.5

JKBigInteger2 0.0.5

测试已测试
Lang语言 CC
许可证 MIT
发布上次发布2016 年 4 月

Andrii Struts 维护。



JKBigInteger

关于 JKBigInteger

JKBigInteger 是一个小的库,用于简化 Objective-C 中大整数的操作。JKBigInteger 是 LibTomMath C 库的 Objective-C 封装。它受到 Java BigInteger 的启发。

示例

JKBigInteger *int1 = [[JKBigInteger alloc] initWithString:@"123"];

NSLog(@"%@ + %@ = %@", int1, int1, [int1 add:int1]);

JKBigInteger *int2 = [[JKBigInteger alloc] initWithString:@"10000001234567890123"];
JKBigInteger *int3 = [[JKBigInteger alloc] initWithString:@"123"];

NSLog(@"%@ - %@ = %@", int2, int3, [int2 subtract:int3]);

JKBigInteger *int4 = [[JKBigInteger alloc] initWithString:@"11111111111111111111"];

NSLog(@"%@ * %@ = %@", int4, int4, [int4 multiply:int4]);

JKBigInteger *int5 = [[JKBigInteger alloc] initWithString:@"10000001234567890123123123123"];
JKBigInteger *int6 = [[JKBigInteger alloc] initWithString:@"123"];

NSLog(@"%@ / %@ = %@", int5, int6, [int5 divide:int6]);

unsigned int numBytesInt5 = [int5 countBytes];
unsigned char bytes[numBytesInt5];

[int5 toByteArrayUnsigned:bytes];

for(unsigned i = 0; i < numBytesInt5; i++)
{
     NSLog(@"Byte %d: %X", i, bytes[i]);
}

JKBigDecimal *dec1 = [[JKBigDecimal alloc] initWithString:@"2015.987"];
JKBigDecimal *dec2 = [[JKBigDecimal alloc] initWithString:@"5.4"];
NSLog(@"%@ + %@ = %@", dec1, dec2, [dec1 add:dec2]);
NSLog(@"%@ - %@ = %@", dec1, dec2, [dec1 subtract:dec2]);
NSLog(@"%@ * %@ = %@", dec1, dec2, [dec1 multiply:dec2]);
NSLog(@"%@ / %@ = %@", dec1, dec2, [dec1 divide:dec2]);
NSLog(@"%@ %% %@ = %@", dec1, dec2, [dec1 remainder:dec2]);

JKBigDecimal *dec3 = [[JKBigDecimal alloc] initWithString:@"0.99"];
NSLog(@"%@ pow 365 = %@", dec3, [dec3 pow:365]);

安装

您可以通过将以下内容添加到您的 Podfile 中,使用 CocoaPods 容易地将 JKBigInteger 添加到项目中

pod 'JKBigInteger', '~> 0.0.1'

阅读 'Pod' 语法参考 以获取更多详细信息。

感谢

JKBigInteger 由 Jānis Kiršteins 创建。JKBigDecimal 由 Midfar Sun 创建。

许可证

JKBigInteger 基于 MIT 许可证可用。有关更多信息,请参阅 LICENSE 文件。