1

http://www.leemon.com/crypto/BigInt.js

I am using the leemon bigint.js library, but I am having trouble figuring out how to divide one big number by another. Here is what I have so far:

var a = str2bigInt("100",10);
var b = int2bigInt("5", 10);
var result = [];
var r = [];
divide_(a,b,result,r)
alert(bigInt2str(result,10));

but when I alert(result) the output is 0. The result should be 20? Can anybody see what I am doing wrong?

Cheers

2 Answers 2

3

I suppose the line

var b = int2bigInt("5", 10);

should be

var b = str2bigInt("5", 10);

The function int2bigInt expects an integer, not a string.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you explain what is the second parameter? I have to port this function to other language, so confused
0

Apparently, this BigInt.js library expects the result arrays to already have sufficient length to store the result; using empty arrays doesn't work.

This code however works as expected:

var a = str2bigInt("100",10);
var b = int2bigInt("5", 10);
var result = new Array(2);
var r = new Array(2);
divide_(a,b,result,r);
alert(bigInt2str(result,10));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.