Annotate new API with SinceKotlin, provide common headers

#KT-4900

Also update binary API dump.
This commit is contained in:
Ilya Gorbunov
2017-07-28 18:27:08 +03:00
parent a69a583c64
commit 57f5791e70
5 changed files with 1105 additions and 0 deletions
+82
View File
@@ -23,8 +23,10 @@ import kotlin.js.Math as nativeMath
// constants, can't use them from nativeMath as they are not constants there
/** Ratio of the circumference of a circle to its diameter, approximately 3.14159. */
@SinceKotlin("1.2")
public const val PI: Double = 3.141592653589793
/** Base of the natural logarithms, approximately 2.71828. */
@SinceKotlin("1.2")
public const val E: Double = 2.718281828459045
// ================ Double Math ========================================
@@ -35,6 +37,7 @@ public const val E: Double = 2.718281828459045
*
* - `sin(NaN|+Inf|-Inf)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sin(a: Double): Double = nativeMath.sin(a)
@@ -44,6 +47,7 @@ public inline fun sin(a: Double): Double = nativeMath.sin(a)
*
* - `cos(NaN|+Inf|-Inf)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cos(a: Double): Double = nativeMath.cos(a)
@@ -53,6 +57,7 @@ public inline fun cos(a: Double): Double = nativeMath.cos(a)
*
* - `tan(NaN|+Inf|-Inf)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tan(a: Double): Double = nativeMath.tan(a)
@@ -63,6 +68,7 @@ public inline fun tan(a: Double): Double = nativeMath.tan(a)
* Special cases:
* - `asin(v)` is `NaN`, when `abs(v) > 1` or v is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun asin(a: Double): Double = nativeMath.asin(a)
@@ -73,6 +79,7 @@ public inline fun asin(a: Double): Double = nativeMath.asin(a)
* Special cases:
* - `acos(v)` is `NaN`, when `abs(v) > 1` or v is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun acos(a: Double): Double = nativeMath.acos(a)
@@ -83,6 +90,7 @@ public inline fun acos(a: Double): Double = nativeMath.acos(a)
* Special cases:
* - `atan(NaN)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan(a: Double): Double = nativeMath.atan(a)
@@ -102,6 +110,7 @@ public inline fun atan(a: Double): Double = nativeMath.atan(a)
* - `atan2(-Inf, x)` is `-PI/2` for finite `x`
* - `atan2(NaN, x)` and `atan2(y, NaN)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x)
@@ -114,6 +123,7 @@ public inline fun atan2(y: Double, x: Double): Double = nativeMath.atan2(y, x)
* - `sinh(+Inf)` is `+Inf`
* - `sinh(-Inf)` is `-Inf`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sinh(a: Double): Double = nativeMath.sinh(a)
@@ -125,6 +135,7 @@ public inline fun sinh(a: Double): Double = nativeMath.sinh(a)
* - `cosh(NaN)` is `NaN`
* - `cosh(+Inf|-Inf)` is `+Inf`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cosh(a: Double): Double = nativeMath.cosh(a)
@@ -137,6 +148,7 @@ public inline fun cosh(a: Double): Double = nativeMath.cosh(a)
* - `tanh(+Inf)` is `1.0`
* - `tanh(-Inf)` is `-1.0`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tanh(a: Double): Double = nativeMath.tanh(a)
@@ -147,6 +159,7 @@ public inline fun tanh(a: Double): Double = nativeMath.tanh(a)
* - returns `+Inf` if any of arguments is infinite
* - returns `NaN` if any of arguments is `NaN` and the other is not infinite
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y)
@@ -156,6 +169,7 @@ public inline fun hypot(x: Double, y: Double): Double = nativeMath.hypot(x, y)
* Special cases:
* - `sqrt(x)` is `NaN` when `x < 0` or `x` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sqrt(a: Double): Double = nativeMath.sqrt(a)
@@ -167,6 +181,7 @@ public inline fun sqrt(a: Double): Double = nativeMath.sqrt(a)
* - `exp(+Inf)` is `+Inf`
* - `exp(-Inf)` is `0.0`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun exp(a: Double): Double = nativeMath.exp(a)
@@ -182,6 +197,7 @@ public inline fun exp(a: Double): Double = nativeMath.exp(a)
*
* @see [exp] function.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun expm1(a: Double): Double = nativeMath.expm1(a)
@@ -195,6 +211,7 @@ public inline fun expm1(a: Double): Double = nativeMath.expm1(a)
* - `log(+Inf, b)` is `+Inf` for `b > 1` and `-Inf` for `b < 1`
* - `log(0.0, b)` is `-Inf` for `b > 1` and `+Inf` for `b > 1`
*/
@SinceKotlin("1.2")
public fun log(a: Double, base: Double): Double {
if (base <= 0.0 || base == 1.0) return Double.NaN
return nativeMath.log(a) / nativeMath.log(base)
@@ -209,6 +226,7 @@ public fun log(a: Double, base: Double): Double {
* - `ln(+Inf)` is `+Inf`
* - `ln(0.0)` is `-Inf`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln(a: Double): Double = nativeMath.log(a)
@@ -217,6 +235,7 @@ public inline fun ln(a: Double): Double = nativeMath.log(a)
*
* @see [ln] function for special cases.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log10(a: Double): Double = nativeMath.log10(a)
@@ -225,6 +244,7 @@ public inline fun log10(a: Double): Double = nativeMath.log10(a)
*
* @see [ln] function for special cases.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log2(a: Double): Double = nativeMath.log2(a)
@@ -242,6 +262,7 @@ public inline fun log2(a: Double): Double = nativeMath.log2(a)
* @see [ln] function.
* @see [expm1] function
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln1p(a: Double): Double = nativeMath.log1p(a)
@@ -253,6 +274,7 @@ public inline fun ln1p(a: Double): Double = nativeMath.log1p(a)
* Special cases:
* - `ceil(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ceil(a: Double): Double = nativeMath.ceil(a).unsafeCast<Double>() // TODO: Remove unsafe cast after removing public js.math
@@ -264,6 +286,7 @@ public inline fun ceil(a: Double): Double = nativeMath.ceil(a).unsafeCast<Double
* Special cases:
* - `floor(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun floor(a: Double): Double = nativeMath.floor(a).unsafeCast<Double>()
@@ -275,6 +298,7 @@ public inline fun floor(a: Double): Double = nativeMath.floor(a).unsafeCast<Doub
* Special cases:
* - `truncate(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun truncate(a: Double): Double = nativeMath.trunc(a)
@@ -284,6 +308,7 @@ public inline fun truncate(a: Double): Double = nativeMath.trunc(a)
* Special cases:
* - `round(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
public fun round(a: Double): Double {
if (a % 0.5 != 0.0) {
return nativeMath.round(a).unsafeCast<Double>()
@@ -300,6 +325,7 @@ public fun round(a: Double): Double {
*
* @see absoluteValue extension property for [Double]
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun abs(a: Double): Double = nativeMath.abs(a)
@@ -312,6 +338,7 @@ public inline fun abs(a: Double): Double = nativeMath.abs(a)
* Special case:
* - `sign(NaN)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sign(a: Double): Double = nativeMath.sign(a)
@@ -321,6 +348,7 @@ public inline fun sign(a: Double): Double = nativeMath.sign(a)
*
* If either value is `NaN`, then the result is `NaN`.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b)
/**
@@ -328,6 +356,7 @@ public inline fun min(a: Double, b: Double): Double = nativeMath.min(a, b)
*
* If either value is `NaN`, then the result is `NaN`.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b)
@@ -344,6 +373,7 @@ public inline fun max(a: Double, b: Double): Double = nativeMath.max(a, b)
* - `x.pow(Inf)` is `NaN` for `abs(x) == 1.0`
* - `x.pow(y)` is `NaN` for `x < 0` and `y` is finite and not an integer
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Double.pow(other: Double): Double = nativeMath.pow(this, other)
@@ -352,6 +382,7 @@ public inline fun Double.pow(other: Double): Double = nativeMath.pow(this, other
*
* See the other overload of [pow] for details.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Double.pow(other: Int): Double = nativeMath.pow(this, other.toDouble())
@@ -363,6 +394,7 @@ public inline fun Double.pow(other: Int): Double = nativeMath.pow(this, other.to
*
* @see abs function
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Double.absoluteValue: Double get() = nativeMath.abs(this)
@@ -375,6 +407,7 @@ public inline val Double.absoluteValue: Double get() = nativeMath.abs(this)
* Special case:
* - `NaN.sign` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Double.sign: Double get() = nativeMath.sign(this)
@@ -383,6 +416,7 @@ public inline val Double.sign: Double get() = nativeMath.sign(this)
*
* If [sign] is `NaN` the sign of the result is undefined.
*/
@SinceKotlin("1.2")
public fun Double.withSign(sign: Double): Double =
this.absoluteValue * when(sign) {
0.0 -> sign(1 / sign)
@@ -392,6 +426,7 @@ public fun Double.withSign(sign: Double): Double =
/**
* Returns this value with the sign bit same as of the [sign] value.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDouble())
@@ -405,6 +440,7 @@ public inline fun Double.withSign(sign: Int): Double = this.withSign(sign.toDoub
*
* @throws IllegalArgumentException when this value is `NaN`
*/
@SinceKotlin("1.2")
public fun Double.roundToInt(): Int = when {
isNaN() -> throw IllegalArgumentException("Cannot round NaN value.")
this > Int.MAX_VALUE -> Int.MAX_VALUE
@@ -422,6 +458,7 @@ public fun Double.roundToInt(): Int = when {
*
* @throws IllegalArgumentException when this value is `NaN`
*/
@SinceKotlin("1.2")
public fun Double.roundToLong(): Long = when {
isNaN() -> throw IllegalArgumentException("Cannot round NaN value.")
this > Long.MAX_VALUE -> Long.MAX_VALUE
@@ -440,6 +477,7 @@ public fun Double.roundToLong(): Long = when {
*
* - `sin(NaN|+Inf|-Inf)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sin(a: Float): Float = nativeMath.sin(a.toDouble()).toFloat()
@@ -449,6 +487,7 @@ public inline fun sin(a: Float): Float = nativeMath.sin(a.toDouble()).toFloat()
*
* - `cos(NaN|+Inf|-Inf)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cos(a: Float): Float = nativeMath.cos(a.toDouble()).toFloat()
@@ -458,6 +497,7 @@ public inline fun cos(a: Float): Float = nativeMath.cos(a.toDouble()).toFloat()
*
* - `tan(NaN|+Inf|-Inf)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tan(a: Float): Float = nativeMath.tan(a.toDouble()).toFloat()
@@ -468,6 +508,7 @@ public inline fun tan(a: Float): Float = nativeMath.tan(a.toDouble()).toFloat()
* Special cases:
* - `asin(v)` is `NaN`, when `abs(v) > 1` or v is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun asin(a: Float): Float = nativeMath.asin(a.toDouble()).toFloat()
@@ -478,6 +519,7 @@ public inline fun asin(a: Float): Float = nativeMath.asin(a.toDouble()).toFloat(
* Special cases:
* - `acos(v)` is `NaN`, when `abs(v) > 1` or v is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun acos(a: Float): Float = nativeMath.acos(a.toDouble()).toFloat()
@@ -488,6 +530,7 @@ public inline fun acos(a: Float): Float = nativeMath.acos(a.toDouble()).toFloat(
* Special cases:
* - `atan(NaN)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan(a: Float): Float = nativeMath.atan(a.toDouble()).toFloat()
@@ -507,6 +550,7 @@ public inline fun atan(a: Float): Float = nativeMath.atan(a.toDouble()).toFloat(
* - `atan2(-Inf, x)` is `-PI/2` for finite `x`
* - `atan2(NaN, x)` and `atan2(y, NaN)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble(), x.toDouble()).toFloat()
@@ -519,6 +563,7 @@ public inline fun atan2(y: Float, x: Float): Float = nativeMath.atan2(y.toDouble
* - `sinh(+Inf)` is `+Inf`
* - `sinh(-Inf)` is `-Inf`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sinh(a: Float): Float = nativeMath.sinh(a.toDouble()).toFloat()
@@ -530,6 +575,7 @@ public inline fun sinh(a: Float): Float = nativeMath.sinh(a.toDouble()).toFloat(
* - `cosh(NaN)` is `NaN`
* - `cosh(+Inf|-Inf)` is `+Inf`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun cosh(a: Float): Float = nativeMath.cosh(a.toDouble()).toFloat()
@@ -542,6 +588,7 @@ public inline fun cosh(a: Float): Float = nativeMath.cosh(a.toDouble()).toFloat(
* - `tanh(+Inf)` is `1.0`
* - `tanh(-Inf)` is `-1.0`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun tanh(a: Float): Float = nativeMath.tanh(a.toDouble()).toFloat()
@@ -552,6 +599,7 @@ public inline fun tanh(a: Float): Float = nativeMath.tanh(a.toDouble()).toFloat(
* - returns `+Inf` if any of arguments is infinite
* - returns `NaN` if any of arguments is `NaN` and the other is not infinite
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble(), y.toDouble()).toFloat()
@@ -561,6 +609,7 @@ public inline fun hypot(x: Float, y: Float): Float = nativeMath.hypot(x.toDouble
* Special cases:
* - `sqrt(x)` is `NaN` when `x < 0` or `x` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sqrt(a: Float): Float = nativeMath.sqrt(a.toDouble()).toFloat()
@@ -572,6 +621,7 @@ public inline fun sqrt(a: Float): Float = nativeMath.sqrt(a.toDouble()).toFloat(
* - `exp(+Inf)` is `+Inf`
* - `exp(-Inf)` is `0.0`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun exp(a: Float): Float = nativeMath.exp(a.toDouble()).toFloat()
@@ -587,6 +637,7 @@ public inline fun exp(a: Float): Float = nativeMath.exp(a.toDouble()).toFloat()
*
* @see [exp] function.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun expm1(a: Float): Float = nativeMath.expm1(a.toDouble()).toFloat()
@@ -600,6 +651,7 @@ public inline fun expm1(a: Float): Float = nativeMath.expm1(a.toDouble()).toFloa
* - `log(+Inf, b)` is `+Inf` for `b > 1` and `-Inf` for `b < 1`
* - `log(0.0, b)` is `-Inf` for `b > 1` and `+Inf` for `b > 1`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log(a: Float, base: Float): Float = log(a.toDouble(), base.toDouble()).toFloat()
@@ -612,6 +664,7 @@ public inline fun log(a: Float, base: Float): Float = log(a.toDouble(), base.toD
* - `ln(+Inf)` is `+Inf`
* - `ln(0.0)` is `-Inf`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln(a: Float): Float = nativeMath.log(a.toDouble()).toFloat()
@@ -620,6 +673,7 @@ public inline fun ln(a: Float): Float = nativeMath.log(a.toDouble()).toFloat()
*
* @see [ln] function for special cases.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log10(a: Float): Float = nativeMath.log10(a.toDouble()).toFloat()
@@ -628,6 +682,7 @@ public inline fun log10(a: Float): Float = nativeMath.log10(a.toDouble()).toFloa
*
* @see [ln] function for special cases.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun log2(a: Float): Float = nativeMath.log2(a.toDouble()).toFloat()
@@ -645,6 +700,7 @@ public inline fun log2(a: Float): Float = nativeMath.log2(a.toDouble()).toFloat(
* @see [ln] function
* @see [expm1] function
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ln1p(a: Float): Float = nativeMath.log1p(a.toDouble()).toFloat()
@@ -656,6 +712,7 @@ public inline fun ln1p(a: Float): Float = nativeMath.log1p(a.toDouble()).toFloat
* Special cases:
* - `ceil(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun ceil(a: Float): Float = nativeMath.ceil(a.toDouble()).toFloat()
@@ -667,6 +724,7 @@ public inline fun ceil(a: Float): Float = nativeMath.ceil(a.toDouble()).toFloat(
* Special cases:
* - `floor(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun floor(a: Float): Float = nativeMath.floor(a.toDouble()).toFloat()
@@ -678,6 +736,7 @@ public inline fun floor(a: Float): Float = nativeMath.floor(a.toDouble()).toFloa
* Special cases:
* - `truncate(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun truncate(a: Float): Float = truncate(a.toDouble()).toFloat()
@@ -687,6 +746,7 @@ public inline fun truncate(a: Float): Float = truncate(a.toDouble()).toFloat()
* Special cases:
* - `round(x)` is `x` where `x` is `NaN` or `+Inf` or `-Inf` or already a mathematical integer.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun round(a: Float): Float = round(a.toDouble()).toFloat()
@@ -699,6 +759,7 @@ public inline fun round(a: Float): Float = round(a.toDouble()).toFloat()
*
* @see absoluteValue extension property for [Float]
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun abs(a: Float): Float = nativeMath.abs(a.toDouble()).toFloat()
@@ -711,6 +772,7 @@ public inline fun abs(a: Float): Float = nativeMath.abs(a.toDouble()).toFloat()
* Special case:
* - `sign(NaN)` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun sign(a: Float): Float = nativeMath.sign(a.toDouble()).toFloat()
@@ -721,6 +783,7 @@ public inline fun sign(a: Float): Float = nativeMath.sign(a.toDouble()).toFloat(
*
* If either value is `NaN`, then the result is `NaN`.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b)
/**
@@ -728,6 +791,7 @@ public inline fun min(a: Float, b: Float): Float = nativeMath.min(a, b)
*
* If either value is `NaN`, then the result is `NaN`.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b)
@@ -745,6 +809,7 @@ public inline fun max(a: Float, b: Float): Float = nativeMath.max(a, b)
* - `x.pow(Inf)` is `NaN` for `abs(x) == 1.0`
* - `x.pow(y)` is `NaN` for `x < 0` and `y` is finite and not an integer
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.pow(other: Float): Float = nativeMath.pow(this.toDouble(), other.toDouble()).toFloat()
@@ -753,6 +818,7 @@ public inline fun Float.pow(other: Float): Float = nativeMath.pow(this.toDouble(
*
* See the other overload of [pow] for details.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.pow(other: Int): Float = nativeMath.pow(this.toDouble(), other.toDouble()).toFloat()
@@ -764,6 +830,7 @@ public inline fun Float.pow(other: Int): Float = nativeMath.pow(this.toDouble(),
*
* @see abs function
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDouble()).toFloat()
@@ -776,6 +843,7 @@ public inline val Float.absoluteValue: Float get() = nativeMath.abs(this.toDoubl
* Special case:
* - `NaN.sign` is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toFloat()
@@ -784,11 +852,13 @@ public inline val Float.sign: Float get() = nativeMath.sign(this.toDouble()).toF
*
* If [sign] is `NaN` the sign of the result is undefined.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.withSign(sign: Float): Float = this.toDouble().withSign(sign.toDouble()).toFloat()
/**
* Returns this value with the sign bit same as of the [sign] value.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(sign.toDouble()).toFloat()
@@ -803,6 +873,7 @@ public inline fun Float.withSign(sign: Int): Float = this.toDouble().withSign(si
*
* @throws IllegalArgumentException when this value is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.roundToInt(): Int = toDouble().roundToInt()
@@ -816,6 +887,7 @@ public inline fun Float.roundToInt(): Int = toDouble().roundToInt()
*
* @throws IllegalArgumentException when this value is `NaN`
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun Float.roundToLong(): Long = toDouble().roundToLong()
@@ -831,17 +903,20 @@ public inline fun Float.roundToLong(): Long = toDouble().roundToLong()
* @see absoluteValue extension property for [Int]
*/
// TODO: remove manual 'or' when KT-19290 is fixed
@SinceKotlin("1.2")
public fun abs(a: Int): Int = if (a < 0) (-a or 0) else a
/**
* Returns the smaller of two values.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun min(a: Int, b: Int): Int = minOf(a, b)
/**
* Returns the greater of two values.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun max(a: Int, b: Int): Int = maxOf(a, b)
@@ -853,6 +928,7 @@ public inline fun max(a: Int, b: Int): Int = maxOf(a, b)
*
* @see abs function
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Int.absoluteValue: Int get() = abs(this)
@@ -862,6 +938,7 @@ public inline val Int.absoluteValue: Int get() = abs(this)
* - `0` if the value is zero,
* - `1` if the value is positive
*/
@SinceKotlin("1.2")
public val Int.sign: Int get() = when {
this < 0 -> -1
this > 0 -> 1
@@ -878,17 +955,20 @@ public val Int.sign: Int get() = when {
*
* @see absoluteValue extension property for [Long]
*/
@SinceKotlin("1.2")
public fun abs(a: Long): Long = if (a < 0) -a else a
/**
* Returns the smaller of two values.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun min(a: Long, b: Long): Long = minOf(a, b)
/**
* Returns the greater of two values.
*/
@SinceKotlin("1.2")
@InlineOnly
public inline fun max(a: Long, b: Long): Long = maxOf(a, b)
@@ -900,6 +980,7 @@ public inline fun max(a: Long, b: Long): Long = maxOf(a, b)
*
* @see abs function
*/
@SinceKotlin("1.2")
@InlineOnly
public inline val Long.absoluteValue: Long get() = abs(this)
@@ -909,6 +990,7 @@ public inline val Long.absoluteValue: Long get() = abs(this)
* - `0` if the value is zero,
* - `1` if the value is positive
*/
@SinceKotlin("1.2")
public val Long.sign: Int get() = when {
this < 0 -> -1
this > 0 -> 1