Make Double and Float known values constant
#KT-13887
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user