writeFloat

Writes four bytes of a bit representation of float, in the big-endian order, to this sink. Bit representation of the float corresponds to the IEEE 754 floating-point "single format" bit layout.

To obtain a bit representation, the Float.toBits function is used.

Should be used with care when working with special values (like NaN) as bit patterns obtained for Float.NaN may vary depending on a platform.

Note that in Kotlin/JS a value obtained by writing an original Float value to a Sink using Sink.writeFloat and then reading it back using Source.readFloat may not be equal to the original value. Please refer to Float.toBits documentation for details.

Parameters

float

the floating point number to be written.

Throws

when the sink is closed.

when some I/O error occurs.

Samples

import kotlinx.io.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val buffer = Buffer()
buffer.writeFloat(12345.678F)

assertContentEquals(byteArrayOf(70, 64, -26, -74), buffer.readByteArray()) 
   //sampleEnd
}