Code Monkey home page Code Monkey logo

jkbiginteger's Introduction

JKBigInteger

About JKBigInteger

JKBigInteger is a small library to facilitate easy working with big integers in Objective-C. JKBigInteger is a Objective-C wrapper around LibTomMath C library. It is inspired by the Java's BigInteger.

Example

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]);

Installation

You can easily add JKBigInteger to your project with CocoaPods by adding it to your Podfile:

pod 'JKBigInteger', '~> 0.0.1'

Read the 'Pod' Syntax Reference for more details.

Credits

JKBigInteger was created by Jānis Kiršteins. JKBigDecimal was created by Midfar Sun.

License

JKBigInteger is available under the MIT license. See the LICENSE file for more info.

jkbiginteger's People

Contributors

dbgrandi avatar hphu avatar kirsteins avatar midfar avatar nanolith avatar terribleben avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.