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