test/java/lang/Math/IeeeRecommendedTests.java

Print this page


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


 606         float testCases [][] = {
 607             {NaNf,                      NaNf},
 608             {-infinityF,                -infinityF},
 609             {-Float.MAX_VALUE,          -infinityF},
 610             {-Float_MAX_VALUEmm,        -Float.MAX_VALUE},
 611             {-Float_MAX_SUBNORMAL,      -FloatConsts.MIN_NORMAL},
 612             {-Float_MAX_SUBNORMALmm,    -Float_MAX_SUBNORMAL},
 613             {-0.0f,                     -Float.MIN_VALUE},
 614             {+0.0f,                     -Float.MIN_VALUE},
 615             {Float.MIN_VALUE,           0.0f},
 616             {Float.MIN_VALUE*2,         Float.MIN_VALUE},
 617             {Float_MAX_SUBNORMAL,       Float_MAX_SUBNORMALmm},
 618             {FloatConsts.MIN_NORMAL,    Float_MAX_SUBNORMAL},
 619             {FloatConsts.MIN_NORMAL+
 620              Float.MIN_VALUE,           FloatConsts.MIN_NORMAL},
 621             {Float.MAX_VALUE,           Float_MAX_VALUEmm},
 622             {infinityF,                 Float.MAX_VALUE},
 623         };
 624 
 625         for(int i = 0; i < testCases.length; i++) {
 626             failures+=Tests.test("FpUtils.nextDown(float)",
 627                                  testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);



 628         }
 629 
 630         return failures;
 631     }
 632 
 633 
 634     public static int testDoubleNextDown() {
 635         int failures=0;
 636 
 637         /*
 638          * Each row of testCases represents one test case for nextDown;
 639          * the first column is the input and the second column is the
 640          * expected result.
 641          */
 642         double testCases [][] = {
 643             {NaNd,                      NaNd},
 644             {-infinityD,                -infinityD},
 645             {-Double.MAX_VALUE,         -infinityD},
 646             {-Double_MAX_VALUEmm,       -Double.MAX_VALUE},
 647             {-Double_MAX_SUBNORMAL,     -DoubleConsts.MIN_NORMAL},
 648             {-Double_MAX_SUBNORMALmm,   -Double_MAX_SUBNORMAL},
 649             {-0.0d,                     -Double.MIN_VALUE},
 650             {+0.0d,                     -Double.MIN_VALUE},
 651             {Double.MIN_VALUE,          0.0d},
 652             {Double.MIN_VALUE*2,        Double.MIN_VALUE},
 653             {Double_MAX_SUBNORMAL,      Double_MAX_SUBNORMALmm},
 654             {DoubleConsts.MIN_NORMAL,   Double_MAX_SUBNORMAL},
 655             {DoubleConsts.MIN_NORMAL+
 656              Double.MIN_VALUE,          DoubleConsts.MIN_NORMAL},
 657             {Double.MAX_VALUE,          Double_MAX_VALUEmm},
 658             {infinityD,                 Double.MAX_VALUE},
 659         };
 660 
 661         for(int i = 0; i < testCases.length; i++) {
 662             failures+=Tests.test("FpUtils.nextDown(double)",
 663                                  testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);



 664         }
 665 
 666         return failures;
 667     }
 668 
 669 
 670     /* ********************** boolean tests ****************************** */
 671 
 672     /*
 673      * Combined tests for boolean functions, isFinite, isInfinite,
 674      * isNaN, isUnordered.
 675      */
 676 
 677     public static int testFloatBooleanMethods() {
 678         int failures = 0;
 679 
 680         float testCases [] = {
 681             NaNf,
 682             -infinityF,
 683             infinityF,


 689             -Float_MAX_SUBNORMAL,
 690             -Float.MIN_VALUE,
 691             -0.0f,
 692             +0.0f,
 693             Float.MIN_VALUE,
 694             Float_MAX_SUBNORMALmm,
 695             Float_MAX_SUBNORMAL,
 696             FloatConsts.MIN_NORMAL,
 697             1.0f,
 698             3.0f,
 699             Float_MAX_VALUEmm,
 700             Float.MAX_VALUE
 701         };
 702 
 703         for(int i = 0; i < testCases.length; i++) {
 704             // isNaN
 705             failures+=Tests.test("FpUtils.isNaN(float)", testCases[i],
 706                                  FpUtils.isNaN(testCases[i]), (i ==0));
 707 
 708             // isFinite
 709             failures+=Tests.test("FpUtils.isFinite(float)", testCases[i],
 710                                  FpUtils.isFinite(testCases[i]), (i >= 3));
 711 
 712             // isInfinite
 713             failures+=Tests.test("FpUtils.isInfinite(float)", testCases[i],
 714                                  FpUtils.isInfinite(testCases[i]), (i==1 || i==2));
 715 
 716             // isUnorderd
 717             for(int j = 0; j < testCases.length; j++) {
 718                 failures+=Tests.test("FpUtils.isUnordered(float, float)", testCases[i],testCases[j],
 719                                      FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
 720             }
 721         }
 722 
 723         return failures;
 724     }
 725 
 726     public static int testDoubleBooleanMethods() {
 727         int failures = 0;
 728         boolean result = false;
 729 
 730         double testCases [] = {


 739             -Double_MAX_SUBNORMAL,
 740             -Double.MIN_VALUE,
 741             -0.0d,
 742             +0.0d,
 743             Double.MIN_VALUE,
 744             Double_MAX_SUBNORMALmm,
 745             Double_MAX_SUBNORMAL,
 746             DoubleConsts.MIN_NORMAL,
 747             1.0d,
 748             3.0d,
 749             Double_MAX_VALUEmm,
 750             Double.MAX_VALUE
 751         };
 752 
 753         for(int i = 0; i < testCases.length; i++) {
 754             // isNaN
 755             failures+=Tests.test("FpUtils.isNaN(double)", testCases[i],
 756                                  FpUtils.isNaN(testCases[i]), (i ==0));
 757 
 758             // isFinite
 759             failures+=Tests.test("FpUtils.isFinite(double)", testCases[i],
 760                                  FpUtils.isFinite(testCases[i]), (i >= 3));
 761 
 762             // isInfinite
 763             failures+=Tests.test("FpUtils.isInfinite(double)", testCases[i],
 764                                  FpUtils.isInfinite(testCases[i]), (i==1 || i==2));
 765 
 766             // isUnorderd
 767             for(int j = 0; j < testCases.length; j++) {
 768                 failures+=Tests.test("FpUtils.isUnordered(double, double)", testCases[i],testCases[j],
 769                                      FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
 770             }
 771         }
 772 
 773         return failures;
 774     }
 775 
 776     /* ******************** copySign tests******************************** */
 777 
 778    public static int testFloatCopySign() {
 779         int failures = 0;
 780 


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


 606         float testCases [][] = {
 607             {NaNf,                      NaNf},
 608             {-infinityF,                -infinityF},
 609             {-Float.MAX_VALUE,          -infinityF},
 610             {-Float_MAX_VALUEmm,        -Float.MAX_VALUE},
 611             {-Float_MAX_SUBNORMAL,      -FloatConsts.MIN_NORMAL},
 612             {-Float_MAX_SUBNORMALmm,    -Float_MAX_SUBNORMAL},
 613             {-0.0f,                     -Float.MIN_VALUE},
 614             {+0.0f,                     -Float.MIN_VALUE},
 615             {Float.MIN_VALUE,           0.0f},
 616             {Float.MIN_VALUE*2,         Float.MIN_VALUE},
 617             {Float_MAX_SUBNORMAL,       Float_MAX_SUBNORMALmm},
 618             {FloatConsts.MIN_NORMAL,    Float_MAX_SUBNORMAL},
 619             {FloatConsts.MIN_NORMAL+
 620              Float.MIN_VALUE,           FloatConsts.MIN_NORMAL},
 621             {Float.MAX_VALUE,           Float_MAX_VALUEmm},
 622             {infinityF,                 Float.MAX_VALUE},
 623         };
 624 
 625         for(int i = 0; i < testCases.length; i++) {
 626             failures+=Tests.test("Math.nextDown(float)",
 627                                  testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
 628 
 629             failures+=Tests.test("StrictMath.nextDown(float)",
 630                                  testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
 631         }
 632 
 633         return failures;
 634     }
 635 
 636 
 637     public static int testDoubleNextDown() {
 638         int failures=0;
 639 
 640         /*
 641          * Each row of testCases represents one test case for nextDown;
 642          * the first column is the input and the second column is the
 643          * expected result.
 644          */
 645         double testCases [][] = {
 646             {NaNd,                      NaNd},
 647             {-infinityD,                -infinityD},
 648             {-Double.MAX_VALUE,         -infinityD},
 649             {-Double_MAX_VALUEmm,       -Double.MAX_VALUE},
 650             {-Double_MAX_SUBNORMAL,     -DoubleConsts.MIN_NORMAL},
 651             {-Double_MAX_SUBNORMALmm,   -Double_MAX_SUBNORMAL},
 652             {-0.0d,                     -Double.MIN_VALUE},
 653             {+0.0d,                     -Double.MIN_VALUE},
 654             {Double.MIN_VALUE,          0.0d},
 655             {Double.MIN_VALUE*2,        Double.MIN_VALUE},
 656             {Double_MAX_SUBNORMAL,      Double_MAX_SUBNORMALmm},
 657             {DoubleConsts.MIN_NORMAL,   Double_MAX_SUBNORMAL},
 658             {DoubleConsts.MIN_NORMAL+
 659              Double.MIN_VALUE,          DoubleConsts.MIN_NORMAL},
 660             {Double.MAX_VALUE,          Double_MAX_VALUEmm},
 661             {infinityD,                 Double.MAX_VALUE},
 662         };
 663 
 664         for(int i = 0; i < testCases.length; i++) {
 665             failures+=Tests.test("Math.nextDown(double)",
 666                                  testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
 667 
 668             failures+=Tests.test("StrictMath.nextDown(double)",
 669                                  testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
 670         }
 671 
 672         return failures;
 673     }
 674 
 675 
 676     /* ********************** boolean tests ****************************** */
 677 
 678     /*
 679      * Combined tests for boolean functions, isFinite, isInfinite,
 680      * isNaN, isUnordered.
 681      */
 682 
 683     public static int testFloatBooleanMethods() {
 684         int failures = 0;
 685 
 686         float testCases [] = {
 687             NaNf,
 688             -infinityF,
 689             infinityF,


 695             -Float_MAX_SUBNORMAL,
 696             -Float.MIN_VALUE,
 697             -0.0f,
 698             +0.0f,
 699             Float.MIN_VALUE,
 700             Float_MAX_SUBNORMALmm,
 701             Float_MAX_SUBNORMAL,
 702             FloatConsts.MIN_NORMAL,
 703             1.0f,
 704             3.0f,
 705             Float_MAX_VALUEmm,
 706             Float.MAX_VALUE
 707         };
 708 
 709         for(int i = 0; i < testCases.length; i++) {
 710             // isNaN
 711             failures+=Tests.test("FpUtils.isNaN(float)", testCases[i],
 712                                  FpUtils.isNaN(testCases[i]), (i ==0));
 713 
 714             // isFinite
 715             failures+=Tests.test("Float.isFinite(float)", testCases[i],
 716                                  Float.isFinite(testCases[i]), (i >= 3));
 717 
 718             // isInfinite
 719             failures+=Tests.test("FpUtils.isInfinite(float)", testCases[i],
 720                                  FpUtils.isInfinite(testCases[i]), (i==1 || i==2));
 721 
 722             // isUnorderd
 723             for(int j = 0; j < testCases.length; j++) {
 724                 failures+=Tests.test("FpUtils.isUnordered(float, float)", testCases[i],testCases[j],
 725                                      FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
 726             }
 727         }
 728 
 729         return failures;
 730     }
 731 
 732     public static int testDoubleBooleanMethods() {
 733         int failures = 0;
 734         boolean result = false;
 735 
 736         double testCases [] = {


 745             -Double_MAX_SUBNORMAL,
 746             -Double.MIN_VALUE,
 747             -0.0d,
 748             +0.0d,
 749             Double.MIN_VALUE,
 750             Double_MAX_SUBNORMALmm,
 751             Double_MAX_SUBNORMAL,
 752             DoubleConsts.MIN_NORMAL,
 753             1.0d,
 754             3.0d,
 755             Double_MAX_VALUEmm,
 756             Double.MAX_VALUE
 757         };
 758 
 759         for(int i = 0; i < testCases.length; i++) {
 760             // isNaN
 761             failures+=Tests.test("FpUtils.isNaN(double)", testCases[i],
 762                                  FpUtils.isNaN(testCases[i]), (i ==0));
 763 
 764             // isFinite
 765             failures+=Tests.test("Double.isFinite(double)", testCases[i],
 766                                  Double.isFinite(testCases[i]), (i >= 3));
 767 
 768             // isInfinite
 769             failures+=Tests.test("FpUtils.isInfinite(double)", testCases[i],
 770                                  FpUtils.isInfinite(testCases[i]), (i==1 || i==2));
 771 
 772             // isUnorderd
 773             for(int j = 0; j < testCases.length; j++) {
 774                 failures+=Tests.test("FpUtils.isUnordered(double, double)", testCases[i],testCases[j],
 775                                      FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
 776             }
 777         }
 778 
 779         return failures;
 780     }
 781 
 782     /* ******************** copySign tests******************************** */
 783 
 784    public static int testFloatCopySign() {
 785         int failures = 0;
 786