1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /** 24 * @test 25 * @bug 8076373 26 * @summary Verify if signaling NaNs are preserved. 27 * 28 * @run main compiler.floatingpoint.NaNTest 29 */ 30 31 package compiler.floatingpoint; 32 33 public class NaNTest { 34 static void testFloat() { 35 int originalValue = 0x7f800001; 36 int readBackValue = Float.floatToRawIntBits(Float.intBitsToFloat(originalValue)); 37 if (originalValue != readBackValue) { 38 String errorMessage = String.format("Original and read back float values mismatch\n0x%X 0x%X\n", 39 originalValue, 40 readBackValue); 41 throw new RuntimeException(errorMessage); 42 } else { 43 System.out.printf("Written and read back float values match\n0x%X 0x%X\n", 44 originalValue, 45 readBackValue); 46 } 47 } 48 49 static void testDouble() { 50 long originalValue = 0xFFF0000000000001L; 51 long readBackValue = Double.doubleToRawLongBits(Double.longBitsToDouble(originalValue)); 52 if (originalValue != readBackValue) { 53 String errorMessage = String.format("Original and read back double values mismatch\n0x%X 0x%X\n", 54 originalValue, 55 readBackValue); 56 throw new RuntimeException(errorMessage); 57 } else { 58 System.out.printf("Written and read back double values match\n0x%X 0x%X\n", 59 originalValue, 60 readBackValue); 61 } 62 63 } 64 65 public static void main(String args[]) { 66 System.out.println("### NanTest started"); 67 68 testFloat(); 69 testDouble(); 70 71 System.out.println("### NanTest ended"); 72 } 73 }