Skip to content

Commit

Permalink
toSigned/Unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Wirtz committed Mar 19, 2013
1 parent 77014b4 commit f7b8717
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 10 deletions.
20 changes: 20 additions & 0 deletions Long.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,26 @@
}
}
};

/**
* @return {!Long} Signed long
* @expose
*/
Long.prototype.toSigned = function() {
var l = this.clone();
l.unsigned = false;
return l;
};

/**
* @return {!Long} Unsigned long
* @expose
*/
Long.prototype.toUnsigned = function() {
var l = this.clone();
l.unsigned = true;
return l;
};

/**
* @return {Long} Cloned instance with the same low/high bits and unsigned flag.
Expand Down
18 changes: 9 additions & 9 deletions Long.min.js

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

152 changes: 152 additions & 0 deletions docs/Long.html
Original file line number Diff line number Diff line change
Expand Up @@ -4712,6 +4712,82 @@ <h5>Returns:</h5>



</dd>



<dt>
<h4 class="name" id="toSigned"><span class="type-signature"></span>toSigned<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="Long.html">Long</a>}</span></h4>


</dt>
<dd>










<dl class="details">























</dl>







<h5>Returns:</h5>


<div class="param-desc">
Signed long
</div>



<dl>
<dt>
Type
</dt>
<dd>

<span class="param-type"><a href="Long.html">Long</a></span>


</dd>
</dl>




</dd>


Expand Down Expand Up @@ -4846,6 +4922,82 @@ <h5>Returns:</h5>



</dd>



<dt>
<h4 class="name" id="toUnsigned"><span class="type-signature"></span>toUnsigned<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="Long.html">Long</a>}</span></h4>


</dt>
<dd>










<dl class="details">























</dl>







<h5>Returns:</h5>


<div class="param-desc">
Unsigned long
</div>



<dl>
<dt>
Type
</dt>
<dd>

<span class="param-type"><a href="Long.html">Long</a></span>


</dd>
</dl>




</dd>


Expand Down
15 changes: 15 additions & 0 deletions externs/Long.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,18 @@ Long.prototype.shiftRight = function(numBits) {};
* @return {!Long}
*/
Long.prototype.shiftRightUnsigned = function(numBits) {};

/**
* @return {!Long}
*/
Long.prototype.toSigned = function() {};

/**
* @return {!Long}
*/
Long.prototype.toUnsigned = function() {};

/**
* @return {!Long}
*/
Long.prototype.clone = function() {};
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.0",
"version": "1.1.1",
"author": "Daniel Wirtz <[email protected]>",
"description": "Long.js: A Long class for representing a 64-bit two's-complement integer value derived from the Closure Library extended with unsigned support.",
"main": "Long.js",
Expand Down
11 changes: 11 additions & 0 deletions tests/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var suite = {
// So let's focus on my probably not-so-smart unsigned extension:

"unsigned": {

"construct_negint": function(test) {
var longVal = Long.fromInt(-1, true);
test.equal(longVal.low, -1);
Expand Down Expand Up @@ -62,6 +63,16 @@ var suite = {
test.equal(longVal.toString(), "18446744073709551615");
test.done();
},

"toSigned/Unsigned": function(test) {
var longVal = Long.fromNumber(-1, false);
test.equal(longVal.toNumber(), -1);
longVal = longVal.toUnsigned();
test.equal(longVal.toNumber(), 0xFFFFFFFFFFFFFFFF);
longVal = longVal.toSigned();
test.equal(longVal.toNumber(), -1);
test.done();
},

"max_unsigned_sub_max_signed": function(test) {
var longVal = Long.MAX_UNSIGNED_VALUE.subtract(Long.MAX_SIGNED_VALUE).subtract(Long.ONE);
Expand Down

0 comments on commit f7b8717

Please sign in to comment.