NaN ã Infinity ã int ã«ãã£ã¹ããªãã¦æ®éã¯ããªãã¨æãã®ã§ããããã£ã¦ã¿ãããããªãã¾ããã
- (int)Double.NaN == 0
- (int)Double.POSITIVE_INFINITY == Integer.MAX_VALUE
- (int)Double.NEGATIVE_INIFINITY == Integer.MIN_VALUE
public static void main(String[] args) throws Exception { // NaN: 0 System.out.println( Double.NaN + ": " + (int) Double.NaN); // Infinity: 2147483647 System.out.println( Double.POSITIVE_INFINITY + ": " + (int) Double.POSITIVE_INFINITY); // -Infinity: -2147483648 System.out.println( Double.NEGATIVE_INFINITY + ": " + (int) Double.NEGATIVE_INFINITY); }
ãã®æåã«ã¤ãã¦ãJava è¨èªä»æ§ 第3çã«ã¯ä»¥ä¸ã®ããã«æ¸ããã¦ãã¾ããã
5.1.3 ããªããã£ãåã®ããã¼ã¤ã³ã°å¤æ
æµ®åå°æ°ç¹ããæ´æ°å T ã¸ã®ããã¼ã¤ã³ã°å¤æã¯ã以ä¸ã®2ã¹ãããã«ã¦è¡ãããï¼
- 第1ã®ã¹ãããã§ã¯ãæµ®åå°æ°ç¹æ°ã以ä¸ã«å¾ã£ã¦ãT ã long ã§ããå ´å㯠long ã¸ã¨ãT ã byte, short, char, int ã§ããå ´å㯠int ã¸ã¨å¤æããï¼
- æµ®åå°æ°ç¹æ°ã NaN ã§ããå ´åãå¤æã®ç¬¬1ã¹ãããã®çµæã¯ãint ããã㯠long ã®ã¼ãã¨ãªãã
ããã§ãªããæµ®åå°æ°ç¹ãç¡é大ã§ãªãå ´åããã®æµ®åå°æ°ç¹ãIEEE754è¦æ ¼ã«ããã¼ãã¸ã®ä¸¸ãã¢ã¼ãã«ãã£ã¦ã¼ãã«åãã£ãæ´æ°å¤ V ã¸ã¨ä¸¸ããããã®å¾ã以ä¸ã®2ã¤ã®å ´åã«åãããï¼
- T ã long ã§ããããã®æ´æ°å¤ã long ã§è¡¨ç¾ã§ããå ´åã第1ã¹ãããã®çµæ㯠long å¤ã® V ã¨ãªãã
- ããã§ãªãããã®æ´æ°å¤ã int ã§è¡¨ç¾ã§ããå ´åã第1ã¹ãããã®çµæ㯠int å¤ã® V ã¨ãªãã
- ããã§ãªãå ´åã¯ã以ä¸ã®ãããããçã¨ãªãã¯ãã§ããï¼
- å¤ãå°ããããï¼å¤§ããªçµ¶å¯¾å¤ã¨ãªãè² ã®å¤ããè² ã®ç¡é大ï¼å ´åã第1ã¹ãããã®çµæ㯠int ããã㯠long åã§è¡¨ç¾å¯è½ãªæå°å¤ã¨ãªãã
- å¤ã大ããããï¼å¤§ããªçµ¶å¯¾å¤ã¨ãªãæ§ã®å¤ããæ£ã®ç¡é大ï¼å ´åã第1ã¹ãããã®çµæ㯠int ããã㯠long åã§è¡¨ç¾å¯è½ãªæ大å¤ã¨ãªãã
- 第2ã®ã¹ãããã§ã¯ï¼
- T ã int ããã㯠long ã§ããå ´åãå¤æçµæã¯ç¬¬1ã¹ãããã®çµæã¨ãªãã
- T ã byte, char, shrot ã§ããå ´åãå¤æçµæã¯ç¬¬1ã¹ãããã®çµæãTåã«ããã¼ã¤ã³ã°å¤æããçµæã¨ãªãã
ãããã«ããã®ãããªå¤æãªãç´å¾ã§ãã