Skip to content

Commit

Permalink
Accept Long-like object in constructor, fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 18, 2014
1 parent 4be41f6 commit a92f218
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
10 changes: 8 additions & 2 deletions dist/Long.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@
*
* @exports Long
* @class A Long class for representing a 64-bit two's-complement integer value.
* @param {number} low The low (signed) 32 bits of the long.
* @param {number} high The high (signed) 32 bits of the long.
* @param {number|!{low: number, high: number, unsigned: boolean}} low The low (signed) 32 bits of the long.
* Optionally accepts a Long-like object as the first parameter.
* @param {number=} high The high (signed) 32 bits of the long.
* @param {boolean=} unsigned Whether unsigned or not. Defaults to `false` (signed).
* @constructor
*/
var Long = function(low, high, unsigned) {
if (low && typeof low === 'object') {
high = low.high;
unsigned = low.unsigned;
low = low.low;
}

/**
* The low 32 bits as a signed value.
Expand Down
8 changes: 4 additions & 4 deletions dist/Long.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions docs/Long.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2>


<dt>
<h4 class="name" id="Long"><span class="type-signature"></span>new Long<span class="signature">(low, high, <span class="optional">unsigned</span>)</span><span class="type-signature"></span></h4>
<h4 class="name" id="Long"><span class="type-signature"></span>new Long<span class="signature">(low, <span class="optional">high</span>, <span class="optional">unsigned</span>)</span><span class="type-signature"></span></h4>


</dt>
Expand Down Expand Up @@ -92,6 +92,9 @@ <h5>Parameters:</h5>


<span class="param-type">number</span>
|

<span class="param-type">!{low: number, high: number, unsigned: boolean}</span>



Expand All @@ -107,7 +110,7 @@ <h5>Parameters:</h5>



<td class="description last">The low (signed) 32 bits of the long.</td>
<td class="description last">The low (signed) 32 bits of the long. Optionally accepts a Long-like object as the first parameter.</td>
</tr>


Expand All @@ -129,6 +132,8 @@ <h5>Parameters:</h5>

<td class="attributes">

&lt;optional><br>



</td>
Expand Down
4 changes: 2 additions & 2 deletions externs/Long.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
*/

/**
* @param {number} low
* @param {number} high
* @param {number|!{low: number, high: number, unsigned: boolean}} low
* @param {number=} high
* @param {boolean=} unsigned
* @constructor
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "long",
"version": "1.1.3",
"version": "1.1.4",
"author": "Daniel Wirtz <dcode@dcode.io>",
"description": "A Long class for representing a 64-bit two's-complement integer value.",
"main": "index.js",
Expand Down
10 changes: 8 additions & 2 deletions src/Long.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@
*
* @exports Long
* @class A Long class for representing a 64-bit two's-complement integer value.
* @param {number} low The low (signed) 32 bits of the long.
* @param {number} high The high (signed) 32 bits of the long.
* @param {number|!{low: number, high: number, unsigned: boolean}} low The low (signed) 32 bits of the long.
* Optionally accepts a Long-like object as the first parameter.
* @param {number=} high The high (signed) 32 bits of the long.
* @param {boolean=} unsigned Whether unsigned or not. Defaults to `false` (signed).
* @constructor
*/
var Long = function(low, high, unsigned) {
if (low && typeof low === 'object') {
high = low.high;
unsigned = low.unsigned;
low = low.low;
}

/**
* The low 32 bits as a signed value.
Expand Down
4 changes: 4 additions & 0 deletions tests/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ var suite = {
var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF);
test.equal(longVal.toNumber(), 9223372036854775807);
test.equal(longVal.toString(), "9223372036854775807");
var longVal2 = new Long(longVal);
test.equal(longVal2.toNumber(), 9223372036854775807);
test.equal(longVal2.toString(), "9223372036854775807");
test.equal(longVal2.unsigned, longVal.unsigned);
test.done();
},

Expand Down

0 comments on commit a92f218

Please sign in to comment.