File: p58.java

package info (click to toggle)
bock 0.20.2.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,228 kB
  • ctags: 1,370
  • sloc: ansic: 7,367; java: 5,553; yacc: 963; lex: 392; makefile: 243; sh: 90; perl: 42
file content (24 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Test {

        public static void main(String[] args) {

                // A narrowing of int to short loses high bits:
                System.out.println("(short)0x12345678==0x" +
                        Integer.toHexString((short)0x12345678));

                // A int value not fitting in byte changes sign and magnitude:
                System.out.println("(byte)255==" + (byte)255);

                // A float value too big to fit gives largest int value:
                System.out.println("(int)1e20f==" + (int)1e20f);

                // A NaN converted to int yields zero:
                System.out.println("(int)NaN==" + (int)Float.NaN);

                // A double value too large for float yields infinity:
                System.out.println("(float)-1e100==" + (float)-1e100);

                // A double value too small for float underflows to zero:
                System.out.println("(float)1e-50==" + (float)1e-50);
        }
}