Code Monkey home page Code Monkey logo

jkbiginteger's People

Contributors

dbgrandi avatar hphu avatar kirsteins avatar midfar avatar nanolith avatar palpatim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jkbiginteger's Issues

JKBigDecimal is not included in the pod

JKBigDecimal.h and JKBigDecimal.m files are missing after including the pod to a project using
pod 'JKBigInteger', '~> 0.0.1'

I am not sure should they exist in the pod file, however you are giving examples with them in your README.md

I would be really glad if you include them and update the pod specs.
Thanks.

SquareRoot unavailable.

There is no square-root method which would be very useful. I've taken the liberty of writing a square-root approximation code that will get about 99.9% accurate to the actual value. Having a "SquareRootApprox" function would even be useful to many programmers I'd assume. (*Note: uses containsString which is iOS8+, this can be converted to .rangeOfString != for further compatability.

`

-(NSString *)squareRootEstimateOfNumber:(NSString *)number {

if ([number containsString:@"."]) {
    number = [[number componentsSeparatedByString:@"."] objectAtIndex:0];
}

int significantDigits = (int)[pString @"%i", INT_MAX].length-1;
significantDigits-=significantDigits%2;

JKBigDecimal *numberJKF = [[JKBigDecimal alloc] initWithString:number];
int numberOfDigits = (int)number.length;

if (numberOfDigits <= significantDigits) {
    return [pString @"%i", (int)round(sqrt([number floatValue]))];
} else {
    JKBigDecimal *tenJKF = [[JKBigDecimal alloc] initWithString:@"10"];
    int divisorExponent = numberOfDigits-significantDigits-(numberOfDigits%2);
    int factorExponent = (int)((float)divisorExponent/2.0f);
    JKBigDecimal *divisorJKF = [[JKBigDecimal alloc] initWithString:@"1"];
    divisorJKF = [tenJKF pow:divisorExponent];
    JKBigDecimal *factorJKF = [[JKBigDecimal alloc] initWithString:@"1"];
    factorJKF = [tenJKF pow:factorExponent];

    float significantFigures = (float)[[[numberJKF divide:divisorJKF] stringValue] floatValue];
    int significantRoot = (int)round(sqrt(significantFigures));
    JKBigDecimal *significantRootJKF = [[JKBigDecimal alloc] initWithString:[pString @"%i", significantRoot]];

    JKBigDecimal *estimateRootJKF = [[JKBigDecimal alloc] initWithString:@"1"];
    estimateRootJKF = [significantRootJKF multiply:factorJKF];

    return [estimateRootJKF stringValue];
}

}

`

There is a problem with the stringValue implementation

- (NSString *)stringValue
implementation returns wrong values when it is dealing with negative numbers in the interval [-1; 0]
There are problems with JKBigDecimal implementation.

Code for testing:
JKBigDecimal* b = [[JKBigDecimal alloc] initWithString:@"0.0074000"]; b = [b negate]; NSLog(@"-0.0074000 is %@", [b stringValue]);

Analyzer issues

Hi! Is there a build of this library with no analyzer issues in tommath? I am building in Xcode 5.1.1. I can likely work around/fix these, but if this is already being worked on, I'd be happy to test.

Tag from last commit

Hello,

I am using your library and really like it!
But I use 'pow:andMod:' method, which does not have tag.
Could you please create a tag from your last commit so I can easily use it in mine podfile and podspec file?

Thanks in advance!

Pod unable to install JKBigInteger2 0.0.5

Currently I stucked with this while install from cocoapods. For other packages are working ok.

[!] Error installing JKBigInteger2
[!] /usr/bin/git clone https://github.com/astruts/JKBigInteger.git /var/folders/4c/prj_vdcs0ln44y4sxdp_vp300000gp/T/d20191105-23278-66j5j1 --template= --single-branch --depth 1 --branch 0.0.5

Cloning into '/var/folders/4c/prj_vdcs0ln44y4sxdp_vp300000gp/T/d20191105-23278-66j5j1'...
fatal: unable to access 'https://github.com/astruts/JKBigInteger.git/': Failed to connect to 10.210.250.7 port 8080: Network is unreachable

How to calculate Pow with negative number?

Hi,
Your library is great, but how can we calculate Pow with negative number with very large result.Example: pow(2000,-250). Totally, I want to calculate this type: pow(1500,-245) mod 5794. Can you help me how to do it? Thank you

Fatal Error: JKBigDecimal Internal Logic Mutates Variables

While performing some functions, sometimes the internal logic of the library will mutate values we were working with, this was leading to fatal errors in our system

One isolated example is here:


+(void)load {
    
#define jkCopy(__jk) __jk//[JKBigDecimal decimalWithString:[(__jk) stringValue]]
    
    JKBigDecimal *tcc = [JKBigDecimal decimalWithString:[NSString stringWithFormat:@"%i", (int)pow(2, 13)]];
    JKBigDecimal *rbc = [JKBigDecimal decimalWithString:[NSString stringWithFormat:@"%i", (int)pow(2, 21)]];

    JKBigDecimal *HPS = [JKBigDecimal decimalWithString:[NSString stringWithFormat:@"%f", 500000.0]];
    
    JKBigDecimal *btwt = [jkCopy(rbc) divide:jkCopy(HPS)];
    JKBigDecimal *btwot = [jkCopy([jkCopy(rbc) multiply:jkCopy(tcc)]) divide:jkCopy(HPS)];
    
    NSLog(@"btwt = %@", [btwt stringValue]);//logs 4 correctly
    
    NSLog(@"btwt/2 = %@", [[jkCopy(btwt) divide:[JKBigDecimal decimalWithString:@"2.0"]] stringValue]);
    
    NSLog(@"btwt = %@", [btwt stringValue]);//logs 40 incorrectly, btwt was mutated! Fatal error
    
    exit(0);
    
}

As you can see, the variable btwt changes from 4 to 40 at the end even though we did not mutate it in our code (it was mutated internally by a bug in JKBigDecimal)

I created a macro jkCopy() to make a new version of each JKBigDecimal value each time to prevent the mutation from impacting other areas of code, this copy macro is disabled in the code above but you can un-comment it back in to see it fix and give the expected output value in logs.

JKBigDecimal subtraction bug

1.1 - 1.01 = 9.09, instead of 0.09

JKBigDecimal *bigDecimal = [JKBigDecimal decimalWithString:@"1.1"];
bigDecimal = [bigDecimal subtract:[JKBigDecimal decimalWithString:@"1.01"]];
NSLog(@"%@", bigDecimal.stringValue); // 1.1 - 1.01 = 9.09, instead of 0.09

Please change current

- (id)subtract:(JKBigDecimal *)bigDecimal
{
...
}

to this:

- (id)subtract:(JKBigDecimal *)bigDecimal
{
JKBigDecimal *newBigDecimal = [self add:[bigDecimal multiply:[JKBigDecimal decimalWithString:@"-1"]]];
return newBigDecimal;
}

JKBigDecimal division rounds

JKBigDecimal doesn't scale appropriately for integer division.
Ex.
1/32 = 0, expected: 0.03125
1/1000 = 0, expected: 0.001

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.