June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
13
Task/Safe-addition/Scala/safe-addition.scala
Normal file
13
Task/Safe-addition/Scala/safe-addition.scala
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
object SafeAddition extends App {
|
||||
val (a, b) = (1.2, 0.03)
|
||||
val result = safeAdd(a, b)
|
||||
|
||||
private def safeAdd(a: Double, b: Double) = Seq(stepDown(a + b), stepUp(a + b))
|
||||
|
||||
private def stepDown(d: Double) = Math.nextAfter(d, Double.NegativeInfinity)
|
||||
|
||||
private def stepUp(d: Double) = Math.nextUp(d)
|
||||
|
||||
println(f"($a%.2f + $b%.2f) is in the range ${result.head}%.16f .. ${result.last}%.16f")
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue