test/java/lang/Math/Rint.java

Print this page




   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 4101566 4831589
  27  * @summary Check for correct implementation of Math.rint(double)



  28  */
  29 
  30 import sun.misc.DoubleConsts;
  31 
  32 public class Rint {
  33 
  34     static int testRintCase(double input, double expected) {
  35         int failures = 0;
  36         double result;
  37         failures += Tests.test("Math.rint",  input, Math.rint(input),   expected);
  38         failures += Tests.test("Math.rint", -input, Math.rint(-input), -expected);
  39         failures += Tests.test("StrictMath.rint",
  40                                input, StrictMath.rint(input),   expected);
  41         failures += Tests.test("StrictMath.rint", -input,
  42                                StrictMath.rint(-input), -expected);
  43         return failures;
  44     }
  45 
  46 
  47     public static void main(String args[]) {
  48         int failures = 0;
  49         double twoToThe52 = Math.scalb(1.0, 52); // 2^52
  50 
  51         double [][] testCases = {
  52             {0.0,                               0.0},
  53             {Double.MIN_VALUE,                  0.0},
  54             {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
  55             {DoubleConsts.MIN_NORMAL,           0.0},
  56 
  57             {0.2,                               0.0},
  58 
  59             {Math.nextDown(0.5),             0.0},
  60             {              0.5,              0.0},
  61             {  Math.nextUp(0.5),             1.0},
  62 
  63             {0.7,                               1.0},
  64             {Math.nextDown(1.0),             1.0},
  65             {              1.0,              1.0},
  66             {  Math.nextUp(1.0),             1.0},
  67 
  68             {Math.nextDown(1.5),             1.0},
  69             {              1.5,              2.0},
  70             {  Math.nextUp(1.5),             2.0},
  71 
  72             {4.2,                               4.0},
  73             {4.5,                               4.0},
  74             {4.7,                               5.0},
  75 




   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 4101566 4831589
  27  * @summary Check for correct implementation of Math.rint(double)
  28  * @library /lib/testlibrary
  29  * @build jdk.testlibrary.DoubleUtils jdk.testlibrary.FloatUtils
  30  * @run main Rint
  31  */
  32 


  33 public class Rint {
  34 
  35     static int testRintCase(double input, double expected) {
  36         int failures = 0;
  37         double result;
  38         failures += Tests.test("Math.rint",  input, Math.rint(input),   expected);
  39         failures += Tests.test("Math.rint", -input, Math.rint(-input), -expected);
  40         failures += Tests.test("StrictMath.rint",
  41                                input, StrictMath.rint(input),   expected);
  42         failures += Tests.test("StrictMath.rint", -input,
  43                                StrictMath.rint(-input), -expected);
  44         return failures;
  45     }
  46 
  47 
  48     public static void main(String args[]) {
  49         int failures = 0;
  50         double twoToThe52 = Math.scalb(1.0, 52); // 2^52
  51 
  52         double [][] testCases = {
  53             {0.0,                               0.0},
  54             {Double.MIN_VALUE,                  0.0},
  55             {Math.nextDown(Double.MIN_NORMAL),  0.0},
  56             {Double.MIN_NORMAL,                 0.0},
  57 
  58             {0.2,                               0.0},
  59 
  60             {Math.nextDown(0.5),             0.0},
  61             {              0.5,              0.0},
  62             {  Math.nextUp(0.5),             1.0},
  63 
  64             {0.7,                               1.0},
  65             {Math.nextDown(1.0),             1.0},
  66             {              1.0,              1.0},
  67             {  Math.nextUp(1.0),             1.0},
  68 
  69             {Math.nextDown(1.5),             1.0},
  70             {              1.5,              2.0},
  71             {  Math.nextUp(1.5),             2.0},
  72 
  73             {4.2,                               4.0},
  74             {4.5,                               4.0},
  75             {4.7,                               5.0},
  76