Add SIZE_BITS and SIZE_BYTES constants to Double and Float

#KT-29182
This commit is contained in:
Ilya Gorbunov
2019-10-08 19:42:42 +03:00
parent 1c93911279
commit f3fc1197ae
6 changed files with 72 additions and 3 deletions
+24
View File
@@ -919,6 +919,18 @@ public class Float private constructor() : Number(), Comparable<Float> {
* A constant holding the "not a number" value of Float. * A constant holding the "not a number" value of Float.
*/ */
public const val NaN: Float = -(0.0F/0.0F) public const val NaN: Float = -(0.0F/0.0F)
/**
* The number of bytes used to represent an instance of Float in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BYTES: Int = 4
/**
* The number of bits used to represent an instance of Float in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BITS: Int = 32
} }
/** /**
@@ -1120,6 +1132,18 @@ public class Double private constructor() : Number(), Comparable<Double> {
* A constant holding the "not a number" value of Double. * A constant holding the "not a number" value of Double.
*/ */
public const val NaN: Double = -(0.0/0.0) public const val NaN: Double = -(0.0/0.0)
/**
* The number of bytes used to represent an instance of Double in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BYTES: Int = 8
/**
* The number of bits used to represent an instance of Double in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BITS: Int = 64
} }
/** /**
+4 -3
View File
@@ -100,18 +100,19 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
*/ */
public const val MAX_VALUE: $className = $maxValue""") public const val MAX_VALUE: $className = $maxValue""")
} }
if (kind.isIntegral) { if (kind.isIntegral || kind.isFloatingPoint) {
val sizeSince = if (kind.isFloatingPoint) "1.4" else "1.3"
out.println(""" out.println("""
/** /**
* The number of bytes used to represent an instance of $className in a binary form. * The number of bytes used to represent an instance of $className in a binary form.
*/ */
@SinceKotlin("1.3") @SinceKotlin("$sizeSince")
public const val SIZE_BYTES: Int = ${kind.byteSize} public const val SIZE_BYTES: Int = ${kind.byteSize}
/** /**
* The number of bits used to represent an instance of $className in a binary form. * The number of bits used to represent an instance of $className in a binary form.
*/ */
@SinceKotlin("1.3") @SinceKotlin("$sizeSince")
public const val SIZE_BITS: Int = ${kind.bitSize}""") public const val SIZE_BITS: Int = ${kind.bitSize}""")
} }
out.println(""" }""") out.println(""" }""")
@@ -701,6 +701,18 @@ public class Float private constructor() : Number(), Comparable<Float> {
* A constant holding the "not a number" value of Float. * A constant holding the "not a number" value of Float.
*/ */
public const val NaN: Float = -(0.0F/0.0F) public const val NaN: Float = -(0.0F/0.0F)
/**
* The number of bytes used to represent an instance of Float in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BYTES: Int = 4
/**
* The number of bits used to represent an instance of Float in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BITS: Int = 32
} }
/** /**
@@ -906,6 +918,18 @@ public class Double private constructor() : Number(), Comparable<Double> {
* A constant holding the "not a number" value of Double. * A constant holding the "not a number" value of Double.
*/ */
public const val NaN: Double = -(0.0/0.0) public const val NaN: Double = -(0.0/0.0)
/**
* The number of bytes used to represent an instance of Double in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BYTES: Int = 8
/**
* The number of bits used to represent an instance of Double in a binary form.
*/
@SinceKotlin("1.4")
public const val SIZE_BITS: Int = 64
} }
/** /**
@@ -21,6 +21,12 @@ internal object DoubleCompanionObject {
@JsName("NaN") @JsName("NaN")
const val NaN: Double = -(0.0/0.0) const val NaN: Double = -(0.0/0.0)
@JsName("SIZE_BYTES")
const val SIZE_BYTES = 8
@JsName("SIZE_BITS")
const val SIZE_BITS = 64
} }
@JsName("FloatCompanionObject") @JsName("FloatCompanionObject")
@@ -39,6 +45,12 @@ internal object FloatCompanionObject {
@JsName("NaN") @JsName("NaN")
const val NaN: Float = -(0.0F/0.0F) const val NaN: Float = -(0.0F/0.0F)
@JsName("SIZE_BYTES")
const val SIZE_BYTES = 4
@JsName("SIZE_BITS")
const val SIZE_BITS = 32
} }
@JsName("IntCompanionObject") @JsName("IntCompanionObject")
@@ -11,6 +11,8 @@ internal object DoubleCompanionObject {
const val POSITIVE_INFINITY: Double = java.lang.Double.POSITIVE_INFINITY const val POSITIVE_INFINITY: Double = java.lang.Double.POSITIVE_INFINITY
const val NEGATIVE_INFINITY: Double = java.lang.Double.NEGATIVE_INFINITY const val NEGATIVE_INFINITY: Double = java.lang.Double.NEGATIVE_INFINITY
const val NaN: Double = java.lang.Double.NaN const val NaN: Double = java.lang.Double.NaN
const val SIZE_BYTES: Int = 8
const val SIZE_BITS: Int = SIZE_BYTES * 8
// for binary compatibility with pre 1.4 // for binary compatibility with pre 1.4
fun getMIN_VALUE(): Double = java.lang.Double.MIN_VALUE fun getMIN_VALUE(): Double = java.lang.Double.MIN_VALUE
@@ -26,6 +28,8 @@ internal object FloatCompanionObject {
const val POSITIVE_INFINITY: Float = java.lang.Float.POSITIVE_INFINITY const val POSITIVE_INFINITY: Float = java.lang.Float.POSITIVE_INFINITY
const val NEGATIVE_INFINITY: Float = java.lang.Float.NEGATIVE_INFINITY const val NEGATIVE_INFINITY: Float = java.lang.Float.NEGATIVE_INFINITY
const val NaN: Float = java.lang.Float.NaN const val NaN: Float = java.lang.Float.NaN
const val SIZE_BYTES: Int = 4
const val SIZE_BITS: Int = SIZE_BYTES * 8
// for binary compatibility with pre 1.4 // for binary compatibility with pre 1.4
fun getMIN_VALUE(): Float = java.lang.Float.MIN_VALUE fun getMIN_VALUE(): Float = java.lang.Float.MIN_VALUE
@@ -3318,6 +3318,8 @@ public final class kotlin/jvm/internal/DoubleCompanionObject {
public static final field NEGATIVE_INFINITY D public static final field NEGATIVE_INFINITY D
public static final field NaN D public static final field NaN D
public static final field POSITIVE_INFINITY D public static final field POSITIVE_INFINITY D
public static final field SIZE_BITS I
public static final field SIZE_BYTES I
public final fun getMAX_VALUE ()D public final fun getMAX_VALUE ()D
public final fun getMIN_VALUE ()D public final fun getMIN_VALUE ()D
public final fun getNEGATIVE_INFINITY ()D public final fun getNEGATIVE_INFINITY ()D
@@ -3343,6 +3345,8 @@ public final class kotlin/jvm/internal/FloatCompanionObject {
public static final field NEGATIVE_INFINITY F public static final field NEGATIVE_INFINITY F
public static final field NaN F public static final field NaN F
public static final field POSITIVE_INFINITY F public static final field POSITIVE_INFINITY F
public static final field SIZE_BITS I
public static final field SIZE_BYTES I
public final fun getMAX_VALUE ()F public final fun getMAX_VALUE ()F
public final fun getMIN_VALUE ()F public final fun getMIN_VALUE ()F
public final fun getNEGATIVE_INFINITY ()F public final fun getNEGATIVE_INFINITY ()F