Float

Common
JVM
JS
Native
1.0
For Common, JVM, JS

Represents a single-precision 32-bit IEEE 754 floating point number. On the JVM, non-nullable values of this type are represented as values of the primitive type float.

For Native

Represents a single-precision 32-bit IEEE 754 floating point number.

Functions

Common
JVM
JS
Native
1.0

compareTo

Compares this value with the specified value for order. Returns zero if this value is equal to the specified other value, a negative number if it's less than other, or a positive number if it's greater than other.

operator fun compareTo(other: Byte): Int
operator fun compareTo(other: Short): Int
operator fun compareTo(other: Int): Int
operator fun compareTo(other: Long): Int
operator fun compareTo(other: Float): Int
operator fun compareTo(other: Double): Int
Common
JVM
JS
Native
1.0

dec

Returns this value decremented by one.

operator fun dec(): Float
Common
JVM
JS
Native
1.0

div

Divides this value by the other value.

operator fun div(other: Byte): Float
operator fun div(other: Short): Float
operator fun div(other: Int): Float
operator fun div(other: Long): Float
operator fun div(other: Float): Float
operator fun div(other: Double): Double

equals

Native
1.3
fun equals(other: Float): Boolean
Common
JVM
JS
Native
1.0

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

fun equals(other: Any?): Boolean
Native
1.3

hashCode

Returns a hash code value for the object. The general contract of hashCode is:

fun hashCode(): Int
Common
JVM
JS
Native
1.0

inc

Returns this value incremented by one.

operator fun inc(): Float
Common
JVM
JS
Native
1.0

minus

Subtracts the other value from this value.

operator fun minus(other: Byte): Float
operator fun minus(other: Short): Float
operator fun minus(other: Int): Float
operator fun minus(other: Long): Float
operator fun minus(other: Float): Float
operator fun minus(other: Double): Double
Common
JVM
JS
Native
1.0

plus

Adds the other value to this value.

operator fun plus(other: Byte): Float
operator fun plus(other: Short): Float
operator fun plus(other: Int): Float
operator fun plus(other: Long): Float
operator fun plus(other: Float): Float
operator fun plus(other: Double): Double
Common
JVM
JS
Native
1.1

rem

Calculates the remainder of truncating division of this value (dividend) by the other value (divisor).

operator fun rem(other: Byte): Float
operator fun rem(other: Short): Float
operator fun rem(other: Int): Float
operator fun rem(other: Long): Float
operator fun rem(other: Float): Float
operator fun rem(other: Double): Double
Common
JVM
JS
Native
1.0

times

Multiplies this value by the other value.

operator fun times(other: Byte): Float
operator fun times(other: Short): Float
operator fun times(other: Int): Float
operator fun times(other: Long): Float
operator fun times(other: Float): Float
operator fun times(other: Double): Double
Common
JVM
JS
Native
1.0

toByte

Converts this Float value to Byte.

fun toByte(): Byte
Common
JVM
JS
Native
1.0

toChar

Converts this Float value to Char.

fun toChar(): Char
Common
JVM
JS
Native
1.0

toDouble

Converts this Float value to Double.

fun toDouble(): Double
Common
JVM
JS
Native
1.0

toFloat

Returns this value.

fun toFloat(): Float
Common
JVM
JS
Native
1.0

toInt

Converts this Float value to Int.

fun toInt(): Int
Common
JVM
JS
Native
1.0

toLong

Converts this Float value to Long.

fun toLong(): Long
Common
JVM
JS
Native
1.0

toShort

Converts this Float value to Short.

fun toShort(): Short
Common
JVM
JS
Native
1.0

toString

Returns a string representation of the object.

fun toString(): String
Common
JVM
JS
Native
1.0

unaryMinus

Returns the negative of this value.

operator fun unaryMinus(): Float
Common
JVM
JS
Native
1.0

unaryPlus

Returns this value.

operator fun unaryPlus(): Float

Companion Object Properties

Common
JVM
JS
Native
1.0

MAX_VALUE

A constant holding the largest positive finite value of Float.

const val MAX_VALUE: Float
Common
JVM
JS
Native
1.0

MIN_VALUE

A constant holding the smallest positive nonzero value of Float.

const val MIN_VALUE: Float
Common
JVM
JS
Native
1.0

NaN

A constant holding the "not a number" value of Float.

const val NaN: Float
Common
JVM
JS
Native
1.0

NEGATIVE_INFINITY

A constant holding the negative infinity value of Float.

const val NEGATIVE_INFINITY: Float
Common
JVM
JS
Native
1.0

POSITIVE_INFINITY

A constant holding the positive infinity value of Float.

const val POSITIVE_INFINITY: Float
Common
JVM
JS
Native
1.4

SIZE_BITS

The number of bits used to represent an instance of Float in a binary form.

const val SIZE_BITS: Int
Common
JVM
JS
Native
1.4

SIZE_BYTES

The number of bytes used to represent an instance of Float in a binary form.

const val SIZE_BYTES: Int

Extension Functions

Common
JVM
JS
Native
1.0

coerceAtLeast

Ensures that this value is not less than the specified minimumValue.

fun Float.coerceAtLeast(minimumValue: Float): Float
fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T
Common
JVM
JS
Native
1.0

coerceAtMost

Ensures that this value is not greater than the specified maximumValue.

fun Float.coerceAtMost(maximumValue: Float): Float
fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T
Common
JVM
JS
Native
1.0

coerceIn

Ensures that this value lies in the specified range minimumValue..maximumValue.

fun Float.coerceIn(
    minimumValue: Float,
    maximumValue: Float
): Float
fun <T : Comparable<T>> T.coerceIn(
    minimumValue: T?,
    maximumValue: T?
): T

Ensures that this value lies in the specified range.

fun <T : Comparable<T>> T.coerceIn(
    range: ClosedFloatingPointRange<T>
): T
fun <T : Comparable<T>> T.coerceIn(range: ClosedRange<T>): T
Common
JVM
JS
Native
1.6

compareTo

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.

infix fun <T> Comparable<T>.compareTo(other: T): Int
Common
JVM
JS
Native
1.5

mod

Calculates the remainder of flooring division of this value (dividend) by the other value (divisor).

fun Float.mod(other: Float): Float
fun Float.mod(other: Double): Double
Native
1.3

narrow

fun <R : Number> Number.narrow(): R
Common
JVM
JS
Native
1.0

rangeTo

Creates a range from this Float value to the specified that value.

operator fun Float.rangeTo(
    that: Float
): ClosedFloatingPointRange<Float>

Creates a range from this Comparable value to the specified that value.

operator fun <T : Comparable<T>> T.rangeTo(
    that: T
): ClosedRange<T>
Common
JVM
JS
Native
1.9

rangeUntil

Creates an open-ended range from this Float value to the specified that value.

operator fun Float.rangeUntil(
    that: Float
): OpenEndRange<Float>

Creates an open-ended range from this Comparable value to the specified that value.

operator fun <T : Comparable<T>> T.rangeUntil(
    that: T
): OpenEndRange<T>
Native
1.3

signExtend

fun <R : Number> Number.signExtend(): R
JVM
1.2

toBigDecimal

Returns the value of this Float number as a BigDecimal.

fun Float.toBigDecimal(): BigDecimal
fun Float.toBigDecimal(mathContext: MathContext): BigDecimal
Common
JVM
JS
Native
1.5

toUInt

Converts this Float value to UInt.

fun Float.toUInt(): UInt
Common
JVM
JS
Native
1.5

toULong

Converts this Float value to ULong.

fun Float.toULong(): ULong