JS: Provide MIN_VALUE and MAX_VALUE member constants for Int, Long, Short and Byte companion objects.
JVM: Make MIN_VALUE and MAX_VALUE not an extension but member constant properties of Int, Long, Short and Byte companion objects.
This commit is contained in:
@@ -15,14 +15,6 @@
|
||||
*/
|
||||
package kotlin.jvm
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value an `Int` can have, -2^31.
|
||||
*/
|
||||
public val Int.Companion.MIN_VALUE: Int get() = java.lang.Integer.MIN_VALUE
|
||||
/**
|
||||
* A constant holding the maximum value an `Int` can have, 2^31-1.
|
||||
*/
|
||||
public val Int.Companion.MAX_VALUE: Int get() = java.lang.Integer.MAX_VALUE
|
||||
|
||||
/**
|
||||
* A constant holding the smallest positive nonzero value of type `Double`, 2^-1074.
|
||||
@@ -41,30 +33,3 @@ public val Float.Companion.MIN_VALUE: Float get() = java.lang.Float.MIN_VALUE
|
||||
* * A constant holding the largest positive finite value of type `Float`, (2-2^-23)*2^127.
|
||||
*/
|
||||
public val Float.Companion.MAX_VALUE: Float get() = java.lang.Float.MAX_VALUE
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value a `Long` can have, -2^63.
|
||||
*/
|
||||
public val Long.Companion.MIN_VALUE: Long get() = java.lang.Long.MIN_VALUE
|
||||
/**
|
||||
* A constant holding the maximum value a `Long` can have, 2^63-1.
|
||||
*/
|
||||
public val Long.Companion.MAX_VALUE: Long get() = java.lang.Long.MAX_VALUE
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value a `Short` can have, -2^15.
|
||||
*/
|
||||
public val Short.Companion.MIN_VALUE: Short get() = java.lang.Short.MIN_VALUE
|
||||
/**
|
||||
* A constant holding the maximum value a `Short` can have, 2^15-1.
|
||||
*/
|
||||
public val Short.Companion.MAX_VALUE: Short get() = java.lang.Short.MAX_VALUE
|
||||
|
||||
/**
|
||||
* A constant holding the minimum value a `Byte` can have, -128.
|
||||
*/
|
||||
public val Byte.Companion.MIN_VALUE: Byte get() = java.lang.Byte.MIN_VALUE
|
||||
/**
|
||||
* A constant holding the maximum value a `Byte` can have, 127.
|
||||
*/
|
||||
public val Byte.Companion.MAX_VALUE: Byte get() = java.lang.Byte.MAX_VALUE
|
||||
@@ -5,6 +5,40 @@ import kotlin.test.*
|
||||
|
||||
class NumbersTest {
|
||||
|
||||
|
||||
test fun intMinMaxValues() {
|
||||
assertTrue(Int.MIN_VALUE < 0)
|
||||
assertTrue(Int.MAX_VALUE > 0)
|
||||
|
||||
// overflow behavior
|
||||
// doesn't hold for JS Number
|
||||
// assertEquals(Int.MIN_VALUE, Int.MAX_VALUE + 1)
|
||||
}
|
||||
|
||||
test fun longMinMaxValues() {
|
||||
assertTrue(Long.MIN_VALUE < 0)
|
||||
assertTrue(Long.MAX_VALUE > 0)
|
||||
// overflow behavior
|
||||
assertEquals(Long.MIN_VALUE, Long.MAX_VALUE + 1)
|
||||
assertEquals(Long.MAX_VALUE, Long.MIN_VALUE - 1)
|
||||
}
|
||||
|
||||
test fun shortMinMaxValues() {
|
||||
assertTrue(Short.MIN_VALUE < 0)
|
||||
assertTrue(Short.MAX_VALUE > 0)
|
||||
// overflow behavior
|
||||
assertEquals(Short.MIN_VALUE, (Short.MAX_VALUE + 1).toShort())
|
||||
assertEquals(Short.MAX_VALUE, (Short.MIN_VALUE - 1).toShort())
|
||||
}
|
||||
|
||||
test fun byteMinMaxValues() {
|
||||
assertTrue(Byte.MIN_VALUE < 0)
|
||||
assertTrue(Byte.MAX_VALUE > 0)
|
||||
// overflow behavior
|
||||
assertEquals(Byte.MIN_VALUE, (Byte.MAX_VALUE + 1).toByte())
|
||||
assertEquals(Byte.MAX_VALUE, (Byte.MIN_VALUE - 1).toByte())
|
||||
}
|
||||
|
||||
test fun doubleProperties() {
|
||||
for (value in listOf(1.0, 0.0))
|
||||
doTestNumber(value)
|
||||
|
||||
Reference in New Issue
Block a user