Skip to content

Commit 8dec7f5

Browse files
authored
Clarify writeFloat/readFloat behavior on Kotlin/JS (#323)
Addresses concerns described in #322
1 parent e8add48 commit 8dec7f5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

core/common/src/Sinks.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ public fun Sink.writeULongLe(long: ULong) {
285285
*
286286
* 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.
287287
*
288+
* Note that in Kotlin/JS a value obtained by writing an original [Float] value to a [Sink] using
289+
* [Sink.writeFloat] and then reading it back using [Source.readFloat] may not be equal to the original value.
290+
* Please refer to [Float.toBits] documentation for details.
291+
*
288292
* @param float the floating point number to be written.
289293
*
290294
* @throws IllegalStateException when the sink is closed.
@@ -321,6 +325,10 @@ public fun Sink.writeDouble(double: Double) {
321325
*
322326
* 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.
323327
*
328+
* Note that in Kotlin/JS a value obtained by writing an original [Float] value to a [Sink] using
329+
* [Sink.writeFloatLe] and then reading it back using [Source.readFloatLe] may not be equal to the original value.
330+
* Please refer to [Float.toBits] documentation for details.
331+
*
324332
* @param float the floating point number to be written.
325333
*
326334
* @throws IllegalStateException when the sink is closed.

core/common/src/Sources.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ public fun Source.readULongLe(): ULong = readLongLe().toULong()
361361
*
362362
* The [Float.Companion.fromBits] function is used for decoding bytes into [Float].
363363
*
364+
* Note that in Kotlin/JS a value obtained by writing an original [Float] value to a [Sink] using
365+
* [Sink.writeFloat] and then reading it back using [Source.readFloat] may not be equal to the original value.
366+
* Please refer to [Float.Companion.fromBits] documentation for details.
367+
*
364368
* @throws EOFException when there are not enough data to read an unsigned int value.
365369
* @throws IllegalStateException when the source is closed.
366370
*
@@ -387,6 +391,10 @@ public fun Source.readDouble(): Double = Double.fromBits(readLong())
387391
*
388392
* The [Float.Companion.fromBits] function is used for decoding bytes into [Float].
389393
*
394+
* Note that in Kotlin/JS a value obtained by writing an original [Float] value to a [Sink] using
395+
* [Sink.writeFloatLe] and then reading it back using [Source.readFloatLe] may not be equal to the original value.
396+
* Please refer to [Float.Companion.fromBits] documentation for details.
397+
*
390398
* @throws EOFException when there are not enough data to read an unsigned int value.
391399
* @throws IllegalStateException when the source is closed.
392400
*

0 commit comments

Comments
 (0)