JS backend: prepare long.js for use in translator
This commit is contained in:
@@ -251,6 +251,7 @@
|
|||||||
<file name="kotlin_lib_ecma5.js"/>
|
<file name="kotlin_lib_ecma5.js"/>
|
||||||
<file name="kotlin_lib.js"/>
|
<file name="kotlin_lib.js"/>
|
||||||
<file name="maps.js"/>
|
<file name="maps.js"/>
|
||||||
|
<file name="long.js"/>
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
</closure-compiler>
|
</closure-compiler>
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ public final class RhinoUtils {
|
|||||||
runFileWithRhino(getKotlinLibFile(version), context, scope);
|
runFileWithRhino(getKotlinLibFile(version), context, scope);
|
||||||
runFileWithRhino(pathToTestFilesRoot() + "kotlin_lib.js", context, scope);
|
runFileWithRhino(pathToTestFilesRoot() + "kotlin_lib.js", context, scope);
|
||||||
runFileWithRhino(pathToTestFilesRoot() + "maps.js", context, scope);
|
runFileWithRhino(pathToTestFilesRoot() + "maps.js", context, scope);
|
||||||
|
runFileWithRhino(pathToTestFilesRoot() + "long.js", context, scope);
|
||||||
runFileWithRhino(pathToTestFilesRoot() + "jshint.js", context, scope);
|
runFileWithRhino(pathToTestFilesRoot() + "jshint.js", context, scope);
|
||||||
for (String jsLibrary : jsLibraries) {
|
for (String jsLibrary : jsLibraries) {
|
||||||
runFileWithRhino(jsLibrary, context, scope);
|
runFileWithRhino(jsLibrary, context, scope);
|
||||||
|
|||||||
+277
-251
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
|
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -9,21 +25,11 @@
|
|||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
/**
|
(function (Kotlin) {
|
||||||
* @fileoverview Defines a Long class for representing a 64-bit two's-complement
|
"use strict";
|
||||||
* integer value, which faithfully simulates the behavior of a Java "long". This
|
|
||||||
* implementation is derived from LongLib in GWT.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
goog.provide('goog.math.Long');
|
/**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a 64-bit two's-complement integer, given its low and high 32-bit
|
* Constructs a 64-bit two's-complement integer, given its low and high 32-bit
|
||||||
* values as *signed* integers. See the from* functions below for more
|
* values as *signed* integers. See the from* functions below for more
|
||||||
* convenient ways of constructing Longs.
|
* convenient ways of constructing Longs.
|
||||||
@@ -47,7 +53,7 @@ goog.provide('goog.math.Long');
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
goog.math.Long = function(low, high) {
|
Kotlin.Long = function(low, high) {
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
@@ -59,85 +65,85 @@ goog.math.Long = function(low, high) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.high_ = high | 0; // force into 32 signed bits.
|
this.high_ = high | 0; // force into 32 signed bits.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the
|
// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the
|
||||||
// from* methods on which they depend.
|
// from* methods on which they depend.
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cache of the Long representations of small integer values.
|
* A cache of the Long representations of small integer values.
|
||||||
* @type {!Object}
|
* @type {!Object}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.IntCache_ = {};
|
Kotlin.Long.IntCache_ = {};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Long representing the given (32-bit) integer value.
|
* Returns a Long representing the given (32-bit) integer value.
|
||||||
* @param {number} value The 32-bit integer in question.
|
* @param {number} value The 32-bit integer in question.
|
||||||
* @return {!goog.math.Long} The corresponding Long value.
|
* @return {!Kotlin.Long} The corresponding Long value.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.fromInt = function(value) {
|
Kotlin.Long.fromInt = function(value) {
|
||||||
if (-128 <= value && value < 128) {
|
if (-128 <= value && value < 128) {
|
||||||
var cachedObj = goog.math.Long.IntCache_[value];
|
var cachedObj = Kotlin.Long.IntCache_[value];
|
||||||
if (cachedObj) {
|
if (cachedObj) {
|
||||||
return cachedObj;
|
return cachedObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj = new goog.math.Long(value | 0, value < 0 ? -1 : 0);
|
var obj = new Kotlin.Long(value | 0, value < 0 ? -1 : 0);
|
||||||
if (-128 <= value && value < 128) {
|
if (-128 <= value && value < 128) {
|
||||||
goog.math.Long.IntCache_[value] = obj;
|
Kotlin.Long.IntCache_[value] = obj;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Long representing the given value, provided that it is a finite
|
* Returns a Long representing the given value, provided that it is a finite
|
||||||
* number. Otherwise, zero is returned.
|
* number. Otherwise, zero is returned.
|
||||||
* @param {number} value The number in question.
|
* @param {number} value The number in question.
|
||||||
* @return {!goog.math.Long} The corresponding Long value.
|
* @return {!Kotlin.Long} The corresponding Long value.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.fromNumber = function(value) {
|
Kotlin.Long.fromNumber = function(value) {
|
||||||
if (isNaN(value) || !isFinite(value)) {
|
if (isNaN(value) || !isFinite(value)) {
|
||||||
return goog.math.Long.ZERO;
|
return Kotlin.Long.ZERO;
|
||||||
} else if (value <= -goog.math.Long.TWO_PWR_63_DBL_) {
|
} else if (value <= -Kotlin.Long.TWO_PWR_63_DBL_) {
|
||||||
return goog.math.Long.MIN_VALUE;
|
return Kotlin.Long.MIN_VALUE;
|
||||||
} else if (value + 1 >= goog.math.Long.TWO_PWR_63_DBL_) {
|
} else if (value + 1 >= Kotlin.Long.TWO_PWR_63_DBL_) {
|
||||||
return goog.math.Long.MAX_VALUE;
|
return Kotlin.Long.MAX_VALUE;
|
||||||
} else if (value < 0) {
|
} else if (value < 0) {
|
||||||
return goog.math.Long.fromNumber(-value).negate();
|
return Kotlin.Long.fromNumber(-value).negate();
|
||||||
} else {
|
} else {
|
||||||
return new goog.math.Long(
|
return new Kotlin.Long(
|
||||||
(value % goog.math.Long.TWO_PWR_32_DBL_) | 0,
|
(value % Kotlin.Long.TWO_PWR_32_DBL_) | 0,
|
||||||
(value / goog.math.Long.TWO_PWR_32_DBL_) | 0);
|
(value / Kotlin.Long.TWO_PWR_32_DBL_) | 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Long representing the 64-bit integer that comes by concatenating
|
* Returns a Long representing the 64-bit integer that comes by concatenating
|
||||||
* the given high and low bits. Each is assumed to use 32 bits.
|
* the given high and low bits. Each is assumed to use 32 bits.
|
||||||
* @param {number} lowBits The low 32-bits.
|
* @param {number} lowBits The low 32-bits.
|
||||||
* @param {number} highBits The high 32-bits.
|
* @param {number} highBits The high 32-bits.
|
||||||
* @return {!goog.math.Long} The corresponding Long value.
|
* @return {!Kotlin.Long} The corresponding Long value.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.fromBits = function(lowBits, highBits) {
|
Kotlin.Long.fromBits = function(lowBits, highBits) {
|
||||||
return new goog.math.Long(lowBits, highBits);
|
return new Kotlin.Long(lowBits, highBits);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Long representation of the given string, written using the given
|
* Returns a Long representation of the given string, written using the given
|
||||||
* radix.
|
* radix.
|
||||||
* @param {string} str The textual representation of the Long.
|
* @param {string} str The textual representation of the Long.
|
||||||
* @param {number=} opt_radix The radix in which the text is written.
|
* @param {number=} opt_radix The radix in which the text is written.
|
||||||
* @return {!goog.math.Long} The corresponding Long value.
|
* @return {!Kotlin.Long} The corresponding Long value.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.fromString = function(str, opt_radix) {
|
Kotlin.Long.fromString = function(str, opt_radix) {
|
||||||
if (str.length == 0) {
|
if (str.length == 0) {
|
||||||
throw Error('number format error: empty string');
|
throw Error('number format error: empty string');
|
||||||
}
|
}
|
||||||
@@ -148,138 +154,138 @@ goog.math.Long.fromString = function(str, opt_radix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (str.charAt(0) == '-') {
|
if (str.charAt(0) == '-') {
|
||||||
return goog.math.Long.fromString(str.substring(1), radix).negate();
|
return Kotlin.Long.fromString(str.substring(1), radix).negate();
|
||||||
} else if (str.indexOf('-') >= 0) {
|
} else if (str.indexOf('-') >= 0) {
|
||||||
throw Error('number format error: interior "-" character: ' + str);
|
throw Error('number format error: interior "-" character: ' + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do several (8) digits each time through the loop, so as to
|
// Do several (8) digits each time through the loop, so as to
|
||||||
// minimize the calls to the very expensive emulated div.
|
// minimize the calls to the very expensive emulated div.
|
||||||
var radixToPower = goog.math.Long.fromNumber(Math.pow(radix, 8));
|
var radixToPower = Kotlin.Long.fromNumber(Math.pow(radix, 8));
|
||||||
|
|
||||||
var result = goog.math.Long.ZERO;
|
var result = Kotlin.Long.ZERO;
|
||||||
for (var i = 0; i < str.length; i += 8) {
|
for (var i = 0; i < str.length; i += 8) {
|
||||||
var size = Math.min(8, str.length - i);
|
var size = Math.min(8, str.length - i);
|
||||||
var value = parseInt(str.substring(i, i + size), radix);
|
var value = parseInt(str.substring(i, i + size), radix);
|
||||||
if (size < 8) {
|
if (size < 8) {
|
||||||
var power = goog.math.Long.fromNumber(Math.pow(radix, size));
|
var power = Kotlin.Long.fromNumber(Math.pow(radix, size));
|
||||||
result = result.multiply(power).add(goog.math.Long.fromNumber(value));
|
result = result.multiply(power).add(Kotlin.Long.fromNumber(value));
|
||||||
} else {
|
} else {
|
||||||
result = result.multiply(radixToPower);
|
result = result.multiply(radixToPower);
|
||||||
result = result.add(goog.math.Long.fromNumber(value));
|
result = result.add(Kotlin.Long.fromNumber(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// NOTE: the compiler should inline these constant values below and then remove
|
// NOTE: the compiler should inline these constant values below and then remove
|
||||||
// these variables, so there should be no runtime penalty for these.
|
// these variables, so there should be no runtime penalty for these.
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number used repeated below in calculations. This must appear before the
|
* Number used repeated below in calculations. This must appear before the
|
||||||
* first call to any from* function below.
|
* first call to any from* function below.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_16_DBL_ = 1 << 16;
|
Kotlin.Long.TWO_PWR_16_DBL_ = 1 << 16;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_24_DBL_ = 1 << 24;
|
Kotlin.Long.TWO_PWR_24_DBL_ = 1 << 24;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_32_DBL_ =
|
Kotlin.Long.TWO_PWR_32_DBL_ =
|
||||||
goog.math.Long.TWO_PWR_16_DBL_ * goog.math.Long.TWO_PWR_16_DBL_;
|
Kotlin.Long.TWO_PWR_16_DBL_ * Kotlin.Long.TWO_PWR_16_DBL_;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_31_DBL_ =
|
Kotlin.Long.TWO_PWR_31_DBL_ =
|
||||||
goog.math.Long.TWO_PWR_32_DBL_ / 2;
|
Kotlin.Long.TWO_PWR_32_DBL_ / 2;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_48_DBL_ =
|
Kotlin.Long.TWO_PWR_48_DBL_ =
|
||||||
goog.math.Long.TWO_PWR_32_DBL_ * goog.math.Long.TWO_PWR_16_DBL_;
|
Kotlin.Long.TWO_PWR_32_DBL_ * Kotlin.Long.TWO_PWR_16_DBL_;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_64_DBL_ =
|
Kotlin.Long.TWO_PWR_64_DBL_ =
|
||||||
goog.math.Long.TWO_PWR_32_DBL_ * goog.math.Long.TWO_PWR_32_DBL_;
|
Kotlin.Long.TWO_PWR_32_DBL_ * Kotlin.Long.TWO_PWR_32_DBL_;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_63_DBL_ =
|
Kotlin.Long.TWO_PWR_63_DBL_ =
|
||||||
goog.math.Long.TWO_PWR_64_DBL_ / 2;
|
Kotlin.Long.TWO_PWR_64_DBL_ / 2;
|
||||||
|
|
||||||
|
|
||||||
/** @type {!goog.math.Long} */
|
/** @type {!Kotlin.Long} */
|
||||||
goog.math.Long.ZERO = goog.math.Long.fromInt(0);
|
Kotlin.Long.ZERO = Kotlin.Long.fromInt(0);
|
||||||
|
|
||||||
|
|
||||||
/** @type {!goog.math.Long} */
|
/** @type {!Kotlin.Long} */
|
||||||
goog.math.Long.ONE = goog.math.Long.fromInt(1);
|
Kotlin.Long.ONE = Kotlin.Long.fromInt(1);
|
||||||
|
|
||||||
|
|
||||||
/** @type {!goog.math.Long} */
|
/** @type {!Kotlin.Long} */
|
||||||
goog.math.Long.NEG_ONE = goog.math.Long.fromInt(-1);
|
Kotlin.Long.NEG_ONE = Kotlin.Long.fromInt(-1);
|
||||||
|
|
||||||
|
|
||||||
/** @type {!goog.math.Long} */
|
/** @type {!Kotlin.Long} */
|
||||||
goog.math.Long.MAX_VALUE =
|
Kotlin.Long.MAX_VALUE =
|
||||||
goog.math.Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0);
|
Kotlin.Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0);
|
||||||
|
|
||||||
|
|
||||||
/** @type {!goog.math.Long} */
|
/** @type {!Kotlin.Long} */
|
||||||
goog.math.Long.MIN_VALUE = goog.math.Long.fromBits(0, 0x80000000 | 0);
|
Kotlin.Long.MIN_VALUE = Kotlin.Long.fromBits(0, 0x80000000 | 0);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {!goog.math.Long}
|
* @type {!Kotlin.Long}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
goog.math.Long.TWO_PWR_24_ = goog.math.Long.fromInt(1 << 24);
|
Kotlin.Long.TWO_PWR_24_ = Kotlin.Long.fromInt(1 << 24);
|
||||||
|
|
||||||
|
|
||||||
/** @return {number} The value, assuming it is a 32-bit integer. */
|
/** @return {number} The value, assuming it is a 32-bit integer. */
|
||||||
goog.math.Long.prototype.toInt = function() {
|
Kotlin.Long.prototype.toInt = function() {
|
||||||
return this.low_;
|
return this.low_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {number} The closest floating-point representation to this value. */
|
/** @return {number} The closest floating-point representation to this value. */
|
||||||
goog.math.Long.prototype.toNumber = function() {
|
Kotlin.Long.prototype.toNumber = function() {
|
||||||
return this.high_ * goog.math.Long.TWO_PWR_32_DBL_ +
|
return this.high_ * Kotlin.Long.TWO_PWR_32_DBL_ +
|
||||||
this.getLowBitsUnsigned();
|
this.getLowBitsUnsigned();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number=} opt_radix The radix in which the text should be written.
|
* @param {number=} opt_radix The radix in which the text should be written.
|
||||||
* @return {string} The textual representation of this value.
|
* @return {string} The textual representation of this value.
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.toString = function(opt_radix) {
|
Kotlin.Long.prototype.toString = function(opt_radix) {
|
||||||
var radix = opt_radix || 10;
|
var radix = opt_radix || 10;
|
||||||
if (radix < 2 || 36 < radix) {
|
if (radix < 2 || 36 < radix) {
|
||||||
throw Error('radix out of range: ' + radix);
|
throw Error('radix out of range: ' + radix);
|
||||||
@@ -290,10 +296,10 @@ goog.math.Long.prototype.toString = function(opt_radix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNegative()) {
|
if (this.isNegative()) {
|
||||||
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
if (this.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
// We need to change the Long value before it can be negated, so we remove
|
// We need to change the Long value before it can be negated, so we remove
|
||||||
// the bottom-most digit in this base and then recurse to do the rest.
|
// the bottom-most digit in this base and then recurse to do the rest.
|
||||||
var radixLong = goog.math.Long.fromNumber(radix);
|
var radixLong = Kotlin.Long.fromNumber(radix);
|
||||||
var div = this.div(radixLong);
|
var div = this.div(radixLong);
|
||||||
var rem = div.multiply(radixLong).subtract(this);
|
var rem = div.multiply(radixLong).subtract(this);
|
||||||
return div.toString(radix) + rem.toInt().toString(radix);
|
return div.toString(radix) + rem.toInt().toString(radix);
|
||||||
@@ -304,7 +310,7 @@ goog.math.Long.prototype.toString = function(opt_radix) {
|
|||||||
|
|
||||||
// Do several (6) digits each time through the loop, so as to
|
// Do several (6) digits each time through the loop, so as to
|
||||||
// minimize the calls to the very expensive emulated div.
|
// minimize the calls to the very expensive emulated div.
|
||||||
var radixToPower = goog.math.Long.fromNumber(Math.pow(radix, 6));
|
var radixToPower = Kotlin.Long.fromNumber(Math.pow(radix, 6));
|
||||||
|
|
||||||
var rem = this;
|
var rem = this;
|
||||||
var result = '';
|
var result = '';
|
||||||
@@ -323,35 +329,35 @@ goog.math.Long.prototype.toString = function(opt_radix) {
|
|||||||
result = '' + digits + result;
|
result = '' + digits + result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {number} The high 32-bits as a signed value. */
|
/** @return {number} The high 32-bits as a signed value. */
|
||||||
goog.math.Long.prototype.getHighBits = function() {
|
Kotlin.Long.prototype.getHighBits = function() {
|
||||||
return this.high_;
|
return this.high_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {number} The low 32-bits as a signed value. */
|
/** @return {number} The low 32-bits as a signed value. */
|
||||||
goog.math.Long.prototype.getLowBits = function() {
|
Kotlin.Long.prototype.getLowBits = function() {
|
||||||
return this.low_;
|
return this.low_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {number} The low 32-bits as an unsigned value. */
|
/** @return {number} The low 32-bits as an unsigned value. */
|
||||||
goog.math.Long.prototype.getLowBitsUnsigned = function() {
|
Kotlin.Long.prototype.getLowBitsUnsigned = function() {
|
||||||
return (this.low_ >= 0) ?
|
return (this.low_ >= 0) ?
|
||||||
this.low_ : goog.math.Long.TWO_PWR_32_DBL_ + this.low_;
|
this.low_ : Kotlin.Long.TWO_PWR_32_DBL_ + this.low_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number} Returns the number of bits needed to represent the absolute
|
* @return {number} Returns the number of bits needed to represent the absolute
|
||||||
* value of this Long.
|
* value of this Long.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.getNumBitsAbs = function() {
|
Kotlin.Long.prototype.getNumBitsAbs = function() {
|
||||||
if (this.isNegative()) {
|
if (this.isNegative()) {
|
||||||
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
if (this.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
return 64;
|
return 64;
|
||||||
} else {
|
} else {
|
||||||
return this.negate().getNumBitsAbs();
|
return this.negate().getNumBitsAbs();
|
||||||
@@ -365,88 +371,88 @@ goog.math.Long.prototype.getNumBitsAbs = function() {
|
|||||||
}
|
}
|
||||||
return this.high_ != 0 ? bit + 33 : bit + 1;
|
return this.high_ != 0 ? bit + 33 : bit + 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {boolean} Whether this value is zero. */
|
/** @return {boolean} Whether this value is zero. */
|
||||||
goog.math.Long.prototype.isZero = function() {
|
Kotlin.Long.prototype.isZero = function() {
|
||||||
return this.high_ == 0 && this.low_ == 0;
|
return this.high_ == 0 && this.low_ == 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {boolean} Whether this value is negative. */
|
/** @return {boolean} Whether this value is negative. */
|
||||||
goog.math.Long.prototype.isNegative = function() {
|
Kotlin.Long.prototype.isNegative = function() {
|
||||||
return this.high_ < 0;
|
return this.high_ < 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {boolean} Whether this value is odd. */
|
/** @return {boolean} Whether this value is odd. */
|
||||||
goog.math.Long.prototype.isOdd = function() {
|
Kotlin.Long.prototype.isOdd = function() {
|
||||||
return (this.low_ & 1) == 1;
|
return (this.low_ & 1) == 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {goog.math.Long} other Long to compare against.
|
* @param {Kotlin.Long} other Long to compare against.
|
||||||
* @return {boolean} Whether this Long equals the other.
|
* @return {boolean} Whether this Long equals the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.equals = function(other) {
|
Kotlin.Long.prototype.equals = function(other) {
|
||||||
return (this.high_ == other.high_) && (this.low_ == other.low_);
|
return (this.high_ == other.high_) && (this.low_ == other.low_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {goog.math.Long} other Long to compare against.
|
* @param {Kotlin.Long} other Long to compare against.
|
||||||
* @return {boolean} Whether this Long does not equal the other.
|
* @return {boolean} Whether this Long does not equal the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.notEquals = function(other) {
|
Kotlin.Long.prototype.notEquals = function(other) {
|
||||||
return (this.high_ != other.high_) || (this.low_ != other.low_);
|
return (this.high_ != other.high_) || (this.low_ != other.low_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {goog.math.Long} other Long to compare against.
|
* @param {Kotlin.Long} other Long to compare against.
|
||||||
* @return {boolean} Whether this Long is less than the other.
|
* @return {boolean} Whether this Long is less than the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.lessThan = function(other) {
|
Kotlin.Long.prototype.lessThan = function(other) {
|
||||||
return this.compare(other) < 0;
|
return this.compare(other) < 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {goog.math.Long} other Long to compare against.
|
* @param {Kotlin.Long} other Long to compare against.
|
||||||
* @return {boolean} Whether this Long is less than or equal to the other.
|
* @return {boolean} Whether this Long is less than or equal to the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.lessThanOrEqual = function(other) {
|
Kotlin.Long.prototype.lessThanOrEqual = function(other) {
|
||||||
return this.compare(other) <= 0;
|
return this.compare(other) <= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {goog.math.Long} other Long to compare against.
|
* @param {Kotlin.Long} other Long to compare against.
|
||||||
* @return {boolean} Whether this Long is greater than the other.
|
* @return {boolean} Whether this Long is greater than the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.greaterThan = function(other) {
|
Kotlin.Long.prototype.greaterThan = function(other) {
|
||||||
return this.compare(other) > 0;
|
return this.compare(other) > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {goog.math.Long} other Long to compare against.
|
* @param {Kotlin.Long} other Long to compare against.
|
||||||
* @return {boolean} Whether this Long is greater than or equal to the other.
|
* @return {boolean} Whether this Long is greater than or equal to the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.greaterThanOrEqual = function(other) {
|
Kotlin.Long.prototype.greaterThanOrEqual = function(other) {
|
||||||
return this.compare(other) >= 0;
|
return this.compare(other) >= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares this Long with the given one.
|
* Compares this Long with the given one.
|
||||||
* @param {goog.math.Long} other Long to compare against.
|
* @param {Kotlin.Long} other Long to compare against.
|
||||||
* @return {number} 0 if they are the same, 1 if the this is greater, and -1
|
* @return {number} 0 if they are the same, 1 if the this is greater, and -1
|
||||||
* if the given one is greater.
|
* if the given one is greater.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.compare = function(other) {
|
Kotlin.Long.prototype.compare = function(other) {
|
||||||
if (this.equals(other)) {
|
if (this.equals(other)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -466,25 +472,25 @@ goog.math.Long.prototype.compare = function(other) {
|
|||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {!goog.math.Long} The negation of this value. */
|
/** @return {!Kotlin.Long} The negation of this value. */
|
||||||
goog.math.Long.prototype.negate = function() {
|
Kotlin.Long.prototype.negate = function() {
|
||||||
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
if (this.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
return goog.math.Long.MIN_VALUE;
|
return Kotlin.Long.MIN_VALUE;
|
||||||
} else {
|
} else {
|
||||||
return this.not().add(goog.math.Long.ONE);
|
return this.not().add(Kotlin.Long.ONE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the sum of this and the given Long.
|
* Returns the sum of this and the given Long.
|
||||||
* @param {goog.math.Long} other Long to add to this one.
|
* @param {Kotlin.Long} other Long to add to this one.
|
||||||
* @return {!goog.math.Long} The sum of this and the given Long.
|
* @return {!Kotlin.Long} The sum of this and the given Long.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.add = function(other) {
|
Kotlin.Long.prototype.add = function(other) {
|
||||||
// Divide each number into 4 chunks of 16 bits, and then sum the chunks.
|
// Divide each number into 4 chunks of 16 bits, and then sum the chunks.
|
||||||
|
|
||||||
var a48 = this.high_ >>> 16;
|
var a48 = this.high_ >>> 16;
|
||||||
@@ -509,36 +515,36 @@ goog.math.Long.prototype.add = function(other) {
|
|||||||
c32 &= 0xFFFF;
|
c32 &= 0xFFFF;
|
||||||
c48 += a48 + b48;
|
c48 += a48 + b48;
|
||||||
c48 &= 0xFFFF;
|
c48 &= 0xFFFF;
|
||||||
return goog.math.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
|
return Kotlin.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the difference of this and the given Long.
|
* Returns the difference of this and the given Long.
|
||||||
* @param {goog.math.Long} other Long to subtract from this.
|
* @param {Kotlin.Long} other Long to subtract from this.
|
||||||
* @return {!goog.math.Long} The difference of this and the given Long.
|
* @return {!Kotlin.Long} The difference of this and the given Long.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.subtract = function(other) {
|
Kotlin.Long.prototype.subtract = function(other) {
|
||||||
return this.add(other.negate());
|
return this.add(other.negate());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the product of this and the given long.
|
* Returns the product of this and the given long.
|
||||||
* @param {goog.math.Long} other Long to multiply with this.
|
* @param {Kotlin.Long} other Long to multiply with this.
|
||||||
* @return {!goog.math.Long} The product of this and the other.
|
* @return {!Kotlin.Long} The product of this and the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.multiply = function(other) {
|
Kotlin.Long.prototype.multiply = function(other) {
|
||||||
if (this.isZero()) {
|
if (this.isZero()) {
|
||||||
return goog.math.Long.ZERO;
|
return Kotlin.Long.ZERO;
|
||||||
} else if (other.isZero()) {
|
} else if (other.isZero()) {
|
||||||
return goog.math.Long.ZERO;
|
return Kotlin.Long.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
if (this.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
return other.isOdd() ? goog.math.Long.MIN_VALUE : goog.math.Long.ZERO;
|
return other.isOdd() ? Kotlin.Long.MIN_VALUE : Kotlin.Long.ZERO;
|
||||||
} else if (other.equals(goog.math.Long.MIN_VALUE)) {
|
} else if (other.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
return this.isOdd() ? goog.math.Long.MIN_VALUE : goog.math.Long.ZERO;
|
return this.isOdd() ? Kotlin.Long.MIN_VALUE : Kotlin.Long.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNegative()) {
|
if (this.isNegative()) {
|
||||||
@@ -552,9 +558,9 @@ goog.math.Long.prototype.multiply = function(other) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If both longs are small, use float multiplication
|
// If both longs are small, use float multiplication
|
||||||
if (this.lessThan(goog.math.Long.TWO_PWR_24_) &&
|
if (this.lessThan(Kotlin.Long.TWO_PWR_24_) &&
|
||||||
other.lessThan(goog.math.Long.TWO_PWR_24_)) {
|
other.lessThan(Kotlin.Long.TWO_PWR_24_)) {
|
||||||
return goog.math.Long.fromNumber(this.toNumber() * other.toNumber());
|
return Kotlin.Long.fromNumber(this.toNumber() * other.toNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
|
// Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
|
||||||
@@ -591,42 +597,42 @@ goog.math.Long.prototype.multiply = function(other) {
|
|||||||
c32 &= 0xFFFF;
|
c32 &= 0xFFFF;
|
||||||
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
||||||
c48 &= 0xFFFF;
|
c48 &= 0xFFFF;
|
||||||
return goog.math.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
|
return Kotlin.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns this Long divided by the given one.
|
* Returns this Long divided by the given one.
|
||||||
* @param {goog.math.Long} other Long by which to divide.
|
* @param {Kotlin.Long} other Long by which to divide.
|
||||||
* @return {!goog.math.Long} This Long divided by the given one.
|
* @return {!Kotlin.Long} This Long divided by the given one.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.div = function(other) {
|
Kotlin.Long.prototype.div = function(other) {
|
||||||
if (other.isZero()) {
|
if (other.isZero()) {
|
||||||
throw Error('division by zero');
|
throw Error('division by zero');
|
||||||
} else if (this.isZero()) {
|
} else if (this.isZero()) {
|
||||||
return goog.math.Long.ZERO;
|
return Kotlin.Long.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
if (this.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
if (other.equals(goog.math.Long.ONE) ||
|
if (other.equals(Kotlin.Long.ONE) ||
|
||||||
other.equals(goog.math.Long.NEG_ONE)) {
|
other.equals(Kotlin.Long.NEG_ONE)) {
|
||||||
return goog.math.Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
return Kotlin.Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
||||||
} else if (other.equals(goog.math.Long.MIN_VALUE)) {
|
} else if (other.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
return goog.math.Long.ONE;
|
return Kotlin.Long.ONE;
|
||||||
} else {
|
} else {
|
||||||
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
|
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
|
||||||
var halfThis = this.shiftRight(1);
|
var halfThis = this.shiftRight(1);
|
||||||
var approx = halfThis.div(other).shiftLeft(1);
|
var approx = halfThis.div(other).shiftLeft(1);
|
||||||
if (approx.equals(goog.math.Long.ZERO)) {
|
if (approx.equals(Kotlin.Long.ZERO)) {
|
||||||
return other.isNegative() ? goog.math.Long.ONE : goog.math.Long.NEG_ONE;
|
return other.isNegative() ? Kotlin.Long.ONE : Kotlin.Long.NEG_ONE;
|
||||||
} else {
|
} else {
|
||||||
var rem = this.subtract(other.multiply(approx));
|
var rem = this.subtract(other.multiply(approx));
|
||||||
var result = approx.add(rem.div(other));
|
var result = approx.add(rem.div(other));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (other.equals(goog.math.Long.MIN_VALUE)) {
|
} else if (other.equals(Kotlin.Long.MIN_VALUE)) {
|
||||||
return goog.math.Long.ZERO;
|
return Kotlin.Long.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNegative()) {
|
if (this.isNegative()) {
|
||||||
@@ -644,7 +650,7 @@ goog.math.Long.prototype.div = function(other) {
|
|||||||
// into the result, and subtract it from the remainder. It is critical that
|
// into the result, and subtract it from the remainder. It is critical that
|
||||||
// the approximate value is less than or equal to the real value so that the
|
// the approximate value is less than or equal to the real value so that the
|
||||||
// remainder never becomes negative.
|
// remainder never becomes negative.
|
||||||
var res = goog.math.Long.ZERO;
|
var res = Kotlin.Long.ZERO;
|
||||||
var rem = this;
|
var rem = this;
|
||||||
while (rem.greaterThanOrEqual(other)) {
|
while (rem.greaterThanOrEqual(other)) {
|
||||||
// Approximate the result of division. This may be a little greater or
|
// Approximate the result of division. This may be a little greater or
|
||||||
@@ -658,82 +664,82 @@ goog.math.Long.prototype.div = function(other) {
|
|||||||
|
|
||||||
// Decrease the approximation until it is smaller than the remainder. Note
|
// Decrease the approximation until it is smaller than the remainder. Note
|
||||||
// that if it is too large, the product overflows and is negative.
|
// that if it is too large, the product overflows and is negative.
|
||||||
var approxRes = goog.math.Long.fromNumber(approx);
|
var approxRes = Kotlin.Long.fromNumber(approx);
|
||||||
var approxRem = approxRes.multiply(other);
|
var approxRem = approxRes.multiply(other);
|
||||||
while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
|
while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
|
||||||
approx -= delta;
|
approx -= delta;
|
||||||
approxRes = goog.math.Long.fromNumber(approx);
|
approxRes = Kotlin.Long.fromNumber(approx);
|
||||||
approxRem = approxRes.multiply(other);
|
approxRem = approxRes.multiply(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We know the answer can't be zero... and actually, zero would cause
|
// We know the answer can't be zero... and actually, zero would cause
|
||||||
// infinite recursion since we would make no progress.
|
// infinite recursion since we would make no progress.
|
||||||
if (approxRes.isZero()) {
|
if (approxRes.isZero()) {
|
||||||
approxRes = goog.math.Long.ONE;
|
approxRes = Kotlin.Long.ONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = res.add(approxRes);
|
res = res.add(approxRes);
|
||||||
rem = rem.subtract(approxRem);
|
rem = rem.subtract(approxRem);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns this Long modulo the given one.
|
* Returns this Long modulo the given one.
|
||||||
* @param {goog.math.Long} other Long by which to mod.
|
* @param {Kotlin.Long} other Long by which to mod.
|
||||||
* @return {!goog.math.Long} This Long modulo the given one.
|
* @return {!Kotlin.Long} This Long modulo the given one.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.modulo = function(other) {
|
Kotlin.Long.prototype.modulo = function(other) {
|
||||||
return this.subtract(this.div(other).multiply(other));
|
return this.subtract(this.div(other).multiply(other));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @return {!goog.math.Long} The bitwise-NOT of this value. */
|
/** @return {!Kotlin.Long} The bitwise-NOT of this value. */
|
||||||
goog.math.Long.prototype.not = function() {
|
Kotlin.Long.prototype.not = function() {
|
||||||
return goog.math.Long.fromBits(~this.low_, ~this.high_);
|
return Kotlin.Long.fromBits(~this.low_, ~this.high_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the bitwise-AND of this Long and the given one.
|
* Returns the bitwise-AND of this Long and the given one.
|
||||||
* @param {goog.math.Long} other The Long with which to AND.
|
* @param {Kotlin.Long} other The Long with which to AND.
|
||||||
* @return {!goog.math.Long} The bitwise-AND of this and the other.
|
* @return {!Kotlin.Long} The bitwise-AND of this and the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.and = function(other) {
|
Kotlin.Long.prototype.and = function(other) {
|
||||||
return goog.math.Long.fromBits(this.low_ & other.low_,
|
return Kotlin.Long.fromBits(this.low_ & other.low_,
|
||||||
this.high_ & other.high_);
|
this.high_ & other.high_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the bitwise-OR of this Long and the given one.
|
* Returns the bitwise-OR of this Long and the given one.
|
||||||
* @param {goog.math.Long} other The Long with which to OR.
|
* @param {Kotlin.Long} other The Long with which to OR.
|
||||||
* @return {!goog.math.Long} The bitwise-OR of this and the other.
|
* @return {!Kotlin.Long} The bitwise-OR of this and the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.or = function(other) {
|
Kotlin.Long.prototype.or = function(other) {
|
||||||
return goog.math.Long.fromBits(this.low_ | other.low_,
|
return Kotlin.Long.fromBits(this.low_ | other.low_,
|
||||||
this.high_ | other.high_);
|
this.high_ | other.high_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the bitwise-XOR of this Long and the given one.
|
* Returns the bitwise-XOR of this Long and the given one.
|
||||||
* @param {goog.math.Long} other The Long with which to XOR.
|
* @param {Kotlin.Long} other The Long with which to XOR.
|
||||||
* @return {!goog.math.Long} The bitwise-XOR of this and the other.
|
* @return {!Kotlin.Long} The bitwise-XOR of this and the other.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.xor = function(other) {
|
Kotlin.Long.prototype.xor = function(other) {
|
||||||
return goog.math.Long.fromBits(this.low_ ^ other.low_,
|
return Kotlin.Long.fromBits(this.low_ ^ other.low_,
|
||||||
this.high_ ^ other.high_);
|
this.high_ ^ other.high_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns this Long with bits shifted to the left by the given amount.
|
* Returns this Long with bits shifted to the left by the given amount.
|
||||||
* @param {number} numBits The number of bits by which to shift.
|
* @param {number} numBits The number of bits by which to shift.
|
||||||
* @return {!goog.math.Long} This shifted to the left by the given amount.
|
* @return {!Kotlin.Long} This shifted to the left by the given amount.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.shiftLeft = function(numBits) {
|
Kotlin.Long.prototype.shiftLeft = function(numBits) {
|
||||||
numBits &= 63;
|
numBits &= 63;
|
||||||
if (numBits == 0) {
|
if (numBits == 0) {
|
||||||
return this;
|
return this;
|
||||||
@@ -741,22 +747,22 @@ goog.math.Long.prototype.shiftLeft = function(numBits) {
|
|||||||
var low = this.low_;
|
var low = this.low_;
|
||||||
if (numBits < 32) {
|
if (numBits < 32) {
|
||||||
var high = this.high_;
|
var high = this.high_;
|
||||||
return goog.math.Long.fromBits(
|
return Kotlin.Long.fromBits(
|
||||||
low << numBits,
|
low << numBits,
|
||||||
(high << numBits) | (low >>> (32 - numBits)));
|
(high << numBits) | (low >>> (32 - numBits)));
|
||||||
} else {
|
} else {
|
||||||
return goog.math.Long.fromBits(0, low << (numBits - 32));
|
return Kotlin.Long.fromBits(0, low << (numBits - 32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns this Long with bits shifted to the right by the given amount.
|
* Returns this Long with bits shifted to the right by the given amount.
|
||||||
* @param {number} numBits The number of bits by which to shift.
|
* @param {number} numBits The number of bits by which to shift.
|
||||||
* @return {!goog.math.Long} This shifted to the right by the given amount.
|
* @return {!Kotlin.Long} This shifted to the right by the given amount.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.shiftRight = function(numBits) {
|
Kotlin.Long.prototype.shiftRight = function(numBits) {
|
||||||
numBits &= 63;
|
numBits &= 63;
|
||||||
if (numBits == 0) {
|
if (numBits == 0) {
|
||||||
return this;
|
return this;
|
||||||
@@ -764,26 +770,26 @@ goog.math.Long.prototype.shiftRight = function(numBits) {
|
|||||||
var high = this.high_;
|
var high = this.high_;
|
||||||
if (numBits < 32) {
|
if (numBits < 32) {
|
||||||
var low = this.low_;
|
var low = this.low_;
|
||||||
return goog.math.Long.fromBits(
|
return Kotlin.Long.fromBits(
|
||||||
(low >>> numBits) | (high << (32 - numBits)),
|
(low >>> numBits) | (high << (32 - numBits)),
|
||||||
high >> numBits);
|
high >> numBits);
|
||||||
} else {
|
} else {
|
||||||
return goog.math.Long.fromBits(
|
return Kotlin.Long.fromBits(
|
||||||
high >> (numBits - 32),
|
high >> (numBits - 32),
|
||||||
high >= 0 ? 0 : -1);
|
high >= 0 ? 0 : -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns this Long with bits shifted to the right by the given amount, with
|
* Returns this Long with bits shifted to the right by the given amount, with
|
||||||
* zeros placed into the new leading bits.
|
* zeros placed into the new leading bits.
|
||||||
* @param {number} numBits The number of bits by which to shift.
|
* @param {number} numBits The number of bits by which to shift.
|
||||||
* @return {!goog.math.Long} This shifted to the right by the given amount, with
|
* @return {!Kotlin.Long} This shifted to the right by the given amount, with
|
||||||
* zeros placed into the new leading bits.
|
* zeros placed into the new leading bits.
|
||||||
*/
|
*/
|
||||||
goog.math.Long.prototype.shiftRightUnsigned = function(numBits) {
|
Kotlin.Long.prototype.shiftRightUnsigned = function(numBits) {
|
||||||
numBits &= 63;
|
numBits &= 63;
|
||||||
if (numBits == 0) {
|
if (numBits == 0) {
|
||||||
return this;
|
return this;
|
||||||
@@ -791,13 +797,33 @@ goog.math.Long.prototype.shiftRightUnsigned = function(numBits) {
|
|||||||
var high = this.high_;
|
var high = this.high_;
|
||||||
if (numBits < 32) {
|
if (numBits < 32) {
|
||||||
var low = this.low_;
|
var low = this.low_;
|
||||||
return goog.math.Long.fromBits(
|
return Kotlin.Long.fromBits(
|
||||||
(low >>> numBits) | (high << (32 - numBits)),
|
(low >>> numBits) | (high << (32 - numBits)),
|
||||||
high >>> numBits);
|
high >>> numBits);
|
||||||
} else if (numBits == 32) {
|
} else if (numBits == 32) {
|
||||||
return goog.math.Long.fromBits(high, 0);
|
return Kotlin.Long.fromBits(high, 0);
|
||||||
} else {
|
} else {
|
||||||
return goog.math.Long.fromBits(high >>> (numBits - 32), 0);
|
return Kotlin.Long.fromBits(high >>> (numBits - 32), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Support for Kotlin
|
||||||
|
Kotlin.Long.prototype.equals_za3rmp$ = function (other) {
|
||||||
|
return other instanceof Kotlin.Long && this.equals(other);
|
||||||
|
};
|
||||||
|
|
||||||
|
Kotlin.Long.prototype.compareTo_za3rmp$ = Kotlin.Long.prototype.compare;
|
||||||
|
|
||||||
|
Kotlin.Long.prototype.inc = function() {
|
||||||
|
return this.add(Kotlin.Long.ONE);
|
||||||
|
};
|
||||||
|
|
||||||
|
Kotlin.Long.prototype.dec = function() {
|
||||||
|
return this.add(Kotlin.Long.NEG_ONE);
|
||||||
|
};
|
||||||
|
|
||||||
|
Kotlin.Long.prototype.valueOf = function() {
|
||||||
|
return this.toNumber();
|
||||||
|
};
|
||||||
|
}(Kotlin));
|
||||||
@@ -88,6 +88,8 @@
|
|||||||
</copy>
|
</copy>
|
||||||
<copy tofile="${basedir}/target/generated-js-library/kotlin-maps.js"
|
<copy tofile="${basedir}/target/generated-js-library/kotlin-maps.js"
|
||||||
file="${kotlin-js-lib-srcdir}/../../js.translator/testData/maps.js"/>
|
file="${kotlin-js-lib-srcdir}/../../js.translator/testData/maps.js"/>
|
||||||
|
<copy tofile="${basedir}/target/generated-js-library/kotlin-long.js"
|
||||||
|
file="${kotlin-js-lib-srcdir}/../../js.translator/testData/long.js"/>
|
||||||
<copy tofile="${basedir}/target/generated-js-library/kotlin-lib.js"
|
<copy tofile="${basedir}/target/generated-js-library/kotlin-lib.js"
|
||||||
file="${kotlin-js-lib-srcdir}/../../js.translator/testData/kotlin_lib.js"/>
|
file="${kotlin-js-lib-srcdir}/../../js.translator/testData/kotlin_lib.js"/>
|
||||||
<copy tofile="${basedir}/target/generated-js-library/kotlin-lib-ecma5.js"
|
<copy tofile="${basedir}/target/generated-js-library/kotlin-lib-ecma5.js"
|
||||||
|
|||||||
+3
@@ -42,6 +42,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class K2JSCompilerMojo extends KotlinCompileMojo {
|
public class K2JSCompilerMojo extends KotlinCompileMojo {
|
||||||
public static final String KOTLIN_JS_MAPS = "kotlin-maps.js";
|
public static final String KOTLIN_JS_MAPS = "kotlin-maps.js";
|
||||||
|
public static final String KOTLIN_JS_LONG = "kotlin-long.js";
|
||||||
public static final String KOTLIN_JS_LIB = "kotlin-lib.js";
|
public static final String KOTLIN_JS_LIB = "kotlin-lib.js";
|
||||||
public static final String KOTLIN_JS_LIB_ECMA3 = "kotlin-lib-ecma3.js";
|
public static final String KOTLIN_JS_LIB_ECMA3 = "kotlin-lib-ecma3.js";
|
||||||
public static final String KOTLIN_JS_LIB_ECMA5 = "kotlin-lib-ecma5.js";
|
public static final String KOTLIN_JS_LIB_ECMA5 = "kotlin-lib-ecma5.js";
|
||||||
@@ -91,6 +92,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
|||||||
appendFile(KOTLIN_JS_LIB_ECMA3, builder);
|
appendFile(KOTLIN_JS_LIB_ECMA3, builder);
|
||||||
appendFile(KOTLIN_JS_LIB, builder);
|
appendFile(KOTLIN_JS_LIB, builder);
|
||||||
appendFile(KOTLIN_JS_MAPS, builder);
|
appendFile(KOTLIN_JS_MAPS, builder);
|
||||||
|
appendFile(KOTLIN_JS_LONG, builder);
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
builder.append(text);
|
builder.append(text);
|
||||||
Files.write(builder.toString(), file, charset);
|
Files.write(builder.toString(), file, charset);
|
||||||
@@ -102,6 +104,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
|||||||
getLog().info("Copying kotlin JS library to " + outputKotlinJSDir);
|
getLog().info("Copying kotlin JS library to " + outputKotlinJSDir);
|
||||||
|
|
||||||
copyJsLibraryFile(KOTLIN_JS_MAPS);
|
copyJsLibraryFile(KOTLIN_JS_MAPS);
|
||||||
|
copyJsLibraryFile(KOTLIN_JS_LONG);
|
||||||
copyJsLibraryFile(KOTLIN_JS_LIB);
|
copyJsLibraryFile(KOTLIN_JS_LIB);
|
||||||
copyJsLibraryFile(KOTLIN_JS_LIB_ECMA3);
|
copyJsLibraryFile(KOTLIN_JS_LIB_ECMA3);
|
||||||
copyJsLibraryFile(KOTLIN_JS_LIB_ECMA5);
|
copyJsLibraryFile(KOTLIN_JS_LIB_ECMA5);
|
||||||
|
|||||||
Reference in New Issue
Block a user