1 /* 2 * Copyright (c) 2014, 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 package org.graalvm.compiler.core.test; 24 25 import org.junit.Assert; 26 import org.junit.Test; 27 28 /** 29 * Check for incorrect elimination of 0.0 and -0.0 from computations. They can affect the sign of 30 * the result of an add or substract. 31 */ 32 public class FloatOptimizationTest extends GraalCompilerTest { 33 34 @Test 35 public void test1() { 36 test("test1Snippet", -0.0); 37 } 38 39 @SuppressWarnings("all") 40 public static double test1Snippet(double x) { 41 return x + 0.0; 42 } 43 44 @Test 45 public void test2() { 46 test("test2Snippet", -0.0f); 47 } 48 49 @SuppressWarnings("all") 50 public static double test2Snippet(float x) { 51 return x + 0.0f; 52 } 53 54 @Test 55 public void test3() { 56 test("test3Snippet", -0.0); 57 } 58 59 @SuppressWarnings("all") 60 public static double test3Snippet(double x) { 61 return x - -0.0; 62 } 63 64 @Test 65 public void test4() { 66 test("test4Snippet", -0.0f); 67 } 68 69 @SuppressWarnings("all") 70 public static double test4Snippet(float x) { 71 return x - -0.0f; 72 } 73 74 @Override 75 protected void assertDeepEquals(String message, Object expected, Object actual, double delta) { 76 if (expected instanceof Double && actual instanceof Double) { 77 double e = (double) expected; 78 double a = (double) actual; 79 if (Double.doubleToRawLongBits(a) != Double.doubleToRawLongBits(e)) { 80 Assert.fail((message == null ? "" : message) + "raw double bits not equal " + Double.doubleToRawLongBits(a) + " != " + Double.doubleToRawLongBits(e)); 81 } 82 } else { 83 super.assertDeepEquals(message, expected, actual, delta); 84 } 85 } 86 }