Fix incorrect Double.toLong conversion for infinite values in JS
#KT-33225 Fixed
This commit is contained in:
@@ -335,13 +335,13 @@ internal fun Long.shiftRightUnsigned(numBits: Int): Long {
|
|||||||
internal fun fromInt(value: Int) = Long(value, if (value < 0) -1 else 0)
|
internal fun fromInt(value: Int) = Long(value, if (value < 0) -1 else 0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Long representing the given value, provided that it is a finite
|
* Converts this [Double] value to [Long].
|
||||||
* number. Otherwise, zero is returned.
|
* The fractional part, if any, is rounded down.
|
||||||
* @param {number} value The number in question.
|
* Returns zero if this `Double` value is `NaN`, [Long.MIN_VALUE] if it's less than `Long.MIN_VALUE`,
|
||||||
* @return {!Kotlin.Long} The corresponding Long value.
|
* [Long.MAX_VALUE] if it's bigger than `Long.MAX_VALUE`.
|
||||||
*/
|
*/
|
||||||
internal fun fromNumber(value: Double): Long {
|
internal fun fromNumber(value: Double): Long {
|
||||||
if (value.isNaN() || !value.isFinite()) {
|
if (value.isNaN()) {
|
||||||
return ZERO;
|
return ZERO;
|
||||||
} else if (value <= -TWO_PWR_63_DBL_) {
|
} else if (value <= -TWO_PWR_63_DBL_) {
|
||||||
return MIN_VALUE;
|
return MIN_VALUE;
|
||||||
|
|||||||
@@ -94,13 +94,15 @@ Kotlin.Long.fromInt = function(value) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Long representing the given value, provided that it is a finite
|
* Converts this number value to `Long`.
|
||||||
* number. Otherwise, zero is returned.
|
* The fractional part, if any, is rounded down.
|
||||||
|
* Returns zero if this `Double` value is `NaN`, `Long.MIN_VALUE` if it's less than `Long.MIN_VALUE`,
|
||||||
|
* `Long.MAX_VALUE` if it's bigger than `Long.MAX_VALUE`.
|
||||||
* @param {number} value The number in question.
|
* @param {number} value The number in question.
|
||||||
* @return {!Kotlin.Long} The corresponding Long value.
|
* @return {!Kotlin.Long} The corresponding Long value.
|
||||||
*/
|
*/
|
||||||
Kotlin.Long.fromNumber = function(value) {
|
Kotlin.Long.fromNumber = function(value) {
|
||||||
if (isNaN(value) || !isFinite(value)) {
|
if (isNaN(value)) {
|
||||||
return Kotlin.Long.ZERO;
|
return Kotlin.Long.ZERO;
|
||||||
} else if (value <= -Kotlin.Long.TWO_PWR_63_DBL_) {
|
} else if (value <= -Kotlin.Long.TWO_PWR_63_DBL_) {
|
||||||
return Kotlin.Long.MIN_VALUE;
|
return Kotlin.Long.MIN_VALUE;
|
||||||
|
|||||||
Reference in New Issue
Block a user