test/java/lang/Math/IeeeRecommendedTests.java

Print this page
rev 11823 : 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
Summary: Add ability to initial the random number generator from the system property "seed" and print to STDOUT the seed value actually used.
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 2003, 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  * @test
  26  * @bug 4860891 4826732 4780454 4939441 4826652
  27  * @summary Tests for IEEE 754[R] recommended functions and similar methods



  28  * @author Joseph D. Darcy
  29  * @key randomness
  30  */
  31 
  32 public class IeeeRecommendedTests {
  33     private IeeeRecommendedTests(){}
  34 
  35     static final float  NaNf = Float.NaN;
  36     static final double NaNd = Double.NaN;
  37     static final float  infinityF = Float.POSITIVE_INFINITY;
  38     static final double infinityD = Double.POSITIVE_INFINITY;
  39 
  40     static final float  Float_MAX_VALUEmm       = 0x1.fffffcP+127f;
  41     static final float  Float_MAX_SUBNORMAL     = 0x0.fffffeP-126f;
  42     static final float  Float_MAX_SUBNORMALmm   = 0x0.fffffcP-126f;
  43 
  44     static final double Double_MAX_VALUEmm      = 0x1.ffffffffffffeP+1023;
  45     static final double Double_MAX_SUBNORMAL    = 0x0.fffffffffffffP-1022;
  46     static final double Double_MAX_SUBNORMALmm  = 0x0.ffffffffffffeP-1022;
  47 
  48     // Initialize shared random number generator
  49     static java.util.Random rand = new java.util.Random();
  50 
  51     /**
  52      * Returns a floating-point power of two in the normal range.
  53      */
  54     static double powerOfTwoD(int n) {
  55         return Double.longBitsToDouble((((long)n + (long)Double.MAX_EXPONENT) <<
  56                                         (DoubleConsts.SIGNIFICAND_WIDTH-1))
  57                                        & DoubleConsts.EXP_BIT_MASK);
  58     }
  59 
  60     /**
  61      * Returns a floating-point power of two in the normal range.
  62      */
  63     static float powerOfTwoF(int n) {
  64         return Float.intBitsToFloat(((n + Float.MAX_EXPONENT) <<
  65                                      (FloatConsts.SIGNIFICAND_WIDTH-1))
  66                                     & FloatConsts.EXP_BIT_MASK);
  67     }
  68 
  69     /* ******************** getExponent tests ****************************** */


   1 /*
   2  * Copyright (c) 2003, 2015, 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  * @test
  26  * @library /lib/testlibrary/
  27  * @build jdk.testlibrary.*
  28  * @run main IeeeRecommendedTests
  29  * @bug 4860891 4826732 4780454 4939441 4826652 8078672
  30  * @summary Tests for IEEE 754[R] recommended functions and similar methods (use -Dseed=X to set PRNG seed)
  31  * @author Joseph D. Darcy
  32  * @key randomness
  33  */
  34 
  35 public class IeeeRecommendedTests {
  36     private IeeeRecommendedTests(){}
  37 
  38     static final float  NaNf = Float.NaN;
  39     static final double NaNd = Double.NaN;
  40     static final float  infinityF = Float.POSITIVE_INFINITY;
  41     static final double infinityD = Double.POSITIVE_INFINITY;
  42 
  43     static final float  Float_MAX_VALUEmm       = 0x1.fffffcP+127f;
  44     static final float  Float_MAX_SUBNORMAL     = 0x0.fffffeP-126f;
  45     static final float  Float_MAX_SUBNORMALmm   = 0x0.fffffcP-126f;
  46 
  47     static final double Double_MAX_VALUEmm      = 0x1.ffffffffffffeP+1023;
  48     static final double Double_MAX_SUBNORMAL    = 0x0.fffffffffffffP-1022;
  49     static final double Double_MAX_SUBNORMALmm  = 0x0.ffffffffffffeP-1022;
  50 
  51     // Initialize shared random number generator
  52     static java.util.Random rand = RandomFactory.getRandom();
  53 
  54     /**
  55      * Returns a floating-point power of two in the normal range.
  56      */
  57     static double powerOfTwoD(int n) {
  58         return Double.longBitsToDouble((((long)n + (long)Double.MAX_EXPONENT) <<
  59                                         (DoubleConsts.SIGNIFICAND_WIDTH-1))
  60                                        & DoubleConsts.EXP_BIT_MASK);
  61     }
  62 
  63     /**
  64      * Returns a floating-point power of two in the normal range.
  65      */
  66     static float powerOfTwoF(int n) {
  67         return Float.intBitsToFloat(((n + Float.MAX_EXPONENT) <<
  68                                      (FloatConsts.SIGNIFICAND_WIDTH-1))
  69                                     & FloatConsts.EXP_BIT_MASK);
  70     }
  71 
  72     /* ******************** getExponent tests ****************************** */