|
1 /* |
|
2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 /* |
|
26 * @test |
|
27 * @bug 6778657 |
|
28 * @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour |
|
29 */ |
|
30 |
|
31 public class Test { |
|
32 public static void check_f2i(int expect) { |
|
33 float check = expect; |
|
34 check *= 2; |
|
35 int actual = (int) check; |
|
36 if (actual != expect) |
|
37 throw new RuntimeException("expecting " + expect + ", got " + actual); |
|
38 } |
|
39 |
|
40 public static void check_f2l(long expect) { |
|
41 float check = expect; |
|
42 check *= 2; |
|
43 long actual = (long) check; |
|
44 if (actual != expect) |
|
45 throw new RuntimeException("expecting " + expect + ", got " + actual); |
|
46 } |
|
47 |
|
48 public static void check_d2i(int expect) { |
|
49 double check = expect; |
|
50 check *= 2; |
|
51 int actual = (int) check; |
|
52 if (actual != expect) |
|
53 throw new RuntimeException("expecting " + expect + ", got " + actual); |
|
54 } |
|
55 |
|
56 public static void check_d2l(long expect) { |
|
57 double check = expect; |
|
58 check *= 2; |
|
59 long actual = (long) check; |
|
60 if (actual != expect) |
|
61 throw new RuntimeException("expecting " + expect + ", got " + actual); |
|
62 } |
|
63 |
|
64 public static void main(String[] args) { |
|
65 check_f2i(Integer.MAX_VALUE); |
|
66 check_f2i(Integer.MIN_VALUE); |
|
67 check_f2l(Long.MAX_VALUE); |
|
68 check_f2l(Long.MIN_VALUE); |
|
69 check_d2i(Integer.MAX_VALUE); |
|
70 check_d2i(Integer.MIN_VALUE); |
|
71 check_d2l(Long.MAX_VALUE); |
|
72 check_d2l(Long.MIN_VALUE); |
|
73 } |
|
74 } |
|
75 |