Created
November 11, 2015 22:47
-
-
Save jbn/00208fa74520e8061f4d to your computer and use it in GitHub Desktop.
Double's epsilon and scheduling artifacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Consider two activities, A and B, both scheduled at the same time. When | |
activated, they schedule themselves for reactivation in a time delta of 0.1 | |
and 0.2. If this is less than the ulp at a given time, both activities end | |
up being scheduled at the same time. | |
*/ | |
import scala.math.ulp | |
val MaxTime = 9.007199254740991E15 | |
var a = MaxTime + 0.1 | |
var b = MaxTime + 0.2 | |
println(s"ulp(MaxTime) => ${ulp(MaxTime)}") | |
println(s"a = MaxTime + 0.1 => $a") | |
println(s"b = MaxTime + 0.2 => $b") | |
println(s"a == b => ${a == b}") | |
println("\n----------------------------------------------\n") | |
val HalfMax = 9.007199254740991E15 / 2.0 | |
a = HalfMax + 0.1 | |
b = HalfMax + 0.2 | |
println(s"ulp(HalfMax) => ${ulp(HalfMax)}") | |
println(s"a = HalfMax + 0.1 => $a") | |
println(s"b = HalfMax + 0.2 => $b") | |
println(s"a == b => ${a == b}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment