blob: c33f1c294c253bfd1abed3a74f9bef4a9d9a6363 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
public class CastTest
{
public static void main(String args[])
{
d2d();
l2d2l();
d2l2d();
f2d2f();
d2f2d();
i2f2i();
l2f2l();
f2l2f();
}
static void d2d()
{
String msg = "double -> double ";
try {
double dvalue1 = 4.2;
double dvalue2 = (double)dvalue1;
if (dvalue1 != dvalue2)
failed(msg + dvalue1 + " != " + dvalue2);
else
passed(msg + dvalue1 + " == " + dvalue2);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void l2f2l()
{
String msg = "long -> float -> long ";
try {
long lvalue = 123;
float fvalue = (float)lvalue;
long lvalue2 = (long)fvalue;
if (lvalue != lvalue2)
failed(msg + lvalue + " != " + lvalue2 + " (float)" + fvalue);
else
passed(msg + lvalue + " == " + lvalue2 + " (float)" + fvalue);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void i2f2i()
{
String msg = "int -> float -> int ";
try {
int ivalue = 123;
float fvalue = (float)ivalue;
int ivalue2 = (int)fvalue;
if (ivalue != ivalue2)
failed(msg + ivalue + " != " + ivalue2 + " (float)" + fvalue);
else
passed(msg + ivalue + " == " + ivalue2 + " (float)" + fvalue);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void f2d2f()
{
String msg = "float -> double -> float ";
try {
float fvalue = 123.0f;
double dvalue = (double)fvalue;
float fvalue2 = (float)dvalue;
if (fvalue != fvalue2)
failed(msg + fvalue + " != " + fvalue2 + " (double)" + dvalue);
else
passed(msg + fvalue + " == " + fvalue2 + " (double)" + dvalue);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void f2l2f()
{
String msg = "float -> long -> float ";
try {
float fvalue = 123.0f;
long lvalue = (long)fvalue;
float fvalue2 = (float)lvalue;
if (fvalue != fvalue2)
failed(msg + fvalue + " != " + fvalue2 + " (long)" + lvalue);
else
passed(msg + fvalue + " == " + fvalue2 + " (long)" + lvalue);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void d2f2d()
{
String msg = "double -> float -> double ";
try {
double dvalue = 123.0;
float fvalue = (float)dvalue;
double dvalue2 = (double)fvalue;
if (dvalue != dvalue2)
failed(msg + dvalue + " != " + dvalue2 + " (float)" + fvalue);
else
passed(msg + dvalue + " == " + dvalue2 + " (float)" + fvalue);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void l2d2l()
{
String msg = "long -> double -> long ";
try {
long lvalue = 1023;
double dvalue = (double)lvalue;
long lvalue2 = (long)dvalue;
if (lvalue != lvalue2)
failed(msg + lvalue + " != " + lvalue2 + " (double)" + dvalue);
else
passed(msg + lvalue + " == " + lvalue2 + " (double)" + dvalue);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void d2l2d()
{
String msg = "double -> long -> double ";
try {
double dvalue = 123.0;
long lvalue = (long)dvalue;
double dvalue2 = (double)lvalue;
if (dvalue != dvalue2)
failed(msg + dvalue + " != " + dvalue2 + " (long)" + lvalue);
else
passed(msg + dvalue + " == " + dvalue2 + " (long)" + lvalue);
}
catch (Exception e)
{
failed(msg + " : exception " + e.toString());
}
}
static void passed(String msg)
{
System.out.println("PASSED: "+msg);
}
static void failed(String msg)
{
System.out.println("FAILED: "+msg);
}
}
|