blob: eb9d64a33bb9f38a027cc0f3f3bb2aed78c36e0e [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001public class Main {
2 public static void main(String[] args) {
3 test_printNarrowing();
4 }
5
6 public static void test_printNarrowing() {
7
8 System.out.println();
9 System.out.println("Double.POSITIVE_INFINITY = "
10 + Long.toHexString(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY)));
11 System.out.println("Double.NEGATIVE_INFINITY = "
12 + Long.toHexString(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY)));
13 System.out.println("Float.POSITIVE_INFINITY = "
14 + Long.toHexString(Double.doubleToRawLongBits(Float.POSITIVE_INFINITY)));
15 System.out.println("Float.NEGATIVE_INFINITY = "
16 + Long.toHexString(Double.doubleToRawLongBits(Float.NEGATIVE_INFINITY)));
17 System.out.println("Double.NaN = "
18 + Long.toHexString(Double.doubleToRawLongBits(Double.NaN)));
19 System.out.println("Float.NaN = "
20 + Long.toHexString(Double.doubleToRawLongBits(Float.NaN)));
21 double dbl2 = Double.NaN;
22 System.out.println();
23 System.out.println("(byte) Double.NaN = "
24 + (Long.toHexString((byte)dbl2).equals("0") ? "00" : Long.toHexString((byte)dbl2)
25 .substring(6)) + " expected: 00");
26 System.out.println("(short) Double.NaN = "
27 + (Integer.toHexString((short)dbl2).equals("0") ? "0000" : Integer.toHexString(
28 (short)dbl2).substring(4)) + " expected: 0000");
29 System.out.println("(int) Double.NaN = "
30 + (Integer.toHexString((int)dbl2).equals("0") ? "00000000" : Integer
31 .toHexString((int)dbl2)) + " expected: 00000000");
32 System.out.println("(long) Double.NaN = "
33 + (Long.toHexString((long)dbl2).equals("0") ? "0000000000000000" : Long
34 .toHexString((long)dbl2)) + " expected: 0000000000000000");
35 float fl2 = Float.NaN;
36 System.out.println();
37 System.out.println("(byte) Float.NaN = "
38 + (Long.toHexString((byte)fl2).equals("0") ? "00" : Long.toHexString((byte)fl2)
39 .substring(6)) + " expected: 00");
40 System.out.println("(short) Float.NaN = "
41 + (Integer.toHexString((short)fl2).equals("0") ? "0000" : Integer.toHexString(
42 (short)fl2).substring(4)) + " expected: 0000");
43 System.out.println("(int) Float.NaN = "
44 + (Integer.toHexString((int)fl2).equals("0") ? "00000000" : Integer
45 .toHexString((int)fl2)) + " expected: 00000000");
46 System.out.println("(long) Float.NaN = "
47 + (Long.toHexString((long)fl2).equals("0") ? "0000000000000000" : Long
48 .toHexString((long)fl2)) + " expected: 0000000000000000");
49 double dbl3 = Double.POSITIVE_INFINITY;
50 System.out.println();
51 System.out.println("(byte) Double.POSITIVE_INFINITY = "
52 + (Integer.toHexString((byte)dbl3).equals("0") ? "00" : Integer.toHexString(
53 (byte)dbl3).substring(6)) + " expected: ff");
54 System.out.println("(short) Double.POSITIVE_INFINITY = "
55 + (Integer.toHexString((short)dbl3).equals("0") ? "0000" : Integer.toHexString(
56 (short)dbl3).substring(4)) + " expected: ffff");
57 System.out.println("(int) Double.POSITIVE_INFINITY = "
58 + Integer.toHexString((int)dbl3) + " expected: 7fffffff");
59 System.out.println("(long) Double.POSITIVE_INFINITY = " + Long.toHexString((long)dbl3)
60 + " expected: 7fffffffffffffff");
61 double dbl4 = Double.NEGATIVE_INFINITY;
62 System.out.println();
63 System.out.println("(byte) Double.NEGATIVE_INFINITY = "
64 + (Long.toHexString((byte)dbl4).equals("0") ? " 00" : Long
65 .toHexString((byte)dbl4)) + " expected: 00");
66 System.out.println("(short) Double.NEGATIVE_INFINITY = "
67 + (Integer.toHexString((short)dbl4).equals("0") ? " 0000" : Long
68 .toHexString((short)dbl4)) + " expected: 0000");
69 System.out.println("(int) Double.NEGATIVE_INFINITY = "
70 + Integer.toHexString((int)dbl4) + " expected: 80000000");
71 System.out.println("(long) Double.NEGATIVE_INFINITY = " + Long.toHexString((long)dbl4)
72 + " expected: 8000000000000000");
73 float fl3 = Float.POSITIVE_INFINITY;
74 System.out.println();
75 System.out.println("(byte) Float.POSITIVE_INFINITY = "
76 + (Integer.toHexString((byte)fl3).equals("0") ? "00" : Integer.toHexString(
77 (byte)fl3).substring(6)) + " expected: ff");
78 System.out.println("(short) Float.POSITIVE_INFINITY = "
79 + (Integer.toHexString((short)fl3).equals("0") ? "0000" : Integer.toHexString(
80 (short)fl3).substring(4)) + " expected: ffff");
81 System.out.println("(int) Float.POSITIVE_INFINITY = "
82 + Integer.toHexString((int)fl3) + " expected: 7fffffff");
83 System.out.println("(long) Float.POSITIVE_INFINITY = " + Long.toHexString((long)fl3)
84 + " expected: 7fffffffffffffff");
85 float fl4 = Float.NEGATIVE_INFINITY;
86 System.out.println();
87 System.out.println("(byte) Float.NEGATIVE_INFINITY = "
88 + (Long.toHexString((byte)fl4).equals("0") ? " 00" : Long
89 .toHexString((byte)fl4)) + " expected: 00");
90 System.out.println("(short) Float.NEGATIVE_INFINITY = "
91 + (Integer.toHexString((short)fl4).equals("0") ? " 0000" : Long
92 .toHexString((short)fl4)) + " expected: 0000");
93 System.out.println("(int) Float.NEGATIVE_INFINITY = "
94 + Integer.toHexString((int)fl4) + " expected: 80000000");
95 System.out.println("(long) Float.NEGATIVE_INFINITY = " + Long.toHexString((long)fl4)
96 + " expected: 8000000000000000");
97 System.out.println();
98 }
99}