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
@@ -701,6 +701,18 @@ public class Float private constructor() : Number(), Comparable<Float> {
* A constant holding the "not a number" value of Float.
*/
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.
*/
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")
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")
@@ -39,6 +45,12 @@ internal object FloatCompanionObject {
@JsName("NaN")
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")
@@ -11,6 +11,8 @@ internal object DoubleCompanionObject {
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
const val SIZE_BYTES: Int = 8
const val SIZE_BITS: Int = SIZE_BYTES * 8
// for binary compatibility with pre 1.4
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 NEGATIVE_INFINITY: Float = java.lang.Float.NEGATIVE_INFINITY
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
fun getMIN_VALUE(): Float = java.lang.Float.MIN_VALUE