test/tools/javac/lambda/LambdaTestStrictFPMethod.java

Mon, 23 Jun 2014 13:14:32 -0700

author
rfield
date
Mon, 23 Jun 2014 13:14:32 -0700
changeset 2528
eb284abd64fe
permissions
-rw-r--r--

8046060: Different results of floating point multiplication for lambda code block
Summary: propogate strictfp into lambda body
Reviewed-by: vromero, jlahoda

rfield@2528 1 /*
rfield@2528 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
rfield@2528 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
rfield@2528 4 *
rfield@2528 5 * This code is free software; you can redistribute it and/or modify it
rfield@2528 6 * under the terms of the GNU General Public License version 2 only, as
rfield@2528 7 * published by the Free Software Foundation.
rfield@2528 8 *
rfield@2528 9 * This code is distributed in the hope that it will be useful, but WITHOUT
rfield@2528 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
rfield@2528 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
rfield@2528 12 * version 2 for more details (a copy is included in the LICENSE file that
rfield@2528 13 * accompanied this code).
rfield@2528 14 *
rfield@2528 15 * You should have received a copy of the GNU General Public License version
rfield@2528 16 * 2 along with this work; if not, write to the Free Software Foundation,
rfield@2528 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
rfield@2528 18 *
rfield@2528 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
rfield@2528 20 * or visit www.oracle.com if you need additional information or have any
rfield@2528 21 * questions.
rfield@2528 22 */
rfield@2528 23
rfield@2528 24 /*
rfield@2528 25 * @test
rfield@2528 26 * @bug 8046060
rfield@2528 27 * @summary Different results of floating point multiplication for lambda code block
rfield@2528 28 */
rfield@2528 29
rfield@2528 30 public class LambdaTestStrictFPMethod {
rfield@2528 31
rfield@2528 32 public static void main(String args[]) {
rfield@2528 33 new LambdaTestStrictFPMethod().test();
rfield@2528 34 }
rfield@2528 35
rfield@2528 36 strictfp void test() {
rfield@2528 37 double result = eval(() -> {
rfield@2528 38 double x = Double.longBitsToDouble(0x1e7ee00000000000L);
rfield@2528 39 double y = Double.longBitsToDouble(0x2180101010101010L);
rfield@2528 40
rfield@2528 41 return x * y;
rfield@2528 42 });
rfield@2528 43 {
rfield@2528 44 double x = Double.longBitsToDouble(0x1e7ee00000000000L);
rfield@2528 45 double y = Double.longBitsToDouble(0x2180101010101010L);
rfield@2528 46
rfield@2528 47 double z = x * y;
rfield@2528 48 check(z, result, "method");
rfield@2528 49 }
rfield@2528 50 }
rfield@2528 51
rfield@2528 52 strictfp void check(double expected, double got, String where) {
rfield@2528 53 if (got != expected) {
rfield@2528 54 throw new AssertionError(where + ": Non-strictfp " + got + " != " + expected);
rfield@2528 55 }
rfield@2528 56 }
rfield@2528 57
rfield@2528 58 static double eval(Face arg) {
rfield@2528 59 return arg.m();
rfield@2528 60 }
rfield@2528 61
rfield@2528 62 interface Face {
rfield@2528 63 double m();
rfield@2528 64 }
rfield@2528 65 }

mercurial