silentmatt / javascript-biginteger Goto Github PK
View Code? Open in Web Editor NEWA big integer library for JavaScript
Home Page: http://silentmatt.com/biginteger/
License: MIT License
A big integer library for JavaScript
Home Page: http://silentmatt.com/biginteger/
License: MIT License
It would be great if BigInteger had formatting function.
For example, using D3's formatting:
var myBigInt = BigInteger("1234567890");
console.log(myBigInt.format(",.02f")); // "1,234,567,890.00"
console.log(myBigInt.toString(",.02f")); // "1,234,567,890.00"
Thank you
Please revisit the Bower File to fix the following stuff..
$ bower install javascript-biginteger --save
bower not-cached git://github.com/malsup/blockui.git#*
bower resolve git://github.com/malsup/blockui.git#*
bower checkout blockui#master
bower not-cached git://github.com/lu4/javascript-biginteger.git#*
bower resolve git://github.com/lu4/javascript-biginteger.git#*
bower checkout javascript-biginteger#master
bower invalid-meta blockUI is missing "ignore" entry in bower.json
bower resolved git://github.com/malsup/blockui.git#316f6e5d76
bower progress javascript-biginteger#* Receiving objects: 67% (23/34), 508.00 KiB | 47.00 KiB/s
bower progress javascript-biginteger#* Receiving objects: 67% (23/34), 524.00 KiB | 38.00 KiB/s
bower progress javascript-biginteger#* Receiving objects: 67% (23/34), 564.00 KiB | 32.00 KiB/s
bower progress javascript-biginteger#* Receiving objects: 67% (23/34), 580.00 KiB | 32.00 KiB/s
bower progress javascript-biginteger#* Receiving objects: 85% (29/34), 620.00 KiB | 29.00 KiB/s
bower progress javascript-biginteger#* Receiving objects: 85% (29/34), 676.00 KiB | 32.00 KiB/s
bower invalid-meta javascript-biginteger is missing "main" entry in bower.json
bower invalid-meta javascript-biginteger is missing "ignore" entry in bower.json
bower resolved git://github.com/lu4/javascript-biginteger.git#60190f7b5f
bower install javascript-biginteger#60190f7b5f
bower install blockui#316f6e5d76
javascript-biginteger#60190f7b5f ....\src\web\app\public\vendor\javascript-biginteger
blockui#316f6e5d76 ....\src\web\app\public\vendor\blockui
└── jquery#2.2.0
negative zero is a result of "compareTo"
Array#map is only used once, and needs to be provided for IE compatibility (ugh). It's kind of a waste to have all the code for a single use.
is this intentional?
Could you please provide a small example how to use this module? For example in a node.js environment?
Sorry for the inconvenience,
I was talking about another library.
Mickaël
Make it more clear in the documentation that BigInteger only takes one argument (when called as a normal function), not value and a radix.
The "static" sign function is missing.
The division
BigInteger.parse("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
.divide(BigInteger.parse("1234567890"))
.toString()
should return
"10000000001000000000100000000010000000001000000000100000000010000000001"
but instead returns
"10000000000000000000000000000000000000000000000000000000000000000000000"
We're using your code in an Firefox Extension and their guidelines ask to link to specific tagged version of third party libraries, if you could add a tag for the latest version we'd appreciate it very much, thank you.
First off, great library! Very useful.
But the repository here is missing the divMod and mod functions as listed on the docs, and possibly others I have not noticed, as well as constants like ZERO, _0, etc. I'm guessing you just haven't pushed to git, in which case please do so. :)
////
sorry this was beacuse i used input type="number" instead of input type="text"
In BigInteger.parse, after "// Optimize 10", the while loop uses digits.splice(-BigInteger.base_log10) which equates to digits.splice(-7).
This is not supported by IE (see ref #2 below) => on IE8 (in "IE8 mode"): infinite loop.
In order to overcome the problem, I have replaced this (around line 392):
var d = [];
while (digits.length >= BigInteger.base_log10) {
d.push(parseInt(digits.splice(-BigInteger.base_log10).join(''), 10));
by this:
var d = [];
while (digits.length >= BigInteger.base_log10) {
d.push(parseInt(digits.splice(digits.length-BigInteger.base_log10, BigInteger.base_log10).join(''), 10));
I have successfully run the test suite with this patched code + rhino 1.7R2-3 on Ubuntu 10.04 x86 (aka "lucid"):
./run-test
[...]
Finished in 12.175
Passed 29/29 (100.00%): PASS
References :
1 - splice() at MDN: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice
2 - splice() at MSDN: http://msdn.microsoft.com/en-us/library/wctc5k7s(v=VS.94).aspx
A simple program:
function print (e) {
var val = BigInteger.parse(e, "16").valueOf();
console.log("HEX(" + e + ") = " + val);
}
console.info("Without prepending zero:")
var arr = ['0','1','2','3','4','5','6','7','8','9','a', 'b', 'c', 'd', 'e', 'f'];
arr.forEach(print);
console.info("With prepending zero:")
var arr2 = ['00','01','02','03','04','05','06','07','08','09','0a', '0b', '0c', '0d', '0e', '0f'];
arr2.forEach(print);
It returns:
Without prepending zero:
HEX(0) = 0
HEX(1) = 1
HEX(2) = 2
HEX(3) = 3
HEX(4) = 4
HEX(5) = 5
HEX(6) = 6
HEX(7) = 7
HEX(8) = 8
HEX(9) = 9
HEX(a) = 10
HEX(b) = 11
HEX(c) = 12
HEX(d) = 13
HEX(e) = 14
HEX(f) = 15
With prepending zero:
HEX(00) = 0
HEX(01) = 1
HEX(02) = 2
HEX(03) = 3
HEX(04) = 4
HEX(05) = 5
HEX(06) = 6
HEX(07) = 7
HEX(08) = 8
HEX(09) = 9
HEX(0a) = 10
HEX(0b) = 0
HEX(0c) = 0
HEX(0d) = 13
HEX(0e) = 14
HEX(0f) = 15
0a
,0d
and 0e
are correct, while 0b
and 0c
are zero.
Here the above example (see console): http://paste.dennis-boldt.de/bugs/biginteger/
BigInteger.parse("0.1234*10^4")
parses as 668 instead of 1234 because of the leading zero.
To fix this issue and to avoid confusion, leading zeros should not imply octal. As a replacement, we'll support a "0c" prefix.
BigInteger.valueOf = BigInteger.parse;
BigInteger.prototype.doubleValue = BigInteger.prototype.toJSValue;
BigInteger.prototype.compareTo = BigInteger.prototype.compare;
BigInteger.prototype.signum = BigInteger.prototype.sign;
BigInteger.prototype.gcd = function (l) {
var a = this.abs();
var b = this.multiply(0).add(l).abs();
var t;
while (b.compareTo(0) > 0) {
t = a.remainder(b);
a = b;
b = t;
}
return a;
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.