withSign

expect fun Double.withSign(sign: Double): Double(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(3.14)) // 3.14
println(3.14.withSign(-3.14)) // -3.14
println((-3.14).withSign(-3.14)) // -3.14
println((-3.14).withSign(0.0)) // 3.14
println(Double.NaN.withSign(-1.0)) // NaN 
   //sampleEnd
}

expect fun Double.withSign(sign: Int): Double(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(100)) // 3.14
println(3.14.withSign(-100)) // -3.14
println((-3.14).withSign(-100)) // -3.14
println((-3.14).withSign(0)) // 3.14
println(Double.NaN.withSign(-1)) // NaN 
   //sampleEnd
}

expect fun Float.withSign(sign: Float): Float(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(3.14f)) // 3.14
println(3.14f.withSign(-3.14f)) // -3.14
println((-3.14f).withSign(-3.14f)) // -3.14
println((-3.14f).withSign(0.0f)) // 3.14
println(Float.NaN.withSign(-1.0f)) // NaN 
   //sampleEnd
}

expect fun Float.withSign(sign: Int): Float(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(100)) // 3.14
println(3.14f.withSign(-100)) // -3.14
println((-3.14f).withSign(-100)) // -3.14
println((-3.14f).withSign(0)) // 3.14
println(Float.NaN.withSign(-1)) // NaN 
   //sampleEnd
}
actual fun Double.withSign(sign: Double): Double(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(3.14)) // 3.14
println(3.14.withSign(-3.14)) // -3.14
println((-3.14).withSign(-3.14)) // -3.14
println((-3.14).withSign(0.0)) // 3.14
println(Double.NaN.withSign(-1.0)) // NaN 
   //sampleEnd
}

actual inline fun Double.withSign(sign: Int): Double(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(100)) // 3.14
println(3.14.withSign(-100)) // -3.14
println((-3.14).withSign(-100)) // -3.14
println((-3.14).withSign(0)) // 3.14
println(Double.NaN.withSign(-1)) // NaN 
   //sampleEnd
}

actual inline fun Float.withSign(sign: Float): Float(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(3.14f)) // 3.14
println(3.14f.withSign(-3.14f)) // -3.14
println((-3.14f).withSign(-3.14f)) // -3.14
println((-3.14f).withSign(0.0f)) // 3.14
println(Float.NaN.withSign(-1.0f)) // NaN 
   //sampleEnd
}

actual inline fun Float.withSign(sign: Int): Float(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(100)) // 3.14
println(3.14f.withSign(-100)) // -3.14
println((-3.14f).withSign(-100)) // -3.14
println((-3.14f).withSign(0)) // 3.14
println(Float.NaN.withSign(-1)) // NaN 
   //sampleEnd
}
actual inline fun Double.withSign(sign: Double): Double(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(3.14)) // 3.14
println(3.14.withSign(-3.14)) // -3.14
println((-3.14).withSign(-3.14)) // -3.14
println((-3.14).withSign(0.0)) // 3.14
println(Double.NaN.withSign(-1.0)) // NaN 
   //sampleEnd
}

actual inline fun Double.withSign(sign: Int): Double(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(100)) // 3.14
println(3.14.withSign(-100)) // -3.14
println((-3.14).withSign(-100)) // -3.14
println((-3.14).withSign(0)) // 3.14
println(Double.NaN.withSign(-1)) // NaN 
   //sampleEnd
}

actual inline fun Float.withSign(sign: Float): Float(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(3.14f)) // 3.14
println(3.14f.withSign(-3.14f)) // -3.14
println((-3.14f).withSign(-3.14f)) // -3.14
println((-3.14f).withSign(0.0f)) // 3.14
println(Float.NaN.withSign(-1.0f)) // NaN 
   //sampleEnd
}

actual inline fun Float.withSign(sign: Int): Float(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(100)) // 3.14
println(3.14f.withSign(-100)) // -3.14
println((-3.14f).withSign(-100)) // -3.14
println((-3.14f).withSign(0)) // 3.14
println(Float.NaN.withSign(-1)) // NaN 
   //sampleEnd
}
actual external fun Double.withSign(sign: Double): Double(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(3.14)) // 3.14
println(3.14.withSign(-3.14)) // -3.14
println((-3.14).withSign(-3.14)) // -3.14
println((-3.14).withSign(0.0)) // 3.14
println(Double.NaN.withSign(-1.0)) // NaN 
   //sampleEnd
}

actual fun Double.withSign(sign: Int): Double(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(100)) // 3.14
println(3.14.withSign(-100)) // -3.14
println((-3.14).withSign(-100)) // -3.14
println((-3.14).withSign(0)) // 3.14
println(Double.NaN.withSign(-1)) // NaN 
   //sampleEnd
}

actual external fun Float.withSign(sign: Float): Float(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(3.14f)) // 3.14
println(3.14f.withSign(-3.14f)) // -3.14
println((-3.14f).withSign(-3.14f)) // -3.14
println((-3.14f).withSign(0.0f)) // 3.14
println(Float.NaN.withSign(-1.0f)) // NaN 
   //sampleEnd
}

actual fun Float.withSign(sign: Int): Float(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(100)) // 3.14
println(3.14f.withSign(-100)) // -3.14
println((-3.14f).withSign(-100)) // -3.14
println((-3.14f).withSign(0)) // 3.14
println(Float.NaN.withSign(-1)) // NaN 
   //sampleEnd
}
actual fun Double.withSign(sign: Double): Double(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(3.14)) // 3.14
println(3.14.withSign(-3.14)) // -3.14
println((-3.14).withSign(-3.14)) // -3.14
println((-3.14).withSign(0.0)) // 3.14
println(Double.NaN.withSign(-1.0)) // NaN 
   //sampleEnd
}

actual fun Double.withSign(sign: Int): Double(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(100)) // 3.14
println(3.14.withSign(-100)) // -3.14
println((-3.14).withSign(-100)) // -3.14
println((-3.14).withSign(0)) // 3.14
println(Double.NaN.withSign(-1)) // NaN 
   //sampleEnd
}

actual fun Float.withSign(sign: Float): Float(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(3.14f)) // 3.14
println(3.14f.withSign(-3.14f)) // -3.14
println((-3.14f).withSign(-3.14f)) // -3.14
println((-3.14f).withSign(0.0f)) // 3.14
println(Float.NaN.withSign(-1.0f)) // NaN 
   //sampleEnd
}

actual fun Float.withSign(sign: Int): Float(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(100)) // 3.14
println(3.14f.withSign(-100)) // -3.14
println((-3.14f).withSign(-100)) // -3.14
println((-3.14f).withSign(0)) // 3.14
println(Float.NaN.withSign(-1)) // NaN 
   //sampleEnd
}
actual fun Double.withSign(sign: Double): Double(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(3.14)) // 3.14
println(3.14.withSign(-3.14)) // -3.14
println((-3.14).withSign(-3.14)) // -3.14
println((-3.14).withSign(0.0)) // 3.14
println(Double.NaN.withSign(-1.0)) // NaN 
   //sampleEnd
}

actual fun Double.withSign(sign: Int): Double(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14.withSign(100)) // 3.14
println(3.14.withSign(-100)) // -3.14
println((-3.14).withSign(-100)) // -3.14
println((-3.14).withSign(0)) // 3.14
println(Double.NaN.withSign(-1)) // NaN 
   //sampleEnd
}

actual fun Float.withSign(sign: Float): Float(source)

Returns this value with the sign bit same as of the sign value.

If sign is NaN the sign of the result is undefined.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(3.14f)) // 3.14
println(3.14f.withSign(-3.14f)) // -3.14
println((-3.14f).withSign(-3.14f)) // -3.14
println((-3.14f).withSign(0.0f)) // 3.14
println(Float.NaN.withSign(-1.0f)) // NaN 
   //sampleEnd
}

actual fun Float.withSign(sign: Int): Float(source)

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(3.14f.withSign(100)) // 3.14
println(3.14f.withSign(-100)) // -3.14
println((-3.14f).withSign(-100)) // -3.14
println((-3.14f).withSign(0)) // 3.14
println(Float.NaN.withSign(-1)) // NaN 
   //sampleEnd
}