Skip to content

Commit

Permalink
test(samples): add new samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kotlin-samples-pusher-bot committed Feb 7, 2025
1 parent 17e71da commit f5abb8f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ fun main() {
val boxedA: Int? = a
val anotherBoxedA: Int? = a

val b: Int = 10000
val boxedB: Int? = b
val anotherBoxedB: Int? = b

println(boxedA === anotherBoxedA) // true
println(boxedB === anotherBoxedB) // false
//sampleEnd
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
fun main() {
//sampleStart
val b: Int = 10000
println(b == b) // Prints 'true'
val boxedB: Int? = b
val anotherBoxedB: Int? = b
println(boxedB == anotherBoxedB) // Prints 'true'

println(boxedB === anotherBoxedB) // false
println(boxedB == anotherBoxedB) // true
//sampleEnd
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
fun main() {
//sampleStart
println(1 + 2)
println(2_500_000_000L - 1L)
println(3.14 * 2.71)
println(10.0 / 3)
val l = 1L + 3 // Long + Int => Long
println(l is Long) // true
//sampleEnd
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
fun main() {
//sampleStart
val x = 5 / 2
//println(x == 2.5) // ERROR: Operator '==' cannot be applied to 'Int' and 'Double'
println(x == 2)
println(1 + 2)
println(2_500_000_000L - 1L)
println(3.14 * 2.71)
println(10.0 / 3)
//sampleEnd
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fun main() {
//sampleStart
val x = 5L / 2
println(x == 2L)
val x = 5 / 2.toDouble()
println(x == 2.5)
//sampleEnd
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
fun main() {
//sampleStart
val x = 5 / 2.toDouble()
println(x == 2.5)
//sampleEnd
//sampleStart
// Operand statically typed as floating-point number
println(Double.NaN == Double.NaN) // false

// Operand NOT statically typed as floating-point number
// So NaN is equal to itself
println(listOf(Double.NaN) == listOf(Double.NaN)) // true

// Operand statically typed as floating-point number
println(0.0 == -0.0) // true

// Operand NOT statically typed as floating-point number
// So -0.0 is less than 0.0
println(listOf(0.0) == listOf(-0.0)) // false

println(listOf(Double.NaN, Double.POSITIVE_INFINITY, 0.0, -0.0).sorted())
// [-0.0, 0.0, Infinity, NaN]
//sampleEnd
}

This file was deleted.

0 comments on commit f5abb8f

Please sign in to comment.