W3cubDocs

/Kotlin

Float

class Float : Number, Comparable<Float>

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.

Functions

compareTo

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

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.

dec

operator fun dec(): Float

Decrements this value.

div

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

Divides this value by the other value.

inc

operator fun inc(): Float

Increments this value.

minus

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

Subtracts the other value from this value.

mod

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

Calculates the remainder of dividing this value by the other value.

plus

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

Adds the other value to this value.

rem

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

Calculates the remainder of dividing this value by the other value.

times

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

Multiplies this value by the other value.

toByte

fun toByte(): Byte

Returns the value of this number as a Byte, which may involve rounding or truncation.

toChar

fun toChar(): Char

Returns the Char with the numeric value equal to this number, truncated to 16 bits if appropriate.

toDouble

fun toDouble(): Double

Returns the value of this number as a Double, which may involve rounding.

toFloat

fun toFloat(): Float

Returns the value of this number as a Float, which may involve rounding.

toInt

fun toInt(): Int

Returns the value of this number as an Int, which may involve rounding or truncation.

toLong

fun toLong(): Long

Returns the value of this number as a Long, which may involve rounding or truncation.

toShort

fun toShort(): Short

Returns the value of this number as a Short, which may involve rounding or truncation.

unaryMinus

operator fun unaryMinus(): Float

Returns the negative of this value.

unaryPlus

operator fun unaryPlus(): Float

Returns this value.

Companion Object Properties

MAX_VALUE

val MAX_VALUE: Float

A constant holding the largest positive finite value of Float.

MIN_VALUE

val MIN_VALUE: Float

A constant holding the smallest positive nonzero value of Float.

NEGATIVE_INFINITY

val NEGATIVE_INFINITY: Float

A constant holding the negative infinity value of Float.

NaN

val NaN: Float

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

POSITIVE_INFINITY

val POSITIVE_INFINITY: Float

A constant holding the positive infinity value of Float.

Extension Properties

absoluteValue

val Float.absoluteValue: Float

Returns the absolute value of this value.

sign

val Float.sign: Float

Returns the sign of this value:

ulp

val Float.ulp: Float

Returns the ulp of this value.

Extension Functions

IEEErem

fun Float.IEEErem(divisor: Float): Float

Computes the remainder of division of this value by the divisor value according to the IEEE 754 standard.

coerceAtLeast

fun Float.coerceAtLeast(minimumValue: Float): Float

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

coerceAtMost

fun Float.coerceAtMost(maximumValue: Float): Float

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

coerceIn

fun Float.coerceIn(
    minimumValue: Float, 
    maximumValue: Float
): Float

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

isFinite

fun Float.isFinite(): Boolean

Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).

isInfinite

fun Float.isInfinite(): Boolean

Returns true if this value is infinitely large in magnitude.

isNaN

fun Float.isNaN(): Boolean

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

nextDown

fun Float.nextDown(): Float

Returns the Float value nearest to this value in direction of negative infinity.

nextTowards

fun Float.nextTowards(to: Float): Float

Returns the Float value nearest to this value in direction from this value towards the value to.

nextUp

fun Float.nextUp(): Float

Returns the Float value nearest to this value in direction of positive infinity.

pow

fun Float.pow(x: Float): Float

Raises this value to the power x.

fun Float.pow(n: Int): Float

Raises this value to the integer power n.

rangeTo

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

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

roundToInt

fun Float.roundToInt(): Int

Rounds this Float value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

roundToLong

fun Float.roundToLong(): Long

Rounds this Float value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

toBigDecimal

fun Float.toBigDecimal(): BigDecimal
fun Float.toBigDecimal(mathContext: MathContext): BigDecimal

Returns the value of this Float number as a BigDecimal.

toBits

fun Float.toBits(): Int

Returns a bit representation of the specified floating-point value as Int according to the IEEE 754 floating-point "single format" bit layout.

toRawBits

fun Float.toRawBits(): Int

Returns a bit representation of the specified floating-point value as Int according to the IEEE 754 floating-point "single format" bit layout, preserving NaN values exact layout.

withSign

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

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

Companion Object Extension Functions

fromBits

fun Float.Companion.fromBits(bits: Int): Float

Returns the Float value corresponding to a given bit representation.

© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html