Created
March 9, 2014 14:49
-
-
Save zakki/9448918 to your computer and use it in GitHub Desktop.
This file contains 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
public class Nan { | |
static void f(double a) { | |
long t0 = System.nanoTime(); | |
double acc = a; | |
for (int i = 0; i < 100000000; i++) { | |
acc += i; | |
} | |
long t1 = System.nanoTime(); | |
System.out.println("time:" + (t1 - t0) / 1000000 + " " + acc); | |
} | |
public static void main(String[] args) { | |
for (int i = 0; i < 3; i++) { | |
f(0d); | |
f(0d); | |
f(Double.NaN); | |
f(Double.POSITIVE_INFINITY); | |
} | |
} | |
//time:95 4.99999995E15 | |
//time:96 4.99999995E15 | |
//time:101 NaN | |
//time:101 Infinity | |
//time:100 4.99999995E15 | |
//time:100 4.99999995E15 | |
//time:104 NaN | |
//time:98 Infinity | |
//time:95 4.99999995E15 | |
//time:96 4.99999995E15 | |
//time:116 NaN | |
//time:96 Infinity | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment