508N/A/*
1472N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
508N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
508N/A *
508N/A * This code is free software; you can redistribute it and/or modify it
508N/A * under the terms of the GNU General Public License version 2 only, as
508N/A * published by the Free Software Foundation.
508N/A *
508N/A * This code is distributed in the hope that it will be useful, but WITHOUT
508N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
508N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
508N/A * version 2 for more details (a copy is included in the LICENSE file that
508N/A * accompanied this code).
508N/A *
508N/A * You should have received a copy of the GNU General Public License version
508N/A * 2 along with this work; if not, write to the Free Software Foundation,
508N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
508N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
508N/A *
508N/A */
508N/A
508N/A/*
508N/A * @test
508N/A * @bug 6778657
508N/A * @summary Casts in SharedRuntime::f2i, f2l, d2i and d2l rely on undefined C++ behaviour
508N/A */
508N/A
508N/Apublic class Test {
508N/A public static void check_f2i(int expect) {
508N/A float check = expect;
508N/A check *= 2;
508N/A int actual = (int) check;
508N/A if (actual != expect)
508N/A throw new RuntimeException("expecting " + expect + ", got " + actual);
508N/A }
508N/A
508N/A public static void check_f2l(long expect) {
508N/A float check = expect;
508N/A check *= 2;
508N/A long actual = (long) check;
508N/A if (actual != expect)
508N/A throw new RuntimeException("expecting " + expect + ", got " + actual);
508N/A }
508N/A
508N/A public static void check_d2i(int expect) {
508N/A double check = expect;
508N/A check *= 2;
508N/A int actual = (int) check;
508N/A if (actual != expect)
508N/A throw new RuntimeException("expecting " + expect + ", got " + actual);
508N/A }
508N/A
508N/A public static void check_d2l(long expect) {
508N/A double check = expect;
508N/A check *= 2;
508N/A long actual = (long) check;
508N/A if (actual != expect)
508N/A throw new RuntimeException("expecting " + expect + ", got " + actual);
508N/A }
508N/A
508N/A public static void main(String[] args) {
508N/A check_f2i(Integer.MAX_VALUE);
508N/A check_f2i(Integer.MIN_VALUE);
508N/A check_f2l(Long.MAX_VALUE);
508N/A check_f2l(Long.MIN_VALUE);
508N/A check_d2i(Integer.MAX_VALUE);
508N/A check_d2i(Integer.MIN_VALUE);
508N/A check_d2l(Long.MAX_VALUE);
508N/A check_d2l(Long.MIN_VALUE);
508N/A }
508N/A}
508N/A