Created
February 21, 2013 09:50
-
-
Save blueberrystream/5003576 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
/** | |
* @author KID / @blueberrystream | |
*/ | |
public class 桁落ち { | |
/** | |
* @param args | |
*/ | |
public static void main(final String[] args) { | |
final Long l1 = System.currentTimeMillis(); | |
final Long l2 = System.currentTimeMillis() + 5; | |
final Double d1 = l1.doubleValue() / 10000000000000L; | |
final Double d2 = l2.doubleValue() / 10000000000000L; | |
System.out.println(d1); | |
System.out.println(d2); | |
System.out.println(d2 - d1); | |
/* | |
出力例 | |
0.1361440116519 | |
0.1361440116524 | |
5.000166947155549E-13 | |
*/ | |
} | |
} |
最初のままでも
136.144053347
136.1440533475
4.999947122996673E-10
とか出るじょん!
桁落ちとは : JavaA2Z http://www.kab-studio.biz/Programing/JavaA2Z/Word/00000528.html これのサンプルプログラムのコメントでようやく理解。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
final Double d1 = l1 / 10000000000000.0;
final Double d2 = l2 / 10000000000000.0;
にしたら
0.1361440488412
0.1361440488417
5.000166947155549E-13
とか
0.1361440497788
0.1361440497793
4.999889391399392E-13
とか出るようになった。