hotspot/test/compiler/floatingpoint/NaNTest.java
changeset 32391 01e2f5e916c7
child 40059 c2304140ed64
equal deleted inserted replaced
32371:8815f2d1447f 32391:01e2f5e916c7
       
     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  * @run main NaNTest
       
    28  */
       
    29 public class NaNTest {
       
    30     static void testFloat() {
       
    31         int originalValue = 0x7f800001;
       
    32         int readBackValue = Float.floatToRawIntBits(Float.intBitsToFloat(originalValue));
       
    33         if (originalValue != readBackValue) {
       
    34             String errorMessage = String.format("Original and read back float values mismatch\n0x%X 0x%X\n",
       
    35                                                 originalValue,
       
    36                                                 readBackValue);
       
    37             throw new RuntimeException(errorMessage);
       
    38         } else {
       
    39             System.out.printf("Written and read back float values match\n0x%X 0x%X\n",
       
    40                               originalValue,
       
    41                               readBackValue);
       
    42         }
       
    43     }
       
    44 
       
    45     static void testDouble() {
       
    46         long originalValue = 0xFFF0000000000001L;
       
    47         long readBackValue = Double.doubleToRawLongBits(Double.longBitsToDouble(originalValue));
       
    48         if (originalValue != readBackValue) {
       
    49             String errorMessage = String.format("Original and read back double values mismatch\n0x%X 0x%X\n",
       
    50                                                 originalValue,
       
    51                                                 readBackValue);
       
    52             throw new RuntimeException(errorMessage);
       
    53         } else {
       
    54             System.out.printf("Written and read back double values match\n0x%X 0x%X\n",
       
    55                               originalValue,
       
    56                               readBackValue);
       
    57         }
       
    58 
       
    59     }
       
    60 
       
    61     public static void main(String args[]) {
       
    62         System.out.println("### NanTest started");
       
    63 
       
    64         testFloat();
       
    65         testDouble();
       
    66 
       
    67         System.out.println("### NanTest ended");
       
    68     }
       
    69 }