Git Product home page Git Product logo

javascript-biginteger's Issues

Formatting

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

Missing "main" entry in bower.json

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

Consider removing map dependency

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.

Example

Could you please provide a small example how to use this module? For example in a node.js environment?

Please delete me.

Sorry for the inconvenience,
I was talking about another library.
Mickaël

Bug in division

The division

BigInteger.parse("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
  .divide(BigInteger.parse("1234567890"))
  .toString()

should return

"10000000001000000000100000000010000000001000000000100000000010000000001"

but instead returns

"10000000000000000000000000000000000000000000000000000000000000000000000"

Tagged Version

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.

Please Update this Repository

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. :)

IE does not support array.splice(negative_value), patch included in issue description

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

`parse("0b", "16")` and `parse("0c", "16")` are zero

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/

compatibility with java.math.BigInteger

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;
};

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.