diff --git a/compiler/testData/codegen/bytecodeText/companion/floatingPointCompanionAccess.kt b/compiler/testData/codegen/bytecodeText/companion/floatingPointCompanionAccess.kt index aa1bce3422f..d8f8c21d9fd 100644 --- a/compiler/testData/codegen/bytecodeText/companion/floatingPointCompanionAccess.kt +++ b/compiler/testData/codegen/bytecodeText/companion/floatingPointCompanionAccess.kt @@ -13,10 +13,10 @@ fun main() { val finfn = Float.NEGATIVE_INFINITY } -// 5 GETSTATIC kotlin/jvm/internal/DoubleCompanionObject.INSTANCE -// 5 GETSTATIC kotlin/jvm/internal/FloatCompanionObject.INSTANCE -// 2 getMAX_VALUE -// 2 getMIN_VALUE -// 2 getNaN -// 2 getPOSITIVE_INFINITY -// 2 getNEGATIVE_INFINITY \ No newline at end of file +// 0 GETSTATIC kotlin/jvm/internal/DoubleCompanionObject.INSTANCE +// 0 GETSTATIC kotlin/jvm/internal/FloatCompanionObject.INSTANCE +// 0 getMAX_VALUE +// 0 getMIN_VALUE +// 0 getNaN +// 0 getPOSITIVE_INFINITY +// 0 getNEGATIVE_INFINITY \ No newline at end of file diff --git a/core/builtins/native/kotlin/Primitives.kt b/core/builtins/native/kotlin/Primitives.kt index 1234526cc22..f1c1963815b 100644 --- a/core/builtins/native/kotlin/Primitives.kt +++ b/core/builtins/native/kotlin/Primitives.kt @@ -898,27 +898,27 @@ public class Float private constructor() : Number(), Comparable { /** * A constant holding the smallest *positive* nonzero value of Float. */ - public val MIN_VALUE: Float + public const val MIN_VALUE: Float = 1.4E-45F /** * A constant holding the largest positive finite value of Float. */ - public val MAX_VALUE: Float + public const val MAX_VALUE: Float = 3.4028235E38F /** * A constant holding the positive infinity value of Float. */ - public val POSITIVE_INFINITY: Float + public const val POSITIVE_INFINITY: Float = 1.0F/0.0F /** * A constant holding the negative infinity value of Float. */ - public val NEGATIVE_INFINITY: Float + public const val NEGATIVE_INFINITY: Float = -1.0F/0.0F /** * A constant holding the "not a number" value of Float. */ - public val NaN: Float + public const val NaN: Float = -(0.0F/0.0F) } /** @@ -1099,27 +1099,27 @@ public class Double private constructor() : Number(), Comparable { /** * A constant holding the smallest *positive* nonzero value of Double. */ - public val MIN_VALUE: Double + public const val MIN_VALUE: Double = 4.9E-324 /** * A constant holding the largest positive finite value of Double. */ - public val MAX_VALUE: Double + public const val MAX_VALUE: Double = 1.7976931348623157E308 /** * A constant holding the positive infinity value of Double. */ - public val POSITIVE_INFINITY: Double + public const val POSITIVE_INFINITY: Double = 1.0/0.0 /** * A constant holding the negative infinity value of Double. */ - public val NEGATIVE_INFINITY: Double + public const val NEGATIVE_INFINITY: Double = -1.0/0.0 /** * A constant holding the "not a number" value of Double. */ - public val NaN: Double + public const val NaN: Double = -(0.0/0.0) } /** diff --git a/generators/builtins/primitives.kt b/generators/builtins/primitives.kt index 247acc35252..a0a3b3f4eef 100644 --- a/generators/builtins/primitives.kt +++ b/generators/builtins/primitives.kt @@ -47,8 +47,8 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { PrimitiveType.BYTE -> listOf(java.lang.Byte.MIN_VALUE, java.lang.Byte.MAX_VALUE) PrimitiveType.SHORT -> listOf(java.lang.Short.MIN_VALUE, java.lang.Short.MAX_VALUE) PrimitiveType.LONG -> listOf((java.lang.Long.MIN_VALUE + 1).toString() + "L - 1L", java.lang.Long.MAX_VALUE.toString() + "L") -// PrimitiveType.DOUBLE -> listOf(java.lang.Double.MIN_VALUE, java.lang.Double.MAX_VALUE, "1.0/0.0", "-1.0/0.0", "0.0/0.0") -// PrimitiveType.FLOAT -> listOf(java.lang.Float.MIN_VALUE, java.lang.Float.MAX_VALUE, "1.0F/0.0F", "-1.0F/0.0F", "0.0F/0.0F").map { it as? String ?: "${it}F" } + PrimitiveType.DOUBLE -> listOf(java.lang.Double.MIN_VALUE, java.lang.Double.MAX_VALUE, "1.0/0.0", "-1.0/0.0", "-(0.0/0.0)") + PrimitiveType.FLOAT -> listOf(java.lang.Float.MIN_VALUE, java.lang.Float.MAX_VALUE, "1.0F/0.0F", "-1.0F/0.0F", "-(0.0F/0.0F)").map { it as? String ?: "${it}F" } else -> throw IllegalArgumentException("type: $type") } @@ -60,32 +60,32 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { out.print(" companion object {") if (kind == PrimitiveType.FLOAT || kind == PrimitiveType.DOUBLE) { - //val (minValue, maxValue, posInf, negInf, nan) = primitiveConstants(kind) + val (minValue, maxValue, posInf, negInf, nan) = primitiveConstants(kind) out.println(""" /** * A constant holding the smallest *positive* nonzero value of $className. */ - public val MIN_VALUE: $className + public const val MIN_VALUE: $className = $minValue /** * A constant holding the largest positive finite value of $className. */ - public val MAX_VALUE: $className + public const val MAX_VALUE: $className = $maxValue /** * A constant holding the positive infinity value of $className. */ - public val POSITIVE_INFINITY: $className + public const val POSITIVE_INFINITY: $className = $posInf /** * A constant holding the negative infinity value of $className. */ - public val NEGATIVE_INFINITY: $className + public const val NEGATIVE_INFINITY: $className = $negInf /** * A constant holding the "not a number" value of $className. */ - public val NaN: $className""") + public const val NaN: $className = $nan""") } if (kind == PrimitiveType.INT || kind == PrimitiveType.LONG || kind == PrimitiveType.SHORT || kind == PrimitiveType.BYTE) { val (minValue, maxValue) = primitiveConstants(kind) diff --git a/libraries/stdlib/js-ir/builtins/Primitives.kt b/libraries/stdlib/js-ir/builtins/Primitives.kt index 34356b6e022..d21afaf6fe4 100644 --- a/libraries/stdlib/js-ir/builtins/Primitives.kt +++ b/libraries/stdlib/js-ir/builtins/Primitives.kt @@ -680,32 +680,27 @@ public class Float private constructor() : Number(), Comparable { /** * A constant holding the smallest *positive* nonzero value of Float. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val MIN_VALUE: Float + public const val MIN_VALUE: Float = 1.4E-45F /** * A constant holding the largest positive finite value of Float. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val MAX_VALUE: Float + public const val MAX_VALUE: Float = 3.4028235E38F /** * A constant holding the positive infinity value of Float. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val POSITIVE_INFINITY: Float + public const val POSITIVE_INFINITY: Float = 1.0F/0.0F /** * A constant holding the negative infinity value of Float. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val NEGATIVE_INFINITY: Float + public const val NEGATIVE_INFINITY: Float = -1.0F/0.0F /** * A constant holding the "not a number" value of Float. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val NaN: Float + public const val NaN: Float = -(0.0F/0.0F) } /** @@ -890,32 +885,27 @@ public class Double private constructor() : Number(), Comparable { /** * A constant holding the smallest *positive* nonzero value of Double. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val MIN_VALUE: Double + public const val MIN_VALUE: Double = 4.9E-324 /** * A constant holding the largest positive finite value of Double. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val MAX_VALUE: Double + public const val MAX_VALUE: Double = 1.7976931348623157E308 /** * A constant holding the positive infinity value of Double. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val POSITIVE_INFINITY: Double + public const val POSITIVE_INFINITY: Double = 1.0/0.0 /** * A constant holding the negative infinity value of Double. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val NEGATIVE_INFINITY: Double + public const val NEGATIVE_INFINITY: Double = -1.0/0.0 /** * A constant holding the "not a number" value of Double. */ - @Suppress("MUST_BE_INITIALIZED_OR_BE_ABSTRACT") - public val NaN: Double + public const val NaN: Double = -(0.0/0.0) } /** diff --git a/libraries/stdlib/js/runtime/primitiveCompanionObjects.kt b/libraries/stdlib/js/runtime/primitiveCompanionObjects.kt index 15c4ec1a17a..664fd4dd8c1 100644 --- a/libraries/stdlib/js/runtime/primitiveCompanionObjects.kt +++ b/libraries/stdlib/js/runtime/primitiveCompanionObjects.kt @@ -8,37 +8,37 @@ package kotlin.js.internal @JsName("DoubleCompanionObject") internal object DoubleCompanionObject { @JsName("MIN_VALUE") - val MIN_VALUE: Double = js("Number.MIN_VALUE") + const val MIN_VALUE: Double = 4.9E-324 @JsName("MAX_VALUE") - val MAX_VALUE: Double = js("Number.MAX_VALUE") + const val MAX_VALUE: Double = 1.7976931348623157E308 @JsName("POSITIVE_INFINITY") - val POSITIVE_INFINITY: Double = js("Number.POSITIVE_INFINITY") + const val POSITIVE_INFINITY: Double = 1.0/0.0 @JsName("NEGATIVE_INFINITY") - val NEGATIVE_INFINITY: Double = js("Number.NEGATIVE_INFINITY") + const val NEGATIVE_INFINITY: Double = -1.0/0.0 @JsName("NaN") - val NaN: Double = js("Number.NaN") + const val NaN: Double = -(0.0/0.0) } @JsName("FloatCompanionObject") internal object FloatCompanionObject { @JsName("MIN_VALUE") - val MIN_VALUE: Float = js("Number.MIN_VALUE") + const val MIN_VALUE: Float = 1.4E-45F @JsName("MAX_VALUE") - val MAX_VALUE: Float = js("Number.MAX_VALUE") + const val MAX_VALUE: Float = 3.4028235E38F @JsName("POSITIVE_INFINITY") - val POSITIVE_INFINITY: Float = js("Number.POSITIVE_INFINITY") + const val POSITIVE_INFINITY: Float = 1.0F/0.0F @JsName("NEGATIVE_INFINITY") - val NEGATIVE_INFINITY: Float = js("Number.NEGATIVE_INFINITY") + const val NEGATIVE_INFINITY: Float = -1.0F/0.0F @JsName("NaN") - val NaN: Float = js("Number.NaN") + const val NaN: Float = -(0.0F/0.0F) } @JsName("IntCompanionObject") diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt index c0818c881ac..ea355251d4b 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/PrimitiveCompanionObjects.kt @@ -6,19 +6,33 @@ package kotlin.jvm.internal internal object DoubleCompanionObject { - val MIN_VALUE: Double = java.lang.Double.MIN_VALUE - val MAX_VALUE: Double = java.lang.Double.MAX_VALUE - val POSITIVE_INFINITY: Double = java.lang.Double.POSITIVE_INFINITY - val NEGATIVE_INFINITY: Double = java.lang.Double.NEGATIVE_INFINITY - val NaN: Double = java.lang.Double.NaN + const val MIN_VALUE: Double = java.lang.Double.MIN_VALUE + const val MAX_VALUE: Double = java.lang.Double.MAX_VALUE + const val POSITIVE_INFINITY: Double = java.lang.Double.POSITIVE_INFINITY + const val NEGATIVE_INFINITY: Double = java.lang.Double.NEGATIVE_INFINITY + const val NaN: Double = java.lang.Double.NaN + + // for binary compatibility with pre 1.4 + fun getMIN_VALUE(): Double = java.lang.Double.MIN_VALUE + fun getMAX_VALUE(): Double = java.lang.Double.MAX_VALUE + fun getPOSITIVE_INFINITY(): Double = java.lang.Double.POSITIVE_INFINITY + fun getNEGATIVE_INFINITY(): Double = java.lang.Double.NEGATIVE_INFINITY + fun getNaN(): Double = java.lang.Double.NaN } internal object FloatCompanionObject { - val MIN_VALUE: Float = java.lang.Float.MIN_VALUE - val MAX_VALUE: Float = java.lang.Float.MAX_VALUE - val POSITIVE_INFINITY: Float = java.lang.Float.POSITIVE_INFINITY - val NEGATIVE_INFINITY: Float = java.lang.Float.NEGATIVE_INFINITY - val NaN: Float = java.lang.Float.NaN + const val MIN_VALUE: Float = java.lang.Float.MIN_VALUE + const val MAX_VALUE: Float = java.lang.Float.MAX_VALUE + const val POSITIVE_INFINITY: Float = java.lang.Float.POSITIVE_INFINITY + const val NEGATIVE_INFINITY: Float = java.lang.Float.NEGATIVE_INFINITY + const val NaN: Float = java.lang.Float.NaN + + // for binary compatibility with pre 1.4 + fun getMIN_VALUE(): Float = java.lang.Float.MIN_VALUE + fun getMAX_VALUE(): Float = java.lang.Float.MAX_VALUE + fun getPOSITIVE_INFINITY(): Float = java.lang.Float.POSITIVE_INFINITY + fun getNEGATIVE_INFINITY(): Float = java.lang.Float.NEGATIVE_INFINITY + fun getNaN(): Float = java.lang.Float.NaN } internal object IntCompanionObject { diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index b1426a31096..bede34fd228 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -3313,6 +3313,11 @@ public final class kotlin/jvm/internal/CollectionToArray { public final class kotlin/jvm/internal/DoubleCompanionObject { public static final field INSTANCE Lkotlin/jvm/internal/DoubleCompanionObject; + public static final field MAX_VALUE D + public static final field MIN_VALUE D + public static final field NEGATIVE_INFINITY D + public static final field NaN D + public static final field POSITIVE_INFINITY D public final fun getMAX_VALUE ()D public final fun getMIN_VALUE ()D public final fun getNEGATIVE_INFINITY ()D @@ -3333,6 +3338,11 @@ public final class kotlin/jvm/internal/EnumCompanionObject { public final class kotlin/jvm/internal/FloatCompanionObject { public static final field INSTANCE Lkotlin/jvm/internal/FloatCompanionObject; + public static final field MAX_VALUE F + public static final field MIN_VALUE F + public static final field NEGATIVE_INFINITY F + public static final field NaN F + public static final field POSITIVE_INFINITY F public final fun getMAX_VALUE ()F public final fun getMIN_VALUE ()F public final fun getNEGATIVE_INFINITY ()F