From 432828a2dbfe85d3b08ce8d6c88e8b7a6b728ec7 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Tue, 13 Aug 2019 08:26:15 +0300 Subject: [PATCH] Clarify floating-point to integral conversion rounding behaviour --- core/builtins/native/kotlin/Primitives.kt | 8 ++++---- generators/builtins/primitives.kt | 2 +- generators/builtins/unsignedTypes.kt | 2 +- libraries/stdlib/js-ir/runtime/longjs.kt | 2 +- libraries/stdlib/js-v1/src/js/long.js | 2 +- libraries/stdlib/unsigned/src/kotlin/UInt.kt | 4 ++-- libraries/stdlib/unsigned/src/kotlin/ULong.kt | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/builtins/native/kotlin/Primitives.kt b/core/builtins/native/kotlin/Primitives.kt index a866647c7e4..38a390ff7a5 100644 --- a/core/builtins/native/kotlin/Primitives.kt +++ b/core/builtins/native/kotlin/Primitives.kt @@ -1160,7 +1160,7 @@ public class Float private constructor() : Number(), Comparable { /** * Converts this [Float] value to [Int]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `Float` value is `NaN`, [Int.MIN_VALUE] if it's less than `Int.MIN_VALUE`, * [Int.MAX_VALUE] if it's bigger than `Int.MAX_VALUE`. */ @@ -1168,7 +1168,7 @@ public class Float private constructor() : Number(), Comparable { /** * Converts this [Float] value to [Long]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `Float` 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`. */ @@ -1378,7 +1378,7 @@ public class Double private constructor() : Number(), Comparable { /** * Converts this [Double] value to [Int]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `Double` value is `NaN`, [Int.MIN_VALUE] if it's less than `Int.MIN_VALUE`, * [Int.MAX_VALUE] if it's bigger than `Int.MAX_VALUE`. */ @@ -1386,7 +1386,7 @@ public class Double private constructor() : Number(), Comparable { /** * Converts this [Double] value to [Long]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * 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`. */ diff --git a/generators/builtins/primitives.kt b/generators/builtins/primitives.kt index e9ae1c47edc..b8a5c0f8cfd 100644 --- a/generators/builtins/primitives.kt +++ b/generators/builtins/primitives.kt @@ -241,7 +241,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { """ } else { """ - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `$thisName` value is `NaN`, [$otherName.MIN_VALUE] if it's less than `$otherName.MIN_VALUE`, * [$otherName.MAX_VALUE] if it's bigger than `$otherName.MAX_VALUE`. */ diff --git a/generators/builtins/unsignedTypes.kt b/generators/builtins/unsignedTypes.kt index 955143fde7c..a2351fdc2f7 100644 --- a/generators/builtins/unsignedTypes.kt +++ b/generators/builtins/unsignedTypes.kt @@ -349,7 +349,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns /** * Converts this [$otherName] value to [$className]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `$otherName` value is negative or `NaN`, [$className.MAX_VALUE] if it's bigger than `$className.MAX_VALUE`. */ """.trimIndent() diff --git a/libraries/stdlib/js-ir/runtime/longjs.kt b/libraries/stdlib/js-ir/runtime/longjs.kt index 7758c3e9246..4a19044daab 100644 --- a/libraries/stdlib/js-ir/runtime/longjs.kt +++ b/libraries/stdlib/js-ir/runtime/longjs.kt @@ -336,7 +336,7 @@ internal fun fromInt(value: Int) = Long(value, if (value < 0) -1 else 0) /** * Converts this [Double] value to [Long]. - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * 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`. */ diff --git a/libraries/stdlib/js-v1/src/js/long.js b/libraries/stdlib/js-v1/src/js/long.js index 369679c22b3..e963a21bbc0 100644 --- a/libraries/stdlib/js-v1/src/js/long.js +++ b/libraries/stdlib/js-v1/src/js/long.js @@ -95,7 +95,7 @@ Kotlin.Long.fromInt = function(value) { /** * Converts this number value to `Long`. - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * 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. diff --git a/libraries/stdlib/unsigned/src/kotlin/UInt.kt b/libraries/stdlib/unsigned/src/kotlin/UInt.kt index ecfdf36fd25..e092aed823b 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UInt.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UInt.kt @@ -313,7 +313,7 @@ public inline fun Long.toUInt(): UInt = UInt(this.toInt()) /** * Converts this [Float] value to [UInt]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `Float` value is negative or `NaN`, [UInt.MAX_VALUE] if it's bigger than `UInt.MAX_VALUE`. */ @SinceKotlin("1.3") @@ -323,7 +323,7 @@ public inline fun Float.toUInt(): UInt = doubleToUInt(this.toDouble()) /** * Converts this [Double] value to [UInt]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `Double` value is negative or `NaN`, [UInt.MAX_VALUE] if it's bigger than `UInt.MAX_VALUE`. */ @SinceKotlin("1.3") diff --git a/libraries/stdlib/unsigned/src/kotlin/ULong.kt b/libraries/stdlib/unsigned/src/kotlin/ULong.kt index 34615c2d8fe..70d044135ba 100644 --- a/libraries/stdlib/unsigned/src/kotlin/ULong.kt +++ b/libraries/stdlib/unsigned/src/kotlin/ULong.kt @@ -316,7 +316,7 @@ public inline fun Long.toULong(): ULong = ULong(this) /** * Converts this [Float] value to [ULong]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `Float` value is negative or `NaN`, [ULong.MAX_VALUE] if it's bigger than `ULong.MAX_VALUE`. */ @SinceKotlin("1.3") @@ -326,7 +326,7 @@ public inline fun Float.toULong(): ULong = doubleToULong(this.toDouble()) /** * Converts this [Double] value to [ULong]. * - * The fractional part, if any, is rounded down. + * The fractional part, if any, is rounded down towards zero. * Returns zero if this `Double` value is negative or `NaN`, [ULong.MAX_VALUE] if it's bigger than `ULong.MAX_VALUE`. */ @SinceKotlin("1.3")