Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Allows developer to define irrational numbers as infinite summations and iterate over the digits

Notifications You must be signed in to change notification settings

JadenGeller/JGIrrationalNumber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

JGIrrationalNumber

Allows developer to define irrational numbers as infinite summations and iterate over the digits

Example

We will calculate the natural number e with the infinite series 1/0! + 1/1! + 1/2! + 1/3! + 1/4! + ...

// Define number via infinite series block
JGIrrationalNumber *e = [JGIrrationalNumber irrationalNumberWithConvergingSeries:^NSDecimalNumber *(NSDecimalNumber *term, NSMutableDictionary *storage) {
        
        NSDecimalNumber *factorial = storage[@"factorial"]?: [NSDecimalNumber one];
        if ([term compare:[NSDecimalNumber zero]] != NSOrderedSame) factorial = [factorial decimalNumberByMultiplyingBy:term];
        
        storage[@"factorial"] = factorial;
        
        return [[NSDecimalNumber one] decimalNumberByDividingBy:factorial];
}];
    
// Iterate over the digits of the number
[e getDigitsInRange:NSMakeRange(0, 40) withBlock:^void(NSInteger index, NSString *digit) {
    // Do stuff with each digit
}];

About

Allows developer to define irrational numbers as infinite summations and iterate over the digits

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published