September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
13
Task/Safe-addition/Kotlin/safe-addition.kotlin
Normal file
13
Task/Safe-addition/Kotlin/safe-addition.kotlin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// version 1.1.2
|
||||
|
||||
fun stepDown(d: Double) = Math.nextAfter(d, Double.NEGATIVE_INFINITY)
|
||||
|
||||
fun stepUp(d: Double) = Math.nextUp(d)
|
||||
|
||||
fun safeAdd(a: Double, b: Double) = stepDown(a + b).rangeTo(stepUp(a + b))
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = 1.2
|
||||
val b = 0.03
|
||||
println("($a + $b) is in the range ${safeAdd(a, b)}")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue