< prev index next >

test/java/lang/Math/Tests.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2012, 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  */


 366                            float result, float expected) {
 367         if (Float.compare(expected, result ) != 0) {
 368             System.err.println("Failure for "  + testName + ":\n" +
 369                                "\tFor inputs " + input1   + "\t(" + toHexString(input1) + ") and "
 370                                                + input2   + "\n"  +
 371                                "\texpected  "  + expected + "\t(" + toHexString(expected) + ")\n" +
 372                                "\tgot       "  + result   + "\t(" + toHexString(result) + ").");
 373             return 1;
 374         }
 375         else
 376             return 0;
 377     }
 378 
 379     public static int test(String testName,
 380                            double input1, int input2,
 381                            double result, double expected) {
 382         if (Double.compare(expected, result ) != 0) {
 383             System.err.println("Failure for "  + testName + ":\n" +
 384                                "\tFor inputs " + input1   + "\t(" + toHexString(input1) + ") and "
 385                                                + input2   + "\n"  +
































 386                                "\texpected  "  + expected + "\t(" + toHexString(expected) + ")\n" +
 387                                "\tgot       "  + result   + "\t(" + toHexString(result) + ").");
 388             return 1;
 389         }
 390         else
 391             return 0;
 392     }
 393 
 394     static int testUlpCore(double result, double expected, double ulps) {
 395         // We assume we won't be unlucky and have an inexact expected
 396         // be nextDown(2^i) when 2^i would be the correctly rounded
 397         // answer.  This would cause the ulp size to be half as large
 398         // as it should be, doubling the measured error).
 399 
 400         if (Double.compare(expected, result) == 0) {
 401             return 0;   // result and expected are equivalent
 402         } else {
 403             if( ulps == 0.0) {
 404                 // Equivalent results required but not found
 405                 return 1;


   1 /*
   2  * Copyright (c) 2003, 2016, 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  */


 366                            float result, float expected) {
 367         if (Float.compare(expected, result ) != 0) {
 368             System.err.println("Failure for "  + testName + ":\n" +
 369                                "\tFor inputs " + input1   + "\t(" + toHexString(input1) + ") and "
 370                                                + input2   + "\n"  +
 371                                "\texpected  "  + expected + "\t(" + toHexString(expected) + ")\n" +
 372                                "\tgot       "  + result   + "\t(" + toHexString(result) + ").");
 373             return 1;
 374         }
 375         else
 376             return 0;
 377     }
 378 
 379     public static int test(String testName,
 380                            double input1, int input2,
 381                            double result, double expected) {
 382         if (Double.compare(expected, result ) != 0) {
 383             System.err.println("Failure for "  + testName + ":\n" +
 384                                "\tFor inputs " + input1   + "\t(" + toHexString(input1) + ") and "
 385                                                + input2   + "\n"  +
 386                                "\texpected  "  + expected + "\t(" + toHexString(expected) + ")\n" +
 387                                "\tgot       "  + result   + "\t(" + toHexString(result) + ").");
 388             return 1;
 389         }
 390         else
 391             return 0;
 392     }
 393 
 394     public static int test(String testName,
 395                            float input1, float input2, float input3,
 396                            float result, float expected) {
 397         if (Float.compare(expected, result ) != 0) {
 398             System.err.println("Failure for "  + testName + ":\n" +
 399                                "\tFor inputs " + input1   + "\t(" + toHexString(input1) + ") and "
 400                                                + input2   + "\t(" + toHexString(input2) + ") and" 
 401                                                + input3   + "\t(" + toHexString(input3) + ")\n"  +
 402                                "\texpected  "  + expected + "\t(" + toHexString(expected) + ")\n" +
 403                                "\tgot       "  + result   + "\t(" + toHexString(result) + ").");
 404             return 1;
 405         }
 406         else
 407             return 0;
 408     }
 409 
 410     public static int test(String testName,
 411                            double input1, double input2, double input3,
 412                            double result, double expected) {
 413         if (Double.compare(expected, result ) != 0) {
 414             System.err.println("Failure for "  + testName + ":\n" +
 415                                "\tFor inputs " + input1   + "\t(" + toHexString(input1) + ") and "
 416                                                + input2   + "\t(" + toHexString(input2) + ") and" 
 417                                                + input3   + "\t(" + toHexString(input3) + ")\n"  +
 418                                "\texpected  "  + expected + "\t(" + toHexString(expected) + ")\n" +
 419                                "\tgot       "  + result   + "\t(" + toHexString(result) + ").");
 420             return 1;
 421         }
 422         else
 423             return 0;
 424     }
 425 
 426     static int testUlpCore(double result, double expected, double ulps) {
 427         // We assume we won't be unlucky and have an inexact expected
 428         // be nextDown(2^i) when 2^i would be the correctly rounded
 429         // answer.  This would cause the ulp size to be half as large
 430         // as it should be, doubling the measured error).
 431 
 432         if (Double.compare(expected, result) == 0) {
 433             return 0;   // result and expected are equivalent
 434         } else {
 435             if( ulps == 0.0) {
 436                 // Equivalent results required but not found
 437                 return 1;


< prev index next >